在 Mapping 里面,将 dynamic 参数设置成 strict 可以拒绝索引包含未知字段的文档。 此条 Tips 由 medcl 贡献。

ES使用了同义词后,检索结果排序总是不准确,如何优化?

Elasticsearch | 作者 Dalon | 发布于2022年11月09日 | 阅读数:2387

假设 同义词 :小米,高粱米,大米,白米,
我检索词为 “高粱米”,
检索结果出来 小米全部在前面,高粱米在后面。
这边怎么对检索词进行增加权重,使得满足检索词的在前面呢?
还有很多类似的。
 
这是我部分的检索语句,看了下其他字段都没有符合的。只有goodsName有符合的,而且权重设置的最高
"function_score": {
"functions": [{
"filter": {
"match": {
"goodsName": {
"query": "高粱米",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"minimum_should_match": "3<90%",
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 10.0
}
}
},
"weight": 10.0
},

 
微信图片_20221109175711.jpg
已邀请:

qw8613243

赞同来自: ylcool

要解决这个问题,需要考虑索引查询的精确率和召回率 。
 
精准率,站在用户角度,召回的数据贴合用户的预期,越准确越好
召回率,满足检索条件的语句都尽可能的召回,到底要什么,让用户在结果中二次再做选择。
 

解决办法:混合索引检索方案
词索引——使用 ik_smart 分词。
字索引——使用 standard 标准分词。
 
举例:
PUT test-20220928
{
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "ik_smart",
"fields": {
"standard": {
"type": "text",
"analyzer": "standard"
},
"keyword": {
"type": "keyword"
}
}
}
}
}
}

POST test-20220928/_bulk
{"index":{"_id":1}}
{"title":"手表带真好看"}
{"index":{"_id":2}}
{"title":"手表最近卖的不好,咋整"}
{"index":{"_id":3}}
{"title":"卡西欧手表不错哦"}
{"index":{"_id":4}}
{"title":"手表"}

查询
POST test-20220928/_search
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"title": {
"query": "手表",
"boost": 50
}
}
}
],
"must": [
{
"match": {
"title.standard": "手表"
}
}
]
}
}
}


Pasted_Graphic_2.png

 

要回复问题请先登录注册