I have three fields name
, name.ngram
and model_number
that I am trying to search. I have boosted name
so any match on name
ranks higher than name.ngram
. However, I still have some cases where the name.ngram
doesn't match with terms that contain weird punctuation so I want to complete my query with a fuzzy search on the name
and model_number
fields field.
Here is the query I ultimately want. If I remove the second multi_match, the query works but does not include the fuzzy search.
{
explain: true,
query:{
function_score: {
"query": {
"bool": {
"should":
{
multi_match:{
fields: ["name^10", "name.ngram", "model_number"],
type: "most_fields",
query: "#{query}"
},
multi_match:{
fields: ["name", "model_number"],
type: "most_fields",
query: "#{query}",
fuzziness: "2"
}
},
"filter": {
"bool": {
"must": filters
}
}
}
},field_value_factor:{
field: "popularity",
modifier: "log1p",
factor: 5
},
boost_mode: "sum"
}
},highlight: {
fields: {
:"*" => {}
}
},
aggs: {categories: { terms: { field: "category.raw"} }}
}
I want to ultimately treat the fuzzy search like I do the ngram so that non fuzzy matches rank first and fuzzy matches rank second. How do I add a second multi_match query that would allow for this?