2014-10-28 113 views
1

我想結合ids查詢與must_not子句。我正在使用(重新)輪胎寶石與rails應用程序。Elasticsearch - 結合ids查詢與must_not子句

我在做這樣的事情:

query do 
    ids ["foo", "bar", "test"] 
end 

其中一期工程。但是,當我試圖將其與must_not子句結合使用時,出現錯誤 - must_not僅適用於boolean作用域,其中不包括ids查詢。有什麼辦法可以將這兩個查詢結合起來嗎?

回答

4

,你需要使用ES查詢是這一個:

GET /some_index/some_type/_search 
{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "ids": { 
      "values": ["foo", "bar", "test"] 
      } 
     } 
     ], 
     "must_not": [ 
     { 
      "match": { 
      "name": "whatever" 
      } 
     } 
     ] 
    } 
    } 
} 

所以,你需要布爾範圍,一個mustids和你絕不能匹配查詢一個must_not