【问题标题】:unknown query [filtered] when doing search against ES对 ES 进行搜索时,未知查询 [已过滤]
【发布时间】:2021-04-25 12:33:52
【问题描述】:

我是 ES 新手,我正在使用 ES 7.10.1,我有以下简单的搜索请求:

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

当我在 Kibana 开发工具中运行上述查询(使用查询和过滤器)时,出现如下异常,请问如何解决这个问题,谢谢。

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

【问题讨论】:

标签: elasticsearch


【解决方案1】:

filtered query 已被弃用。您现在应该使用boolean query。将您的搜索查询修改为 -

 {
  "query": {
    "bool": {
      "must": {
        "match": {
          "last_name": "smith"
        }
      },
      "filter": {
        "range": {
          "age": {
            "gt": 30
          }
        }
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 2015-10-06
    • 2021-08-27
    • 2015-01-25
    相关资源
    最近更新 更多