My script does return null which I cant control since it can be a dynamic script because of which I end up getting the following error:
"error": {
"root_cause": [
{
"type": "null_pointer_exception",
"reason": null}],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,...
How can I bypass this error? Is it possible to do this without modifying the script? The script can be dynamic and the query is generated through a NEST object. Why cant the script sort work with null value results?
I don't think the null pointer exception is because you are returning null, but instead because you are trying to access a field which has no values for a document. Are you sure all documents value values for fields 1 and 2? Could you please look in your elasticsearch log and find the full stack trace for the NullPointerException?
I think I see what is happening here now. When painless is missing a return statement, it will by default return null. By not having an else case for your if, the null was returned and causing an NPE when trying to convert to double (the return type of numeric sort scripts).
Is there a reason you can't keep the else case with 0 (or whatever else you want as the default when your condition is not met)?
Well the script is mostly dynamic and could be anything since it is entered by a user according to the way he wants the data. There could be plenty of scripts like these in our system which we might not be able to correct. They run without any issues and display null in our grids. Is there a way to handle these nulls and handle them when sorting?
This is already changed in 6.5.0. The signature for numeric sort scripts changed from returning Object (which is what causes painless to do an implicit return null) to return double, which painless then will return 0.0 with a missing else. Any handling would have to be on the client side.
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.