I am have been playing around the range field types, and in this index I have approx 2500 documents, each defining a different time_range.
Example document:
{
"time_frame": {
"gte": 1509355523000,
"lte": 1509355718871
}
}
A time range queries like:
POST index-1/_search
{
"size": 0,
"query" : {
"range" : {
"time_frame" : {
"gte" : 1509355523000,
"lte" : 1509355523999
}
}
}
}
Gives me how many documents intersect with the defined time range.
Response: {
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 23,
"max_score": 0,
"hits": []
}
}
What I want to achieve is having the number of intersecting documents, returned as a scripted field. In theory I should be able to achieve this by somehow embedding the range query as a scripted field, but as far as I can tell, you can only use Painless (or similar) in a scripted field. Is there a way, I can use Painless, to access the values in the document, and use them in a range query for a scripted field?
Thanks In Advance.