elasticsearch - Elastic Search Script taking date as String -
i have couple of date fields in type . trying run script on date fields find duration between 2 dates.
script takes date field string , gives no such property: millis class. beleive elastic search stores in date in epoch millis.
here script trying
ctx._source.duraton = ctx._source.sessionterminationdatetime.value.millis - ctx._source.eventconversiondatetime.value.millis here mapping
"access-event-logs": { "mappings": { "session-summary": { "dynamic_templates": [ { "long_1": { "mapping": { "type": "long" }, "match": "generation" } }, { "datetime_1": { "mapping": { "format": "strict_date_optional_time||epoch_millis", "type": "date" }, "match": "*datetime" } }, { "string_1": { "mapping": { "index": "not_analyzed", "type": "string" }, "match": "*" } } ], "properties": { "eventconversiondatetime": { "type": "date", "format": "strict_date_optional_time||epoch_millis" }, "generation": { "type": "long" }, "hostname": { "type": "string", "index": "not_analyzed" }, "sessionkey": { "type": "string", "index": "not_analyzed", "include_in_all": false }, "sessionterminationdatetime": { "type": "date", "format": "strict_date_optional_time||epoch_millis" }, } } } } } how can duration in millis between 2 date fields
doc['eventconversiondatetime'].date.getmillis() . { "_index": "access-event-logs", "_type": "session-summary", "_id": "c2de4a9dkarabip1new.lab.fp.f5net.com", "_version": 1, "found": true, "_source": { "sessionkey": "c2de4a9dkarabip1new.lab.fp.f5net.com", "eventconversiondatetime": "2016-01-06t16:08:43.047-08:00", "badipreputation": false, "virtualserver": "/common/access_virtual", "lastupdatemicros": 0 } }
you can convert string date, worked me
post /access-event-logs/session-summary/1/_update { "script": "ctx._source.duration=new date().parse(\"yyyy-mm-dd hh:mm:ss.sss\",ctx._source.eventconversiondatetime.replace(\"t\", \" \").substring(0,23)).gettime();" } hope helps!!
Comments
Post a Comment