gpt4 book ai didi

即使遗漏首字母,Elasticsearch 拼写检查建议

转载 作者:行者123 更新时间:2023-12-02 22:13:07 24 4
gpt4 key购买 nike

我创建了一个这样的索引:

curl --location --request PUT 'http://127.0.0.1:9200/test/' \
--header 'Content-Type: application/json' \
--data-raw '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"properties" : {
"word" : { "type" : "text" }
}
}
}'

当我创建文档时:
curl --location --request POST 'http://127.0.0.1:9200/test/_doc/' \
--header 'Content-Type: application/json' \
--data-raw '{ "word":"organic" }'

最后,用一个故意拼错的词进行搜索:
curl --location --request POST 'http://127.0.0.1:9200/test/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
"suggest": {
"001" : {
"text" : "rganic",
"term" : {
"field" : "word"
}
}
}
}'

“organic”这个词丢失了第一个字母 - ES 从来没有为这种拼写错误提供建议选项(对于任何其他拼写错误 - 'orgnic'、'oragnc' 和 'organi' 绝对适用)。我错过了什么?

最佳答案

这是因为 prefix_length参数:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html .它默认为 1,即至少从术语开头的 1 个字母必须匹配。您可以设置 prefix_length到 0 但这会对性能产生影响。只有你的硬件、你的设置和你的数据集才能准确地向你展示在你的情况下这些将是什么,即尝试它:)。但是,请注意 - Elasticsearch 和 Lucene 开发人员出于某种原因将默认值设置为 1。

这是一个查询,它会在我执行您的设置步骤后返回您在 Elasticsearch 7.4.0 上的建议结果。

curl --location --request POST 'http://127.0.0.1:9200/test/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
"suggest": {
"001" : {
"text" : "rganic",
"term" : {
"field" : "word",
"prefix_length": 0
}
}
}
}'

关于即使遗漏首字母,Elasticsearch 拼写检查建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59527443/

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