Reputation: 8187
I have the 2 following entries indexed in elasticsearch:
united states
united states minor outlying islands
I'd like to fuzzy match with a distance of 1, thus if i send the follwing query terms, I'd like to only match united states
:
united tsates
unitedstates
united sates
I've tried a span_near
approach as suggested in other questions (here and here), but this still matches both united states
and united states minor outlying islands
.
How can I match only united states
with the aforementioned list of terms ?
First attempt:
{
"query":{
"bool":{
"must":{
"match":{
"country_name":{
"query":"united tsates",
"fuzziness":1,
"operator": "and"
}
}
}
}
}
}
Attempt with span_near
:
{
"query":{
"span_near":{
"clauses":[
{
"span_multi":{
"match":{
"fuzzy":{
"country_name":{
"fuzziness":"1",
"value":"united"
}
}
}
}
},
{
"span_multi":{
"match":{
"fuzzy":{
"country_name":{
"fuzziness":"1",
"value":"tsates"
}
}
}
}
}
],
"slop":0,
"in_order":"true"
}
}
}
Upvotes: 0
Views: 139
Reputation: 768
How about a fuzzy query on keyword field? Something like this
GET test_index/_search
{
"query": {
"fuzzy": {
"country_name.keyword": "united tsates"
}
}
}
Upvotes: 1