Hi, I created a script field with the type of date successfully but when I search data in discover something went wrong . And I cannot use my script field in aggregation either. My script field create by if(doc['finished'].value.getHour()>=16) { Instant.ofEpochMilli(doc['finished'].value.getMillis()+8*60*60*1000); } else { Instant.ofEpochMilli(doc['finished'].value.getMillis()); }
. And here is the error below:
Detail of exception:
Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"runtime error","script_stack":["org.elasticsearch.index.fielddata.ScriptDocValues$Dates.get(ScriptDocValues.java:160)","org.elasticsearch.index.fielddata.ScriptDocValues$Dates.getValue(ScriptDocValues.java:154)","if(doc['finished'].value.getHour()>=16)\n{\n "," ^---- HERE"],"script":"if(doc['finished'].value.getHour()>=16)\n{\n Instant.ofEpochMilli(doc['finished'].value.getMillis()+8*60*60*1000);\n}\nelse\n{\n Instant.ofEpochMilli(doc['finished'].value.getMillis());\n}","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"bp-session-log-b","node":"VlTdaqFERuaqpqtJyFR8Sw","reason":{"type":"script_exception","reason":"runtime error","script_stack":["org.elasticsearch.index.fielddata.ScriptDocValues$Dates.get(ScriptDocValues.java:160)","org.elasticsearch.index.fielddata.ScriptDocValues$Dates.getValue(ScriptDocValues.java:154)","if(doc['finished'].value.getHour()>=16)\n{\n "," ^---- HERE"],"script":"if(doc['finished'].value.getHour()>=16)\n{\n Instant.ofEpochMilli(doc['finished'].value.getMillis()+8*60*60*1000);\n}\nelse\n{\n Instant.ofEpochMilli(doc['finished'].value.getMillis());\n}","lang":"painless","caused_by":{"type":"illegal_state_exception","reason":"A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"}}}]},"status":400}
Looking forward to your help,Thanks!