2016-11-10 93 views
48

我有一个查询,我需要筛选出结果。没有[查询]注册为[过滤]

这是我的查询

{ 
    "query": { 
     "filtered": { 
      "query": { 
       "multi_match": { 
        "default_operator": "AND", 
        "fields": [ 
         "author", 
         "title", 
         "publisher", 
         "year" 
        ], 
        "query": "George Orwell" 
       } 
      }, 
      "filter": { 
       "terms": { 
        "year": [ 
         1980, 
         1981 
        ] 
       } 
      } 
     } 
    } 
} 

我得到一个错误说no [query] registered for [filtered]。我清楚地有一个查询过滤字段。我遵循弹性搜索页面上筛选查询文档中给出的格式。 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html

回答

90

filtered查询已被弃用并在ES 5.0中删除。您现在应该使用bool/must/filter查询。

{ 
    "query": { 
     "bool": { 
      "must": { 
       "multi_match": { 
        "operator": "and", 
        "fields": [ 
         "author", 
         "title", 
         "publisher", 
         "year" 
        ], 
        "query": "George Orwell" 
       } 
      }, 
      "filter": { 
       "terms": { 
        "year": [ 
         1980, 
         1981 
        ] 
       } 
      } 
     } 
    } 
} 

这里有两个查询之间的区别:

3,4c3,4 
<   "bool": { 
<    "must": { 
--- 
>   "filtered": { 
>    "query": { 
6c6 
<      "operator": "and", 
--- 
>      "default_operator": "AND", 

PS:你看位于附录的“删除页面”引用页面,所以它不是一部分主要文档了。

+1

当使用5.5似乎default_operator已经从multi_match查询以及VAL删除所以也许值得更新这个答案,因为它使我走上错误的道路假设以上是去上班我修改查询,以符合我的领域然后意识到它没有工作!这是一个简单的修复,我虽然BU只删除默认的操作,而是将来的读者也许值得编辑的错误是:[multi_match]查询不支持[default_operator] – Birdy

+0

@Birdy实际参数被命名为'operator'而不是' default_operator',我已经修改了我的答案,对此很抱歉。 – Val

+0

瓦尔 - 如果你得到一分钟,你能帮我出去logstash问题,我敲我的头了表48小时以上哈哈,我知道你是在该领域的专家,可以帮助节省一天哈哈,谢谢,如果你能的话,我会永远在债务! https://stackoverflow.com/questions/45577572/logstash-error-when-converting-mysql-value-to-nested-elasticsearch-property-on-s – Birdy