Wildcard and Fuzzy query together in elastic search

*爱你&永不变心* 提交于 2019-12-06 15:53:50

问题


I am trying to design a query in which, I can use wildcard and Fuzzy query together.

According to me, query_string is used for wildcard searches and multi_match can be used for fuzziness.

I want a query which will search on words :-

"elast" : - provide results elastic and elasticsearch. "elasttc" :- also provide results as elastic and elasticsearch.

Elastic search supports wildcard and fuzzy query together??

Thanks in advance...


回答1:


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



回答2:


You can use it with Query String with wildcards. The suffix ~AUTO* enables a prefix query with fuzzy, also you can use the fields selection like multi_match query:

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

You can change the AUTO keyword with a numeric value too, as the same fuzziness parameter.



来源:https://stackoverflow.com/questions/52344191/wildcard-and-fuzzy-query-together-in-elastic-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!