5

I am new to ES, and I am using ES 7.10.1, I have following simple search request:

GET /megacorp/_doc/_search
    {
        "query":{
            "filtered":{
                "filter":{
                    "range":{
                        "age":{
                            "gt":30
                        }
                    }
                },
                "query":{
                    "match":{
                        "last_name":"smith"
                    }
                }
            }
        }
    }

When I run the above query(using query and filter) in the Kibana Dev Tools, an exception occurs as follows, I would ask how to fix this,thank.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "parsing_exception",
        "reason" : "unknown query [filtered]",
        "line" : 3,
        "col" : 14
      }
    ],
    "type" : "parsing_exception",
    "reason" : "unknown query [filtered]",
    "line" : 3,
    "col" : 14,
    "caused_by" : {
      "type" : "named_object_not_found_exception",
      "reason" : "[3:14] unknown field [filtered]"
    }
  },
  "status" : 400
}
Tom
  • 5,848
  • 12
  • 44
  • 104
  • This answer might help: https://stackoverflow.com/questions/40519806/no-query-registered-for-filtered/40521602#40521602 – Val Jan 21 '21 at 05:23

1 Answers1

12

The filtered query has been deprecated. You should now use the boolean query. Modify your search query as -

 {
  "query": {
    "bool": {
      "must": {
        "match": {
          "last_name": "smith"
        }
      },
      "filter": {
        "range": {
          "age": {
            "gt": 30
          }
        }
      }
    }
  }
}
ESCoder
  • 15,431
  • 2
  • 19
  • 42