弹性搜索中的模糊匹配和前缀匹配

2024-04-20 07:48:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我的用例是在基于模糊和前缀匹配检索的字段中突出显示多个短语/单词。为此,我目前使用span_near处理短语,span_multi允许在短语术语中使用模糊性。我还需要使用prefix_length,这样fuzzy只允许用于前缀匹配后的字符,但span_multi不允许多个多术语查询。还有其他办法吗

    "query":{
    "bool":{
        "should":[{
  "span_near": {
    "clauses": [
      {
        "span_multi": {
          "match": {
            "fuzzy": {
              "comment": {
                "fuzziness": "5",
                "value": "Beata"
              }
            }
          }
        }
      },
        {
        "span_multi": {
          "match": {
            "fuzzy": {
              "comment": {
                "fuzziness": "5",
                "value": "Rosenane"
              }
            }
          }
        }
      }
    ],
    "in_order": False,
  }},{
  "span_near": {
    "clauses": [
      {
        "span_multi": {
          "match": {
            "fuzzy": {
              "comment": {
                "fuzziness": "5",
                "value": "Christna"
              }
            }
          }
        }
      }
    ],
    "in_order": False,
  }}]
}
},
    "highlight" : {
    "fields" : {
      "comment" : { "pre_tags" : ["<temp>"], "post_tags" : ["</temp>"],
                   "number_of_fragments" : 0
                  }

  }
    }
    
}

Tags: infalsevaluematchtagscommentordermulti