2015-06-10 69 views
2

我想检查包含一些值的数组长类型的字段。 我发现的唯一方法是使用脚本:ElasticSearch Scripting: check if array contains a valueelasticsearch -check if array contains a value

,但它仍然没有工作前我: 查询:

{ 
    "query": { 
     "filtered": { 
      "query": { 
       "match_all": {} 
      }, 
      "filter": { 
       "script": { 
        "script": "doc['Commodity'].values.contains(param1)", 
        "params": { 
         "param1": 50 
        } 
       } 
      } 
     } 
    } 
} 

,但我得到0命中。而我也有记录:

{ 
"_index" : "aaa", 
"_type" : "logs", 
"_id" : "2zzlXEOgRtujWiCGtX6s9Q", 
"_score" : 1, 
"_source" : { 

    "Commodity" : [ 
    50 
    ], 
    "Type" : 1, 
    "SourceId" : "fsd", 
     "Id" : 123 
    } 
} 
+0

你为什么不使用'{ “查询”:{ “匹配”:{ “商品” :50 } } }'? –

+1

我有一个像这样的过滤器很长的列表。 +我希望能够过滤多个值,例如:包含50和45的商品 –

回答

4

试试这个,而不是那个脚本:

{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "terms": { 
      "Commodity": [ 
      55, 
      150 
      ], 
      "execution": "and" 
     } 
     } 
    } 
    } 
} 
+0

好的。谢谢!! –