elasticsearch - Elasticsearch:搜索简单的 'a'字符时不返回结果

标签 elasticsearch

我想在ElasticSearch中存储消息的标签。我将标签字段定义为:

{
  'tags': {
    'type': 'string',
    'index_name': 'tag'
  }
}

对于一条消息,我将以下列表存储在标签字段中:
['a','b','c']

现在,如果我尝试使用以下查询搜索标签“b”,它将返回消息和标签:
{
  'filter': {
    'limit': {
      'value': 100
    }
  },
  'query': {
    'bool': {
      'should': [
        {
          'text': {
            'tags': 'b'
          }
        }
      ],
      'minimum_number_should_match': 1
    }
  }
}

标签“c”也是如此。
但是如果我用这个搜索标签“a”:
{
  'filter': {
    'limit': {
      'value': 100
    }
  },
  'query': {
    'bool': {
      'should': [
        {
          'text': {
            'tags': 'a'
          }
        }
      ],
      'minimum_number_should_match': 1
    }
  }
}

它根本没有任何结果!
答案是:
{
  'hits': {
    'hits': [],
    'total': 0,
    'max_score': None
  },
  '_shards': {
    'successful': 5,
    'failed': 0,
    'total': 5
  },
  'took': 1,
  'timed_out': False
}

我究竟做错了什么? ('a'是列表的第一个元素并不重要,['b','a','c']也是一样。似乎只有一个'a'字符才有问题。

最佳答案

如果您未设置任何分析器并将其映射到索引,则Elasticsearch默认使用其自己的分析器。 Elasticsearch的default_analyzer具有停用词过滤器,默认情况下会忽略英语停用词,例如:

   "a", "an", "and", "are", "as", "at", "be", "but", "by",
  "for", "if", "in", "into", "is", "it",
  "no", "not", "of", "on", "or", "such",
  "that", "the", "their", "then", "there", "these",
  "they", "this", "to", "was", "will", "with"

在进行更多操作之前,请查看ElasticSearch映射和分析器指南:
  • Analyzer Guide
  • Mapping Guide
  • 关于elasticsearch - Elasticsearch:搜索简单的 'a'字符时不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17944500/

    相关文章:

    php - 如何在 Elasticsearch 中设置主机配置以在 php 中连接集群节点?

    elasticsearch - 如何将Elastic search与cassandra集成?

    elasticsearch - 更新Elastic Search中的信息

    xml - Logstash XML解析失败

    elasticsearch - elasticsearch分割索引错误,路由分片必须是目标分片的倍数?

    elasticsearch - 如何在ElasticSearch中将范围函数与_score值一起使用?

    elasticsearch - 更新 ElasticSearch 中的记录

    elasticsearch - Elasticsearch:禁用多匹配查询的协调因子

    r - 使用 R 连接到 AWS Elasticsearch Service - 出现 404 错误

    elasticsearch - 当不是空字符串时,带有字段的Elasticsearch query_string过滤器