I am passing params map in the painless script, that map is type of <String, Long>
.
The key of the map defines the id
and the value defines the foundDate
in epoch Long.
The elastic Document have the raw structure like this :
doc:{
[ "id":11406, // type:Long
"lastFixed": 1666015888000 // type epoch millis
] // ...mutiple ids and their lastFixed Dates
}
I have calculate the average difference between the foundDate
and lastFixed
(both are in epoch).
I have build the ES Painless script as below:
"script": {
"source": "(doc['lastFixed'] - params[doc['id']] )/ (1000*60*60)",
"lang": "expression",
"params": {
"11406": 1614084531000,
"11473": 1073523856000,
"11549": 1447461154000,
"43904": 1666015887000,
"43905": 1666015887000,
"43906": 1666015887000,
"43907": 1666015887000,
"43908": 1666015888000,
"43909": 1666015888000,
"43910": 1666015888000
}
}
For nesting on the array of id
& lastFound
date I am using nest-path-aggr-name
i.e. the nested path.
I want to pass the dynamic value in the params map as it will give the foundDate
from the map for the same id
in the Elasticsearch document.
But I am getting the parsing error from ES. I have tired with param.doc['id']
and param[]
but both are falling and giving parsing error.
What is the correct way to pass the dynamic value in params map.