Hello,
I am confused about the calculation of relevance scores with distance_feature
. In the documentation it says that:
The
distance_feature
query calculates a document’s relevance score as follows:
relevance score = boost * pivot / (pivot + distance)
I have the following query
{
"_source": false,
"query": {
"distance_feature": {
"field": "address.location",
"origin": {
"lat": 52.5065133,
"lon": 13.1445545
},
"pivot": "100000m",
"boost": __BOOST__
}
},
"script_fields": {
"distance": {
"script": {
"source": "doc['address.location'].arcDistance(params.lat,params.lon)",
"params": {
"lat": 52.5065133,
"lon": 13.1445545
}
}
}
}
}
When running the query with boost=1.0
, the documents are scored as expected.
The document below has score 1 * (100000/(100000+2398.9804327731676)) = 0.9765722
.
All scores are in [0, 1].
{
"_index" : "some_index",
"_type" : "_doc",
"_id" : "57114",
"_score" : 0.9765722,
"fields" : {
"distance" : [
2398.9804327731676
]
}
}
Yet when running the same query with boost=2.0
, some score values are bigger than 2.0.
For the same document the calculation does not work out anymore: 2 * (100000/(100000+2398.9804327731676)) = 1.9531444
yet the returned score is 3.9062889
{
"_index" : "some_index",
"_type" : "_doc",
"_id" : "57114",
"_score" : 3.9062889,
"fields" : {
"distance" : [
2398.9804327731676
]
}
}
Am I misunderstanding the docs or have a stupid mistake in my thought process ? I would be glad if someone could help me out with this
EDIT Just to give some context: This is relevant for me because i sometimes use constant_score
queries to make sure that certain hits are sorted to the top. In such a case it's useful to know that the distance_feature
only adds to the score within a certain range. This is how I interpreted the formula, the additional score is in [0, boost]
.
Best regards