Is there a way to contribute to the relevance score of documents using distance?

I want to boost the score of records that are close to some geo position.
Elastic has filters for geo, but that just includes or excludes records.
Is there a way to manipulate the score using the distance? I know there
is a custom_score query where I could specify something like "script" : "_score

  • doc['my_numeric_field'].value". The question is, how would I use the
    distance in the calculation, and not the value of the numeric field?

--

You can calculate the distance using the following
expression: doc['your_geo_field'].distanceInKm(lat, lon) and then use it to
figure out the boost factor. For example this script: "_score *
(doc['your_geo_field'].distanceInKm(40, -70) < 100 : 2.0: 1.0)" will apply
boost 2.0 to all records that are located within 100km from the location
(40, -70). Alternatively, you can use Custom Filters Score Queryhttp://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.htmlto boost records using a geo_distance filter. So, a faster equivalent of
the above expression would be:

{
"custom_filters_score": {
"query": {
.... some query ....
},
"filters": [{
"filter": {
"geo_distance": {
"distance": "100km",
"pin.location": {
"lat": 40,
"lon": -70
}
}
},
"boost": 2.0
}],
"score_mode": "first"
}
}

On Thursday, December 20, 2012 4:17:34 PM UTC-5, Mike wrote:

I want to boost the score of records that are close to some geo position.
Elastic has filters for geo, but that just includes or excludes records.
Is there a way to manipulate the score using the distance? I know there
is a custom_score query where I could specify something like "script" : "_score

  • doc['my_numeric_field'].value". The question is, how would I use the
    distance in the calculation, and not the value of the numeric field?

--