对于下面的查询,我正在搜索文本“基督”。结果没有显示正确的顺序。我有一个记录为“克莉丝汀”,但它不是显示为第一个文件。你能帮我解决这个订单问题吗?我正在使用Elasticsearch 8.5.3。但在Elasticsearch 2.x版本中也是如此。
Map和设置如下,
{
"template": {
"settings": {
"index": {
"max_ngram_diff": "3",
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"analysis": {
"analyzer": {
"special_char_edge_1_gram_analyzer": {
"filter": [
"lowercase"
],
"char_filter": [
"string_special_character_char_filter"
],
"type": "custom",
"tokenizer": "edge_1_gram_tokenizer"
},
"tokenizer": {
"edge_1_gram_tokenizer": {
"token_chars": [
"letter",
"digit"
],
"min_gram": "1",
"type": "edge_ngram",
"max_gram": "100"
}
},
"number_of_shards": "1",
"number_of_replicas": "1"
}
},
"mappings": {
"name": {
"properties": {
"first": {
"type": "text",
"fields": {
"special_char_edge_1_gram_analyzer": {
"type": "text",
"analyzer": "special_char_edge_1_gram_analyzer"
}
}
}
}
}
},
"aliases": {}
}
}
}
}
}
}
}
Query is below,
GET as.contact-154/_search
{
"query": {
"bool": {
"should": {
"multi_match": {
"type": "best_fields",
"query": "christ",
"fields": [ "name.first^2", "name.first.special_char_edge_1_gram_analyzer^5" ]
}
}
}
},
"_source": ["id","name.first","name.last"],
"highlight": {
"pre_tags": [
"<span class='text-highlight'>"
],
"post_tags": [
"</span>"
],
"fields": {
"name.first": {},
"id": {}
}
},
"from": 0,
"size": 100
}
Result,
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 125,
"relation": "eq"
},
"max_score": 62.842735,
"hits": [
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "127848",
"_score": 62.842735,
"_source": {
"name": {
"last": "Poeschl",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "128911",
"_score": 62.842735,
"_source": {
"name": {
"last": "Rhode",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "128925",
"_score": 62.842735,
"_source": {
"name": {
"last": "Hanson",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "129102",
"_score": 62.842735,
"_source": {
"name": {
"last": "Cooper",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "129116",
"_score": 62.842735,
"_source": {
"name": {
"last": "Sipos",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "129119",
"_score": 62.842735,
"_source": {
"name": {
"last": "Sipos",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "129147",
"_score": 62.842735,
"_source": {
"name": {
"last": "Dudlery",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "1264420",
"_score": 62.842735,
"_source": {
"name": {
"last": "Jaquess",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "1264421",
"_score": 62.842735,
"_source": {
"name": {
"last": "Jaquess",
"first": "Chris"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Chris</span>"
]
}
},
{
"_index": "es.contact-154.23-05-12-7-04-12",
"_id": "127930",
"_score": 60.612587,
"_source": {
"name": {
"last": "Vanderzanden",
"first": "Christine"
}
},
"highlight": {
"name.first.special_char_edge_1_gram_analyzer": [
"<span class='text-highlight'>Christ</span>ine"
]
}
}
]
}
}
最新结果,
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 125,
"relation": "eq"
},
"max_score": 104.737885,
"hits": [
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "127848",
"_score": 104.737885,
"_source": {
"name": {
"last": "Poeschl",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "128911",
"_score": 104.737885,
"_source": {
"name": {
"last": "Rhode",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "128925",
"_score": 104.737885,
"_source": {
"name": {
"last": "Hanson",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "129102",
"_score": 104.737885,
"_source": {
"name": {
"last": "Cooper",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "129116",
"_score": 104.737885,
"_source": {
"name": {
"last": "Sipos",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "129119",
"_score": 104.737885,
"_source": {
"name": {
"last": "Sipos",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "129147",
"_score": 104.737885,
"_source": {
"name": {
"last": "Dudlery",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "1264420",
"_score": 104.737885,
"_source": {
"name": {
"last": "Jaquess",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "1264421",
"_score": 104.737885,
"_source": {
"name": {
"last": "Jaquess",
"first": "Chris"
}
}
},
{
"_index": "es.contact-154.23-05-12-14-34-46",
"_id": "127930",
"_score": 102.020966,
"_source": {
"name": {
"last": "Vanderzanden",
"first": "Christine"
}
}
}
]
}
}
1条答案
按热度按时间vzgqcmou1#
问题是边元分析器也在搜索时启动,因此,搜索到的字符串
christ
在搜索时被分析器解析为chris
,并与第一条记录匹配。这不是我们想要的。你应该像这样修改你的Map,并指定一个
standard
search_analyzer
,这样搜索的文本就不会被边缘化: