gpt4 book ai didi

elasticsearch - 是否可以进行nGram模糊搜索?

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

我正在尝试让nGram过滤器与模糊搜索一起使用,但不会。具体来说,我正在尝试使“粗糙”与“粗糙”匹配。

我不知道这是不可能的,还是可能的,但是我定义了错误的映射,或者映射很好,但是我的搜索未正确定义。

对应:

{
settings = new
{
index = new
{
number_of_shards = 1,
number_of_replicas = 1,

analysis = new
{
filter = new
{
edge_ngram_filter = new
{
type = "nGram",
min_gram = 3,
max_gram = 8
}
}, // filter

analyzer = new
{
analyzer_ngram = new
{
type = "custom",
tokenizer = "standard",
filter = new string[]
{
"lowercase",
"edge_ngram_filter"
}
}
} // analyzer

} // analysis

} // index
}, // settings

mappings = new
{
j_cv = new
{
properties = new
{
Text = new
{
type = "text",
include_in_all = false,
analyzer = "analyzer_ngram",
search_analyzer = "standard"
}
}
} // j_cv
} // mappings
}

文件:
{
Id = Guid.NewGuid(),
Name = "Jimmy Riddle",
Keyword = new List<string>(new string[] { "Hunting", "High", "Hotel", "California" }),
Text = "Rough Justice was a program on BBC some years ago. It was quite interesting. Will this match?"
}

搜索:
{
query = new
{
query_string = new
{
fields = new string[] { "Text" },
fuzziness = "3",
query = "rugh"
}
}
}

顺便说一句,“ugh”确实符合您的期望。

谢谢你提供的所有帮助,

亚当。

最佳答案

通常应在索引和搜索时应用同一分析器,因此search_analyzer=standard是错误的,如果将其删除,它应该可以工作。
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html

编辑:
您在查询中忘记了模糊运算符“〜”,如果将其添加到“rugh”,它将起作用!

关于elasticsearch - 是否可以进行nGram模糊搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45306573/

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