elasticsearch - 筛选值为 “no”的字段

标签 elasticsearch

我无法过滤我的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/

相关文章:

elasticsearch - Elasticsearch:使用Java API通过路由创建别名并进行过滤

elasticsearch - 寻找一个kafka连接器以将数据上传到elasticsearch

solr - 进行详细产品搜索的哪种解决方案?

Elasticsearch 带空格的通配符查询

python - Boto3 put_object() 很慢

ruby-on-rails - 生产服务器上的Elasticsearch RAM问题

elasticsearch - 带有filter或bool的ElasticSearch查询

python - ElasticSearch DSL -> 组合多个过滤器并消除元数据

javascript - Angularjs 中的 ElasticSearch 到 NVD3

elasticsearch - ElasticSearch是否有主动提琴?