version 2.4
Below are my two epoch times in Number format
doc['actual'].value-doc['expected'].value < 0?1:0
I'm looking for a percentage of actual time not meeting the expected time. But I have challenge where few documents don't have both of these values or missing either of the values which I want to ignore.
If one of the fields (actual or expected) is missing, what would you like to do? Do you want to use a default value for the missing field, or do you want to skip the calculation entirely and return a default value for the script?
I get the below error
{"error":{"root_cause":[{"type":"lexer_no_viable_alt_exception","reason":"lexer_no_viable_alt_exception: null"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"test","node":"gZEsj74DTtaFMe-aG2","reason":{"type":"script_exception","reason":"Failed to compile inline script [if(doc.containsKey('actual') && doc.containsKey('expected')) {doc['actual'].value - doc['expected'].value < 0?1:0} else {return -1}] using lang [expression]","caused_by":{"type":"script_exception","reason":"Failed to parse expression: if(doc.containsKey('actual') && doc.containsKey('expected')) {doc['actual'].value - doc['expected'].value < 0?1:0} else {return -1}","caused_by":{"type":"parse_exception","reason":"parse_exception: unexpected character ''' on line (1) position (19)","caused_by":{"type":"lexer_no_viable_alt_exception","reason":"lexer_no_viable_alt_exception: null"}}}}}]}}
I'm so sorry, I totally missed that you were working with 2.4. I assumed you were using the new Painless language in 5.x. The syntax will be a little different with lucene expressions:
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.