elasticsearch query dates by range elasticsearch query dates by range elasticsearch elasticsearch

elasticsearch query dates by range


Your field is a string, the format property is ignored. You should change your mapping and use the date type. Have a look here to see the core types available in elasticsearch.

I would use a filter instead of a query. It will be cached, thus faster. The following is an example for the last 7 days:

{    "filter" : {        "range" : {            "PublishTime" : {                "from" : "20130505T000000",                "to" : "20131105T235959"            }        }    }}

Note that if you use the filter like this it's going to be the same filter the whole day, thus you would make good use of the cache.