我无法过滤我的elasticsearch查询来查找值为“no”的项目。我正在使用0.90版。
创建包含以下各项的索引:
{ "foo": "abc", "bar": "yes" }
{ "foo": "def", "bar": "no" }
{ "foo": "ghi", "bar": "maybe" }
现在,尝试对
bar
进行一些术语查询:{ "query": { "term": { "bar": "yes" } } }
// Hits: 1
{ "query": { "term": { "bar": "maybe" } } }
// Hits: 1
{ "query": { "term": { "bar": "no" } } }
// Hits: 0 <-- What??
查询值为“no”时没有命中。
看一下方面:
{ "facets": { "bar": { "terms": { "field": "bar" } } } }
结果:
{
...
"facets": {
"bar": {
"_type": "terms",
"missing": 1,
"total": 2,
"other": 0,
"terms": [
{ "term": "yes", "count": 1 },
{ "term": "maybe", "count": 1 }
]
}
}
}
甚至没有返回“no”值的构面。到底是怎么回事?如何在索引中找到值为“no”的项目?
我刚刚下载了最新版本(1.0.1),可以看到它已修复。但是,我使用的是0.90.3,其行为在0.90.12中相同。有没有办法让它在0.90。*下工作?
最佳答案
使用0.90中的标准分析仪,这是预期的行为。标准分析器在为字符串建立索引时默认使用,它应用stop word token filter。 “否”出现在停用词列表上,因此将从获得索引的术语列表中删除。这就是为什么搜索“否”将不返回任何内容的原因。
此行为在1.0中与众不同的原因是,对停用词的好处提出了质疑,并将其从默认行为中删除。 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/_stopwords.html
如果您希望看到相同的行为,则可以创建自己的分析器或仅使用关键字分析器。这只会将字符串转换为小写字母,不会将其拆分,也不会将停用词过滤器应用于这些字词。
关于此主题的博客很好:http://www.elasticsearch.org/blog/stop-stopping-stop-words-a-look-at-common-terms-query/
还有另一个Stackoverflow问题:elasticsearch: how to index terms which are stopwords only?
关于elasticsearch - 筛选值为 “no”的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22106369/