I've created this script in order to get a date difference between two fields:
use(groovy.time.TimeCategory) { def duration = doc[firstDateField].date - doc[secondDateField].date; duration.Hours; }
In order to check it I'm requesting this _search
request:
#docker exec -it es curl -XGET 'http://localhost:9200/living_team/fuas/_search?pretty' -d ' { "script_fields": { "my_script": { "script": { "file": "dayDateDiff", "params": { "firstDateField": "timestamp", "secondDateField": "startTimestamp" } } } } } '
ElasticSearch is telling me:
{ "error" : { "root_cause" : [ { "type" : "script_exception", "reason" : "failed to run file script [dayDateDiff] using lang [groovy]" } ], "type" : "search_phase_execution_exception", "reason" : "all shards failed", "phase" : "query_fetch", "grouped" : true, "failed_shards" : [ { "shard" : 3, "index" : "living_v1", "node" : "SSgkS5Y9QV-EmzaeP_7hKQ", "reason" : { "type" : "script_exception", "reason" : "failed to run file script [dayDateDiff] using lang [groovy]", "caused_by" : { "type" : "missing_property_exception", "reason" : "No such property: groovy for class: 94b4e4baddb8e121bd26f2098185e84d368e4162" } } } ] }, "status" : 500 }
So, the question would be, why do I need to set a field in order perform an script? and lastly, how can I send this script request correctly?
EDIT
I've changed my script:
new Period(doc[firstDateField].date, doc[secondDateField].date).getHours();
However, it's telling me now:
bbd8b73ce0b0dd070d07e63f11dcdad4fa12121d: 1: unable to resolve class Period Nov 04 10:27:21 core-01 docker[3876]: @ line 1, column 1. Nov 04 10:27:21 core-01 docker[3876]: new Period(doc[firstDateField].date, doc[secondDateField].date).getHours(); Nov 04 10:27:21 core-01 docker[3876]: ^
It's telling me there's some problem with Period
.