# Correlation/updation of document score on timestamp, during query time in kibana search

**URL:** https://discuss.elastic.co/t/correlation-updation-of-document-score-on-timestamp-during-query-time-in-kibana-search/88421
**Category:** Kibana
**Created:** [June 6, 2017, 1:01pm UTC](https://discuss.elastic.co/t/correlation-updation-of-document-score-on-timestamp-during-query-time-in-kibana-search/88421 "2017-06-06T13:01:32Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)
#### Post date: [June 8, 2017, 9:57am UTC](https://discuss.elastic.co/t/correlation-updation-of-document-score-on-timestamp-during-query-time-in-kibana-search/88421/5 "2017-06-08T09:57:03Z")

</div>

Hi @Rahul_Lao,

queries executed in the [filter context](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html) 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](https://www.elastic.co/guide/en/elasticsearch/guide/current/sorting-by-distance.html):

- Use the [`_geo_distance`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#geo-sorting) clause in the `sort` array to sort the result by distance. When using a `sort` clause, the score is not calculated [unless explicitly enabled](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_track_scores).
- Use a [`function_score`](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html) query to explicitly include the distance in the score as demonstrated in the [guide chapter on decay functions](https://www.elastic.co/guide/en/elasticsearch/guide/current/decay-functions.html) 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}
          }
        }
      }
    }
  }
}
```

---

_[View the full topic](https://discuss.elastic.co/t/correlation-updation-of-document-score-on-timestamp-during-query-time-in-kibana-search/88421)._
