0
I'm trying to configure Elasticsearch to give me both exact matches and fuzzy matches, and also phrase matches. I'm using Elasticsearch to search names of foods in a database, and I want it to be fuzzy to allow for minor spelling errors.
Based on the advice I've found on the matter, I'm using "match" and "fuzziness" instead of "fuzzy", which definitely seems to be more accurate.
The problem is that the exact matches seem to be having a lower score than partial matches and fuzziness matches. I can get it, but the problem is I need to call two different indices and if the "exact match" existed the results of the index 2 shows up at first then the exact match of the index1 and .... but if the exact match is not existed in the index2, then the exact match of the index1 shows up first. My desired result is Milk(from index2) > Milk(from index1), chocolate milk > silk(typo)
But the result I get is silk milk(from index1) > chocolate milk > milk(from index2).
If I boost the index2,all the results of index2 get higher ranking even the non "exact match" which is not desirable.
"query": {
"bool": {
"should": [
{
"match_bool_prefix": {
"name": {
"query": "milk",
"fuzziness":"Auto",
"boost": 1
}
}
},
{
"match": {
"name": {
"query": "milk",
"boost": 10
}
}
},
{
"exists": {
"field": "common", #-----> this field only existed in index2
"boost": 1.25
}
},
{
"exists": {
"field": "calories",
"boost": 1
}
}
],
"must": [
{
"match": {
"status": "A"
}
}
]
}
}, "size": 50, "indices_boost": [ { "index2":1.31 }, { "index1":1.3 } ] }
but the result I get is
"_index": "index1",
"_score": 84.111664,
"name": "milk",
}
{"_index": "index1",
"_score": 83.111664,
"name": "chocolate milk"
}
{"_index": "index1",
"_score": 82.111664,
"name": " oat milk"}
{
"_index": "index2",
"_score": 81.111664,
"name": "milk"
but my desired result is
"_index": "index2",
"_score": 84.111664,
"name": "milk",
}
{"_index": "index1",
"_score": 83.111664,
"name": "milk"
}
{"_index": "index1",
"_score": 82.111664,
"name": " chocolate milk"}
{
"_index": "index2",
"_score": 81.111664,
"name": "oat milk"