elaticsear no [query] registered for [filtered] 错误

1、问题描述

执行语句:

 

GET /megacorp/employee/_search
{
    "query" : {
        "filtered" : {
            "filter" : {
                "range" : {
                    "age" : { "gt" : 30 } <1>
                }
            },
            "query" : {
                "match" : {
                    "last_name" : "smith" <2>
                }
            }
        }
    }
}

 出现错误: 

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "no [query] registered for [filtered]",
        "line": 3,
        "col": 22
      }
    ],
    "type": "parsing_exception",
    "reason": "no [query] registered for [filtered]",
    "line": 3,
    "col": 22
  },
  "status": 400
}
 

  

2、原因和解决

原因: 过滤查询已被弃用,并在ES 5.0中删除。 
解决: 使用bool / must / filter查询

GET /megacorp/employee/_search
{
    "query" : {
        "bool" : {
            "filter" : {
                "range" : {
                    "age" : { "gt" : 30 }
                }
            },
            "must" : {
                "match" : {
                    "last_name" : "smith"
                }
            }
        }
    }
}
 

  

 

posted @ 2018-11-30 10:18  斑马森林  阅读(4030)  评论(0编辑  收藏  举报