elasticsearch 弹性模糊查询

cpjpxq1n  于 2023-04-05  发布在  ElasticSearch
关注(0)|答案(1)|浏览(129)
GET index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "default_operator": "AND",
            "default_field": "searchText",
            "query": "rob",
            "fuzziness": "AUTO"
          }
        }
      ]
    }
  }
}

这是字段searchText的Map

"searchText" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }

搜索查询没有返回任何包含值bob作为searchText一部分的文档。是否必须以其他方式更新查询以避免模糊

j7dteeu8

j7dteeu81#

可以使用~运算符在query_string中进行模糊搜索:

POST test_fuzzy/_doc
{
  "searchText": "bob"
}

GET test_fuzzy/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "default_operator": "AND",
            "default_field": "searchText",
            "query": "rob~"
          }
        }
      ]
    }
  }
}

或者你可以使用一个带有“模糊性”的匹配查询:“自动”

GET test_fuzzy/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "searchText": {
              "query": "rob",
              "fuzziness": "AUTO"
            }
          }
        }
      ]
    }
  }
}

相关问题