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
In Elasticsearch, you can write queries that implement fuzzy matching and specify the maximum edit distance that will be allowed.
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.
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.
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.
You need to use the ~ operator to have fuzzy searching in query_string
:
{
"query": {
"query_string": {
"query": "class~"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With