12

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

1 Answer 1

24

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

{
  "query": {
    "query_string": {
      "query": "class~"
    }
  }
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you so much bro u r amazing ;)
This worked for me, thanks. however i wonder if there is no other way because I'm passing the query from an HTTP parameter, so i think it can lead me to problems in the future (if the user adds ~ character at the end of the string).
What if I have "query": ${search}*? how to use fuzziness ?
@PalaniichukDmytro Did you find the solution to this ${search}*?
* and ~ is not supported in the same query elastic.co/guide/en/elasticsearch/reference/current/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.