Search code examples
elasticsearchfilterrangejquery-filter

elasticsearch date range filter error 'no [query] registered for [filtered]'


I need to get result from elasticsearch using filter (date range)

this is my query,

'{
    "sort" : [{ "bytes" : {"order" : "desc"}}],
    "query": {
              "filtered": {
                   "query": { "match_all": {} },
                       "filter": {
                           "range": {
                                "@timestamp": {
                                    "gte": "2017-11-07T00:00:01Z",
                                    "lte": "2017-11-12T00:00:01Z"
                                 }
                            }
                       }
                  }
            }
 }'

when i run this query, i got an error 'no [query] registered for [filtered]'. I am following the format given in the filtered query documentation on the elasticsearch page.

https://www.elastic.co/guide/en/elasticsearch/reference/1.4/_executing_filters.html


Solution

  • the syntax was changed for ES 5.0, and The filtered query is replaced by the bool query. what you have to change is, the two bellow line

          "filtered": {
               "query": { "match_all": {} },
    

    By

    "bool" : {
       "must" : {  "match_all": {} },
    }