2014-10-27 66 views
0

我在Elasticsearch这些文件:无法通过阵列搜索在elasticsearch

{ 
    "id_object": "9", 
    "size_id": "-1", 
    "enabled": 1, 
    "verified": 0, 
    "countries": [ 
     "Germany" 
    ] 
}, 
{ 
    "id_object": "19", 
    "size_id": "-1", 
    "enabled": 1, 
    "verified": 0, 
    "countries": [ 
     "Germany", 
     "France" 
    ] 
} 

我用下面的语句来抓取有“德国”的所有文档里面:

GET abc/def/_search 
{ 
    "query": { 
    "filtered": { 
     "filter": { 
    "bool": { 
     "must": { 
     "term": { 
      "countries": "Germany" 
     } 
     } 
    } 
    } 
} 

} }

但它没有返回结果! 我做错了什么?

回答

2

未对术语“过滤器”进行分析,这意味着它们将与精确的术语匹配,而不会进行压缩,也不会进行任何其他过滤或处理。因此,您的查询将通过完全匹配“德国”来查看倒排索引,而如果您在将这两个文档放入ES中时使用了标准分析器,则它们将被记录为“德国”(小写)和“法国”小写。

所以,你的情况你的过滤器将匹配这样的:

{ "query": { 
    "filtered": { 
     "filter": { 
     "bool": { 
      "must": { 
      "term": { 
       "countries": "germany" 
      } 
      } 
     } 
     } 
    }}} 

在另一方面,“匹配”的查询进行分析,所以,如果你要寻找的“德”,这不是将匹配:

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "bool": { 
      "must": [ 
      {"match": { 
       "countries": "Germany" 
      }} 
      ] 
     } 
     } 
    } 
    } 
} 
+0

如果我有300万个文件,哪一个会更快?查询或过滤? – 2014-10-27 08:34:57

+2

过滤器。如果您经常查询相同的术语,那么它将有助于缓存过滤器。 – 2014-10-27 08:36:37

+0

令人惊叹,谢谢 – 2014-10-27 08:42:25