弹性搜索中通配符和模糊查询一起

时间:2018-09-15 11:17:27

标签: elasticsearch wildcard fuzzy-search

我正在尝试设计一个查询,在其中可以同时使用通配符和模糊查询。

根据我的说法,query_string用于通配符搜索,multi_match可用于模糊性。

我想要一个可以搜索单词的查询:-

“ elast”:-提供结果elastic和elasticsearch。 “ elasttc”:-还提供了elastic和elasticsearch的结果。

弹性搜索同时支持通配符和模糊查询?

预先感谢...

2 个答案:

答案 0 :(得分:0)

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": "testing"
          }
        },
        {
          "wildcard": {
            "title": "*testing*"
          }
        },
        {
          "fuzzy": {
            "title": "testing"
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

答案 1 :(得分:-1)

您可以将其与带有通配符的查询字符串一起使用。后缀~AUTO*启用带模糊前缀查询,您也可以使用字段选择,例如multi_match查询:

{
    "query": {
        "query_string" : {
            "fields" : ["name^2", "content^1"],
            "query" : "elasttc~AUTO*"
        }
    }
}

您也可以使用相同的AUTO参数用数字更改fuzziness关键字。

相关问题