Can I use a Range Query in Scripted Field

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.

can you explain the context with a scripted field here? I do not follow it.

I also think you should take a closer look at the range types, which have been added recently.


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.