Elasticsearch: getMinuteOfDay () applies to time () in a date range filter

I am trying to build an elasticsearch request to return documents between the midnight and current time of the day for all dates. For example, if I run the request at 09:00:00, then the request will return any document with a timestamp between midnight and 09:00:00, regardless of the date.

Here is an example dataset:

curl -XPUT  localhost:9200/test/dt/_mapping -d '{"dt" : {"properties" : {"created_at" : {"type" : "date", "format": "YYYY-MM-DD HH:mm:ss" }}}}'

curl -XPOST localhost:9200/test/dt/1 -d '{ "created_at": "2014-10-09 07:00:00" }'
curl -XPOST localhost:9200/test/dt/2 -d '{ "created_at": "2014-10-09 14:00:00" }'
curl -XPOST localhost:9200/test/dt/3 -d '{ "created_at": "2014-10-08 08:00:00" }'
curl -XPOST localhost:9200/test/dt/4 -d '{ "created_at": "2014-10-08 15:00:00" }'
curl -XPOST localhost:9200/test/dt/5 -d '{ "created_at": "2014-10-07 09:00:00" }'
curl -XPOST localhost:9200/test/dt/6 -d '{ "created_at": "2014-10-07 16:00:00" }'

and filter example:

curl -XPOST localhost:9200/test/dt/_search?pretty -d '{
  "query": {
    "filtered" : {
       "filter" : {
        "bool": {
          "must": [
            {
              "script" : {
            "script" : "doc[\"created_at\"].date.getMinuteOfDay() < 600"
              }
            }
          ]
        }
      }
    }
  }
}'

where 600 is a static parameter that I want to replace with a dynamic parameter of minutes depending on the time of day when the request is executed.

- getMinuteOfDay() , , getMinuteOfDay() . time() 600 , .

?

+4
1

, DateTime.now(),

GET test/dt/_search
{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "script": {
                "script": "doc[\"created_at\"].date.getMinuteOfDay() < DateTime.now().getMinuteOfDay()"
              }
            }
          ]
        }
      }
    }
  }
}

, !

0

All Articles