Вопрос

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.

Это было полезно?

Решение

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
           }

       }
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top