# Time weighting after ANN search

**URL:** <https://discuss.elastic.co/t/time-weighting-after-ann-search/306022>\
**Category:** Elasticsearch\
**Created:** [May 31, 2022, 9:43am UTC](https://discuss.elastic.co/t/time-weighting-after-ann-search/306022 "2022-05-31T09:43:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lz-mn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lz-mn/32/77605_2.png) [@lz-mn](https://discuss.elastic.co/u/lz-mn)\
**Post date:** [May 31, 2022, 9:43am UTC](https://discuss.elastic.co/t/time-weighting-after-ann-search/306022/1 "2022-05-31T09:43:50Z")

</div>

Hi, I'm trying to write a search query to:

- perform an ANN search on a dense vector field
- re-rank the returned documents to weight more recent documents higher, according to a custom exponential decay function applied to a 'date' field.

What is the best practice for doing this - using the query rescorer? Does Elasticsearch have built-in support for time weighting?

Thanks!

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [June 2, 2022, 6:17pm UTC](https://discuss.elastic.co/t/time-weighting-after-ann-search/306022/2 "2022-06-02T18:17:31Z")

</div>

At the moment `_knn_search` endpoint doesn't support rescorers. So you would need to that on your application side.

But we are working on combining \_search and \_knn\_search endpoints, which means there will be an option to use rescorer.

For time weighting, you can either use 1) `script_score` query with [decay functions on date fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-score-query.html#decay-functions-date-fields) or 2) `function_score` query's [decay functions](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-decay)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 30, 2022, 6:17pm UTC](https://discuss.elastic.co/t/time-weighting-after-ann-search/306022/3 "2022-06-30T18:17:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
