문제

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