I've got a field in elasticsearch index, in which I'm trying to search and I'd like for the documents where this field's value begins with the search term to be higher up than documents, where the term is somewhere in the middle of a long phrase. E.g.: When searching for "lorem",
{
"title": "Lorem"
}
should have higher score than
{
"title": "The time I said Lorem"
}
or
{
"title": "The Lorem"
}
or even
{
"title": "Lorem impsum"
}
However this is often not the case with a simple match
, match_phrase_prefix
or query_string
query.
So far I've tried combining prefix
query with a match
query while boosting the prefix, but the boosting doesn't seem to work as I expected, i.e. the results are the same just boosted by 10
...
{
"should": [
{
"prefix": {
"title": {
"value": query,
"boost": 10
}
}
}
{
"match": {
"title": {
"query": query,
"boost": 3,
"fuzziness": "AUTO"
}
}
}
]
}
...
Also, not sure if this is relevant, but the title
field is actually nested, i.e. it's alternative_names.title
Is there any elegant solution to this with elasticsearch?