I want to search by calculated field.
For example, I calculate field by script & want to call it in query after, like in example below.
POST /process-instance/_search
{
"script_fields": {
"duration": {
"script": {
"source":
"""
doc['completedAt'].value.toInstant().toEpochMilli() - doc['createdAt'].value.toInstant ().toEpochMilli()
""",
"lang": "painless"
}
}
},
"query": {
"range": {
//using calculated field 'duration' in search query
"duration": {
"gte": 1000
}
}
}
}
Field ‘duration’ calculates and returns in result for every document, but when I use it in search querty, result is empty.
Have you any idea, how to use calculated field in search query?