Howdy!
I'm trying to boost search results by a status field (it's an enumeration). My query is as follows:
{
"query" : {
"bool" : {
"must" : ...,
"should" : [
{
"term" : {
"status" : { "value" : "Valid", "boost" : 5 }
}
},
{
"term" : {
"status" : { "value" : "Pending", "boost" : 4 }
}
},
{
"term" : {
"status" : { "value" : "Expired", "boost" : 3 }
}
},
{
"term" : {
"status" : { "value" : "Invalid", "boost" : 2 }
}
},
{
"term" : {
"status" : { "value" : "Unknown", "boost" : 1 }
}
}
]
}
}
}
However, this does not sort the results as I would expect. I get the results as follows:
{
"hits" : [
"max_score": 2.1227207,
"hits": [
{
"_score": 2.1227207,
"_source": { "status": "Pending" }
},
{
"_score": 1.5702559,
"_source": { "status": "Unknown" }
},
{
"_score": 1.4841971,
"_source": { "status": "Valid" }
},
{
"_score": 1.4767004,
"_source": { "status": "Expired" }
}
]
]
}
Obviously I was aiming to have Valid results first, then Pending, ..., and last Unknown.
If I remove the should boolean-array of boosted statuses altogether, then all the results have the same score (as I would suspect).
Am I missing something? Why is this query not working as I would suspect? https://www.elastic.co/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html would IMO suggest that this is something that would be possible...
Thank you!
EDIT:
- the
status
-field mapping isnot_analyzed
that's why I use case-sensitive statuses in the query