0

I want to store tags for messages in ElasticSearch. I've defined the tags field as this:

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

For a message I've stored the following list in the tags field:

['a','b','c']

Now if I try to search for tag 'b' with the following query, it gives back the message and the tags:

{
  'filter': {
    'limit': {
      'value': 100
    }
  },
  'query': {
    'bool': {
      'should': [
        {
          'text': {
            'tags': 'b'
          }
        }
      ],
      'minimum_number_should_match': 1
    }
  }
}

There goes the same with tag 'c'. But if I search for tag 'a' with this:

{
  'filter': {
    'limit': {
      'value': 100
    }
  },
  'query': {
    'bool': {
      'should': [
        {
          'text': {
            'tags': 'a'
          }
        }
      ],
      'minimum_number_should_match': 1
    }
  }
}

It gives back no results at all! The answer is:

{
  'hits': {
    'hits': [],
    'total': 0,
    'max_score': None
  },
  '_shards': {
    'successful': 5,
    'failed': 0,
    'total': 5
  },
  'took': 1,
  'timed_out': False
}

What am I doing wrong? (It doesn't matter that the 'a' is the first element of the list, the same goes for ['b','a','c']. It seems it has problems only with a single 'a' character.

4

2 回答 2

1

如果您没有设置任何分析器并映射到您的索引,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 映射和分析器指南:

于 2013-07-30T14:05:34.650 回答
0

可能涉及一些词干或停用词列表。尝试确保不分析该字段。

'tags': {'type': 'string', 'index_name': 'tag', "index" : "not_analyzed"}

类似:在弹性搜索中将整个字符串与破折号匹配

于 2013-07-30T13:22:44.347 回答