1

I have just started exploring Elasticsearch. I created a document as follows:

curl -XPUT "http://localhost:9200/cities/city/1" -d'
{
    "name": "Saint Louis"

}'

I now tried do a fuzzy search on the name field with a Levenshtein distance of 5 as follows :

curl -XGET "http://localhost:9200/_search " -d'
{
    "query": {
       "fuzzy": {
           "name" : {
               "value" : "St. Louis",
               "fuzziness" : 5
           }

       }
    }
}'

But its not returning any match. I expect the Saint Louis record to be returned. How can i fix my query ?

Thanks.

1 Answer 1

3

The problem with your query is that only a maximum edit distance of 2 is allowed.

In the case above what you probably want to do is have a synonym for St. to Saint, and that would match for you. Of course, this would depend on your data as St could also be "street".

If you want to just test the fuzzy searching, you could try this example

curl -XGET "http://localhost:9200/_search " -d'
{
    "query": {
       "fuzzy": {
           "name" : {
               "value" : "Louiee",
               "fuzziness" : 2
           }

       }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

I have a query with should with function_score with fuzziness 0.75 with multi_match with cross_field My query is a term without one last character - for instance "NAM" instead of "NAME" By fuzziness rules it must be returned to me , but I don't get results. What would you suggest on this matter? Is there a way around without NGRAM ?
Gregory, it would probably be best to post that as a new question, along with details of your mapping and query.
@Gregory fuzziness is not supported for cross_field type multi_match queries.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.