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 namesof 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. my desired result is Milk > steamed milk or chocolate milk > silk(typo)
but the result I get is silk milk > steamed milk or chocolate milk > milk.
"query": {
"bool": {
"should": [
{
"match": {
"name": {
"query": "milk",
"fuzziness": auto,
"boost": 1
}
}
},
{
"match": {
"name": {
"query": "milk",
"boost": 20
}
}
},
{
"exists": {
"field": "field1"
}
}
],
"must": [
{
"match": {
"status": "A"
}
}
]
}
I also tried the function score queries as below,it meets all of my needs except
It only returns "milk" and "silk". I does not return any phrase which contains "milk" like "steamed" milk or "chocolate milk
"query":{
"function_score":{
"query":{
"bool":{
"must":[
{
"match":{
"name.keyword":{
"query":"milk",
"fuzziness":"AUTO",
"boost": 10
}
}
}
],
"filter": [
{
"exists": {
"field": "field"
}
},
{
"match": {
"status": "A"
}
}
]
}
},
"boost_mode":"multiply",
"functions":[
{
"filter":{
"term":{
"name":"milk"
}
},
"weight":"5"
}
]
}
}, "sort":[ "_score", { "name.keyword":{ "order":"asc" } } ], "track_scores":true, "size": 60, "indices_boost": [ { "index1":1.3 }, { "index2": 1.3 } ] }
Does anyone have any suggestion for me ?how to get results in the order I need