2017-07-23 40 views
1

我想找到包含「鮑勃」,具有位置即在任一「帕迪尤卡」或'一文檔士麥那」。Elasticsearch布爾查詢必須單場獨詞,而另一場或術語匹配

這是我現在有:

query: { 
    bool: { 
    must: [ 
     { match: { name: 'bob' } }, 
     { match: { location: ['paducah', 'smyrna'] } } 
    ], 
    }, 
}, 

我知道這個問題是位置陣中,因爲如果我把它沒有陣列更改爲單元素的查詢工作就好了。

This is the closest answer i could find

它沒有工作,我收到以下錯誤:

[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

回答

1

你可以試試這個查詢:

{ 
    "query": { 
     "bool": { 
     "must": [ 
      { "match": { "name": "bob" } } 
     ], 
     "should": [ 
      { "match": { "location": "paducah" }}, 
      { "match": { "location": "smyrna" }} 
      ], 
      "minimum_should_match": 1 
     } 
    } 
} 
0

什麼如下:

{ 
    "query": { 
    "bool": { 
     "must": [ 
     { "term": { "name": "bob" }, 
     "bool": { 
      "should": [ 
      {"term": {"location": "paducah"}}, 
      {"term": {"location": "smyrna"}} 
      ] 
     } 
     } 
     ] 
    } 
    } 
}