1
votes

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
Which version of ES are you using? You're looking at the documentation for ES 1.4, but are you really using 1.4? If not, please see this answer: stackoverflow.com/a/40521602/4604579 - Val
"version" : { "number" : "5.6.2", }, i think, i have checked v. 1.4 documentation. - AmilaM
Then you have your answer ;-) - Val
Thank you val. i created that query as in v.5.6 documentation. but it seems not working correctly. the output was not correct. i just want to filter values by date range and sort it. i'm new for elasticsearch. - AmilaM
this is my query. any error there? - AmilaM

1 Answers

1
votes

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