2013-04-27 52 views
14

我想在此查詢上增加一點點。我正在搜索的索引還有一個帶有ID的字段「實體」。所以一些記錄將具有「實體」:16,「實體」156等,這取決於實體的ID。我需要以這種方式擴展此查詢,以便可以傳遞數組或某些值列表,例如{:term => {:entity => [1,16,100]}},然後獲取具有其中一個整數作爲其實體價值。到目前爲止我還沒有運氣,有人可以幫我嗎?使用Elasticsearch中的一個值的屬性查詢多個值

{ 
    "query" : { 

    "bool" : { 
     "must" : [ 
     { 
      "term" : {"user_type" : "alpha"} 
     }, 
     { 
      "term" :{"area" : "16"} 
     } 
     ], 
     "must_not" : [], 
     "should" : [] 
    } 
    }, 
    "filter": { 
    "or" : [{ 
     "and" : [ 
      { "term" : { "area" : "16" } }, 
      { "term" : { "date" : "05072013" } } 
     ] 
    }, { 
     "and" : [ 
      { "term" : { "area" : "16" } }, 
      { "term" : { "date" : "blank" } } 
     ] 
    } 


    ] 
    }, 
"from" : 0, 
"size" : 100 
} 

回答

28

使用"terms"而不是"term"

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html

{ "terms" : { "entity" : [ 123, 1234, ... ] }}

+0

非常感謝您!您保存了我的一天:) – NorthCat 2015-12-14 12:59:53

+0

此查詢將與AND或OR聯繫?我想用OR來檢查我的狀況:在上面的查詢實體= 123或實體= 1234等等。如何編寫該查詢? – 2016-03-31 05:02:38

+0

@DeepParekh您是否可以編寫上述評論的查詢? AND還是OR? 我有這樣的事情。 (我必須傳遞多個擴展值來篩選,你能幫我解決這個問題)現在我只能發送一個擴展值。如果我必須爲過濾器查詢傳遞多個擴展值,該怎麼辦? (ft => ft.Term(t => t.Field(「content_type」)。Value(extension)))))'' – ASN 2016-06-20 03:01:11

相關問題