I am using Elasticsearch 6.5.
I want to use an update API with the painless script. Let's say, that my target document has an
address structure inside of it. Update script may look something like this:
ctx._source.address.street = params.src.address.street; ctx._source.address.city = params.src.address.city; ctx._source.address.postal_code = params.src.address.postal_code;
Which usually runs great. But there are documents, that do not have an
address structure. In these cases update script fails with
null_pointer_exception error - then I am addressing inner field of not existing structure.
So basically my questions are:
- How to detect in painless, that document does not have an
- How to create this inner structure and set values to it?
To answer questions that may arise: making the whole document flat (just fields without inner structure) is not an option in my case. Also, I cannot modify documents to ensure, that everyone has an
address structure, before an update script.