【发布时间】:2020-08-24 16:36:59
【问题描述】:
我正在我的 elasticsearch 索引中搜索 Bob Smith。结果 Bob Smith 和 Bobbi Smith 都以相同的分数返回响应。我希望 Bob Smith 获得更高的分数,以便它首先出现在我的结果集中。为什么分数相等?
这是我的查询
{
"query": {
"query_string": {
"query": "Bob Smith",
"fields": [
"text_field"
]
}
}
}
以下是我的索引设置。我正在使用此处描述的 ngram 令牌过滤器:https://qbox.io/blog/an-introduction-to-ngrams-in-elasticsearch
{
"contacts_5test": {
"aliases": {},
"mappings": {
"properties": {
"text_field": {
"type": "text",
"term_vector": "yes",
"analyzer": "ngram_filter_analyzer"
}
}
},
"settings": {
"index": {
"number_of_shards": "1",
"provided_name": "contacts_5test",
"creation_date": "1588987227997",
"analysis": {
"filter": {
"ngram_filter": {
"type": "nGram",
"min_gram": "4",
"max_gram": "4"
}
},
"analyzer": {
"ngram_filter_analyzer": {
"filter": [
"lowercase",
"ngram_filter"
],
"type": "custom",
"tokenizer": "standard"
}
}
},
"number_of_replicas": "1",
"uuid": "HqOXu9bNRwCHSeK39WWlxw",
"version": {
"created": "7060199"
}
}
}
}
}
这是我的查询结果...
"hits": [
{
"_index": "contacts_5test",
"_type": "_doc",
"_id": "1",
"_score": 0.69795835,
"_source": {
"text_field": "Bob Smith"
}
},
{
"_index": "contacts_5test",
"_type": "_doc",
"_id": "2",
"_score": 0.69795835,
"_source": {
"text_field": "Bobbi Smith"
}
}
]
如果我改为搜索 Bobbi Smith,elastic 会返回两个文档,但 Bobbi Smith 的得分更高。这更有意义。
【问题讨论】:
标签: elasticsearch match n-gram relevance