Elasticsearch 模糊短语 [英] Elasticsearch Fuzzy Phrases

查看:20
本文介绍了Elasticsearch 模糊短语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询来为我的搜索添加模糊性.但是,我现在意识到匹配查询不像 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆