Hi @Rahul_Lao,
queries executed in the filter context do not influence the score. But there are two way of using the geo distance query to influence the sorting as explained in The Definitive Guide:
- Use the
_geo_distance
clause in thesort
array to sort the result by distance. When using asort
clause, the score is not calculated unless explicitly enabled. - Use a
function_score
query to explicitly include the distance in the score as demonstrated in the guide chapter on decay functions and don't explicitly specify the sorting.
Only the second solution can currently be used in Kibana's Discover app at the moment, because it is not possible to specify the _geo_distance
clause in the sort
array. When sorting by the _score
field, the query could look similar to:
{
"query": {
"bool": {
"must": {
"function_score": {
"${YOUR_DECAY_FUNCTION}": {
"geo.coordinates": {
"origin": {
"lat": ${YOUR_LATITUDE},
"lon": ${YOUR_LONGITUDE}
},
"offset": "${YOUR_OFFSET}km",
"scale": "${YOUR_SCALE}km"
}
}
}
},
"filter": {
"geo_distance": {
"distance": "${YOUR_CUTOFF_DISTANCE}km",
"geo.coordinates": {
"lat": ${YOUR_LATITUDE},
"lon":${YOUR_LONGITUDE}
}
}
}
}
}
}