When running the wikidata autocomplete queries it's possible for results to have 0 score due to the way it is constructed. This is not currently a critical problem, but future versions of elastic disallow negative scores.
{
"bool": {
"should": [
{
"bool": {
"filter": [ { "match": { "labels_all.prefix": "albert" } } ],
"should": [
{
"dis_max": {
"tie_breaker": 0,
"queries": [
{ "constant_score": { "filter": { "match": { "labels.en.near_match": "albert" } }, "boost": 2 } },
{ "constant_score": { "filter": { "match": { "labels.en.near_match_folded": "albert" } }, "boost": 1.6 } },
{ "constant_score": { "filter": { "match": { "labels.en.prefix": "albert" } }, "boost": 1.1 } },
{ "constant_score": { "filter": { "match": { "labels_all.near_match_folded": "albert" } }, "boost": 0.001 } }
]
}
}
]
}
},
{ "term": { "title.keyword": "albert" } }
],
"minimum_should_match": 1,
"filter": [ { "term": { "content_model": "wikibase-item" } } ]
}
}https://www.wikidata.org//w/api.php?action=wbsearchentities&format=json&search=abstract+art&language=en&cirrusDumpResult
The 6th result has a score of 0:
{
_index: "wikidatawiki_content_1537536135",
_type: "page",
_id: "55400981",
_score: 0,
_source: {
namespace: 0,
title: "Q55370741",
descriptions: {
en: "exhibition"
}
},
highlight: {
labels.nl.prefix: [
"0:0-12:40|Abstract art, Befreiung, Stil und Ironie"
]
}
}In this particular case there are only 7 results, so a score wouldn't change anything, but this likely occurs elsewhere. Item's can match the bool filter but nothing else, resulting in a score of 0. Negative rescore boosts take the 0 and turn it negative.Converting that filter into a must with tiny boost should ensure we always have some sort of score to apply basic ordering:
{
"bool": {
"should": [
{
"bool": {
"must": [
{ "constant_score": { "filter": { "match": { "labels_all.prefix": "albert" }}, "boost": 0.001} }
],
"should": [
{
"dis_max": {
"tie_breaker": 0,
"queries": [
{ "constant_score": { "filter": { "match": { "labels.en.near_match": "albert" } }, "boost": 2 } },
{ "constant_score": { "filter": { "match": { "labels.en.near_match_folded": "albert" } }, "boost": 1.6 } },
{ "constant_score": { "filter": { "match": { "labels.en.prefix": "albert" } }, "boost": 1.1 } },
{ "constant_score": { "filter": { "match": { "labels_all.near_match_folded": "albert" } }, "boost": 0.001 } }
]
}
}
]
}
},
{ "term": { "title.keyword": "{{QUERY_STRING}}" } }
],
"minimum_should_match": 1,
"filter": [ { "term": { "content_model": "wikibase-item" } } ]
}
}For the negative boosts, perhaps we can come up with a way to switch them from sum's to products. A product with a value < 1 will de-boost things without going negative.