我想在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映射和分析器指南:
关于elasticsearch - Elasticsearch:搜索简单的 'a'字符时不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17944500/