Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fuzzy searching with query_string Elasticsearch

i have a record saved in Elasticsearch which contains a string exactly equals to Clash of clans

now i want to search this string with Elasticsearch and i using this

{
    "query_string" : {
        "query" : "clash"
    }
}

its working perfectly but now if i write

"query" : "class"

it dont give me back any record so i realize i should use Fuzzy searching so i come to know that i can use fuzziness parameter with query_string so i did

{
    "query_string" : {
        "query" : "clas"
        "fuzziness":1
    }
}

but still elasticsearch is not returning anything! kindly help and i cant use Fuzzy query i just can use query_string. Thanks

like image 559
maq Avatar asked Oct 19 '15 22:10

maq


People also ask

Does Elasticsearch do fuzzy matching?

In Elasticsearch, you can write queries that implement fuzzy matching and specify the maximum edit distance that will be allowed.

How does Elasticsearch fuzzy search work?

In Elasticsearch, fuzzy query means the terms are not the exact matches of the index. The result is 2, but you can use fuzziness to find the correct word for a typo in Elasticsearch's fuzzy in Match Query. For 6 characters, the Elasticsearch by default will allow 2 edit distance.

How do you handle typos in Elasticsearch using fuzzy query?

Handling a typo in Elasticsearch is very easy and can improve the user's experience. The simplest way to handle a typo is to just add "fuzziness":"AUTO" in your Match Query. If you want to tune the Query, there are some parameters that you can change with the "fuzziness" being the most important.

What is fuzzy query in Elasticsearch?

Fuzzy queryedit. Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance. An edit distance is the number of one-character changes needed to turn one term into another.


1 Answers

You need to use the ~ operator to have fuzzy searching in query_string:

{
  "query": {
    "query_string": {
      "query": "class~"
    }
  }
}
like image 188
Andrei Stefan Avatar answered Oct 14 '22 07:10

Andrei Stefan