弹性搜索模糊短语

eco*_*eer 10 elasticsearch

我有以下查询为我的搜索添加模糊性.但是,我现在意识到匹配查询不考虑搜索字符串中单词的顺序,就像match_phrase那样.但是,我不能得到match_phrase给我模糊的结果.有没有办法告诉匹配考虑单词之间的顺序和距离?

{
    "query": {
        "match": {
            "content": {
                "query": "some search terms like this",
                "fuzziness": 1,
                "operator": "and"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

eco*_*eer 15

最终我发现我需要使用一组span查询,这些查询可以对模糊和污点进行大量的微调.我需要添加一个函数来手动标记我的短语并以编程方式添加到"子句"数组:

{"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"
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的回复,它对我有用,但我想我应该提到“内容”应该替换为您要搜索的“field_name”。例如,如果您想搜索 `title` 字段,请将 `"content": {"fuziness": "2", "value": "word"}` 替换为 `"title": {"fuziness": “2”,“值”:“单词”}`。 (2认同)