Im trying to get Elastic Search making a phonetic search in a list of cities. My goal is to find matching results even if the user uses an incorrect spelling.
I've done the following steps:
Remove domain
curl -X DELETE "localhost:9200/city/"
Create new domain
curl -X PUT "localhost:9200/city/?pretty" -H 'Content-Type: application/json' -d' { "settings": { "index": { "analysis": { "analyzer": { "my_analyzer": { "tokenizer": "standard", "filter": [ "lowercase", "my_metaphone" ] } }, "filter": { "my_metaphone": { "type": "phonetic", "encoder": "metaphone", "replace": true } } } } }, "mappings": { "properties": { "name": { "type": "text", "analyzer": "my_analyzer" } } } }'
Fill some sample data
curl -X PUT "localhost:9200/city/_doc/1?pretty" -H 'Content-Type: application/json' -d' { "name":"Mayrhofen" } ' curl -X PUT "localhost:9200/city/_doc/2?pretty" -H 'Content-Type: application/json' -d' { "name":"Ischgl" } ' curl -X PUT "localhost:9200/city/_doc/3?pretty" -H 'Content-Type: application/json' -d' { "name":"Saalbach" } '
Search in the cities - here I get an result
curl -X GET ""localhost:9200/city/_search?pretty" -H 'Content-Type: application/json' -d' { "query":{ "query_string":{ "query":"Mayrhofen" } } } '
I tried the query with Mayerhofen and expected the same result as using Mayrhofen. The same issue with Ischgl and Ichgl or Saalbach and Salbach.
Where's my error? Is something mssing?