Elasticsearch模糊短语 [英] Elasticsearch Fuzzy Phrases
问题描述
我有以下查询,可在搜索时增加模糊性。但是,我现在意识到,匹配查询不像match_phrase那样考虑搜索字符串中单词的顺序。但是,我无法获得match_phrase给我模糊的结果。有没有一种方法可以告诉匹配项考虑单词之间的顺序和距离?
I have the following query to add fuzziness to my search. However, I now realize that the match query doesn't consider the order of the words in the search string, as the match_phrase does. However, I can't get match_phrase to give me results with fuzziness. Is there a way to tell match to consider the order and distance between words?
{
"query": {
"match": {
"content": {
"query": "some search terms like this",
"fuzziness": 1,
"operator": "and"
}
}
}
}
推荐答案
最终我发现我需要使用 span
查询的组合,从而可以进行大量的微调模糊和倾斜。我需要添加一个函数来手动标记我的短语并以编程方式添加到子句数组中:
Eventually figured out that I needed to use a combination of span
queries, which give an excellent amount of fine tuning to fuzziness and slop. I needed to add a function to manually tokenize my phrases and add to the "clauses" array in an programmatically:
{"query":
{
"span_near": {
"clauses": [
{
"span_multi": {
"match": {
"fuzzy": {
"content": {
"fuzziness": "2",
"value": "word"
}
}
}
}
},
{
"span_multi": {
"match": {
"fuzzy": {
"content": {
"fuzziness": "2",
"value": "another"
}
}
}
}
}
],
"slop": 1,
"in_order": "true"
这篇关于Elasticsearch模糊短语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!