How to catch a null_pointer_exception?

On a reindex operation I'm using

if(ctx._source.containsKey("author")) {
    ctx._source.title = ctx._source.title +[0];

Which throws a null pointer exception error:


How can I check which document causes this error? Because I made sure the author field exists, is an array, and the 0 index exists, so I have no idea why I still get the null pointer exception

What versions are you working with? You might have documents without the _source field. Easiest way to check and fix if that's the case is to wrap it all in another IF clause that checks for the _source field before everything.

I'm using Elasticsearch 7.6 and ctx._source always works. But for some reason not when performing a reindex operation.

What I did as a result was to use a query to check if the field exists in the source index.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.