2016-09-15 154 views
3

我对弹性搜索非常陌生,想编写一个关注两个字段的查询。我的意思是这些字段的内容包含指定的子字符串。我有一个包含字段的文档,像这样:用多个字段匹配查询

name: n 
tag: t 

我尝试这样做:

/_search -d ' 
{ 
    "query": { 
     "match": { 
      "name": "n", 
      "tag": "t" 
     } 
    } 
} 

但查询结果中出现以下错误:

[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?

有没有办法做到这在elasticsearch?

回答

7

您需要封闭在一个bool/must查询的两个match查询,像这样:

{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "match": { 
      "name": "n" 
      } 
     }, 
     { 
      "match": { 
      "tag": "t" 
      } 
     } 
     ] 
    } 
    } 
}