Fuzzy string matching using Levenshtein algorithm in Elasticsearch

时光毁灭记忆、已成空白 提交于 2019-12-08 06:44:50

问题


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:


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
           }

       }
    }
}


来源:https://stackoverflow.com/questions/21748164/fuzzy-string-matching-using-levenshtein-algorithm-in-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!