Hello everyone, I have been trying to improve my search for a while now
I am searching for names with the help of search_as_you_type and a mixture of match_phrase and the math_phrase_prefix. the search itself works wonderfully. However, I still have a problem:
If the search is not yet long, and I search e.g. with Da
, the results are ranked as follows:
Dave Peter
Peter Dave
But of course I would like the weighting of the first ngram to be much higher. I have tried to give the first ngram a higher boost with a span_first, unfortunately without success. Does anyone have any tips on the best way to do this? Thanks for your help!
{
"query": {
"bool": {
"should": [
{
"span_first": {
"match": {
"span_term": {
"name.name": "searchTerm"
}
},
"end": 1,
"boost": 5
}
},
{
"match_phrase": {
"name.name": {
"query": "searchTerm",
"boost": 10
}
}
},
{
"match_phrase_prefix": {
"name.name": {
"query": "searchTerm",
"boost": 7
}
}
},
{
"multi_match": {
"query": "searchTerm",
"type": "bool_prefix",
"fields": [
"name.name",
"name.name._2gram",
"name.name._3gram"
],
"operator": "and",
"minimum_should_match": "100%"
}
},
{
"multi_match": {
"query": "searchTerm",
"fields": [
"name.name",
"name.name._2gram",
"name.name._3gram"
],
"fuzziness": 2,
"operator": "and",
"minimum_should_match": "100%",
"boost": 0.5
}
}
]
}
}
}