gpt4 book ai didi

elasticsearch - 同义词分析器未给出结果

转载 作者:行者123 更新时间:2023-12-03 01:03:53 25 4
gpt4 key购买 nike

我定义了以下定制分析器:

{
"analysis": {
"analyzer": {
"products-alike": {
"filter": [
"lowercase",
"product-db"
],
"tokenizer": "standard"
}
},
"filter": {
"product-db": {
"type": "synonym",
"synonyms": [
"Xiaomi,Mi,Mi3,Mi4,Redmi",
"OnePlus,OnePlusOne,OnePlus1,OnePlus2"
]
}
}
}
}

现在,我已将此映射到必填字段并完成了查询。但是只有完全匹配的结果,例如,如果我查询 Xiaomi,就会有结果,但是 MiMi3不会给我任何帮助。为什么会发生这种情况,任何人都可以帮助使其正常工作吗?

最佳答案

您只需要用小写而不是CamelCase来编写所有同义词,就像这样:

{
"analysis": {
"analyzer": {
"products-alike": {
"filter": [
"lowercase",
"product-db"
],
"tokenizer": "standard"
}
},
"filter": {
"product-db": {
"type": "synonym",
"synonyms": [
"xiaomi,mi,mi3,mi4,redmi",
"oneplus,oneplusone,oneplus1,oneplus2"
]
}
}
}
}

此后,它将起作用,即,如果您查询 Mi3,则将匹配所有同义词标记:
curl -XGET 'localhost:9200/your_index/_analyze?analyzer=products-alike&pretty' -d 'Mi3'

结果:
{
"tokens" : [ {
"token" : "xiaomi",
"start_offset" : 0,
"end_offset" : 3,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "mi",
"start_offset" : 0,
"end_offset" : 3,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "mi3",
"start_offset" : 0,
"end_offset" : 3,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "mi4",
"start_offset" : 0,
"end_offset" : 3,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "redmi",
"start_offset" : 0,
"end_offset" : 3,
"type" : "SYNONYM",
"position" : 1
} ]
}

关于elasticsearch - 同义词分析器未给出结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33428428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com