【问题标题】:Filter on fields with a value of "no"过滤值为“no”的字段
【发布时间】:2014-03-01 06:04:45
【问题描述】:

我无法过滤我的 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.* 中工作?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    这是在 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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 2020-11-03
      • 2020-03-30
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多