2013-02-19 78 views
0

我有一個查詢:Elasticsearch比較或

{ 
    "query": { 
     "bool" : { 
      "must": [ 
       { "match": { "tags": "htc" } }, 
       { "match": { "votype" : 1} }, 
       { "match": { "subtype": 1 } }, 
       { "match": { "deleted": 0 } }, 
       { "match": { "build_status": 4 } }, 
       { "match": { "publish": 1 } } 
      ] 
     } 
    }, 

    "sort": [ 
     { "created": "desc" } 
    ], 

    "size": 30, 
    "from": 0 
} 

,我想投入值

的值列表
{ "match": { "votype": [1 or 2 or 3] } } 

SQL模擬:

SELECT * FROM tablename WHERE type IN(1, 2); 

但不`知道如何到

不工作:

{ "match": { "votype": [1,3] } }, 
{ "match": { "votype": "1 2" } }, 
{ "match": { "votype": "1OR2" } } 
+1

看一看的[條款查詢](http://www.elasticsearch.org/guide/reference/query-dsl/terms-query.html) – Thorsten 2013-02-19 17:05:07

+0

是工作!感謝您的提示 – ahiipsa 2013-02-20 13:14:15

回答

1

我的解決方案

{ 
    "query": { 
     "bool" : { 
      "must": [ 
       { "terms" : { "tags": ["htc"], "minimum_match": 1 } }, 
       { "terms" : { "votype" : [1,2], "minimum_match": 1 } }, 
       { "terms" : { "deleted": [0], "minimum_match": 1 } }, 
       { "terms" : { "build_status": [4], "minimum_match": 1 } }, 
       { "terms" : { "publish": [1], "minimum_match": 1 } } 
      ] 

     } 
    }, 

    "sort": [ 
     { "created": "desc" } 
    ], 

    "size": 30, 
    "from": 0 
} 
1

這工作?

{ "match": { "votype": "1 2 3" } } 
+1

我認爲這個問題是「如何在匹配查詢中搜索值列表?」我想我回答了這個問題。我沒有看到我的答案出了什麼問題。我誤解了這個問題嗎? – dadoonet 2013-02-19 20:35:06

+0

這個字符串值的工作 – ahiipsa 2013-02-20 11:31:27

+0

@dadoonet對不起,我在這裏的觸發器有點快。 – Emil 2013-02-20 13:20:31