The params.population_key is a string and the field is present only in some documents, it's mapping is defined as a dynamic template of type double.
The execution works but logs following error:
returning default values for missing document values is deprecated. Set system property '-Des.scripting.exception_for_missing_value=true' to make behaviour compatible with future major versions!
It seems to me that the true branch of the ternary expression is evaluated eagerly, maybe because some kind of type conversion or so? Could you please suggest a way how to rewrite the script so I don't get any warning?
I've probably found the problem. Inside the script, the doc object is a prepared data structure in a tabular format, optimized for fast access. It's not the underlying source document, which we indexed.
So the doc most likely contains all keys known from the index mapping. Which means that doc.containsKey('any_mapping_key') evaluates to true and the first branch of the ternary operator is always triggered.
I solved the problem by using doc[params.population_key].empty condition instead. It makes sense to combine this condition with doc.containsKey(params.population_key) if there is a chance that the param will be something not known from mappings.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.