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

640 views Asked by At

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

1

There are 1 answers

0
BERGUIGA Mohamed Amine On

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": {} },
}