# How to give more importance to recent dates within a certain range?

**URL:** <https://discuss.elastic.co/t/how-to-give-more-importance-to-recent-dates-within-a-certain-range/226347>\
**Category:** Elasticsearch\
**Created:** [April 3, 2020, 7:02am UTC](https://discuss.elastic.co/t/how-to-give-more-importance-to-recent-dates-within-a-certain-range/226347 "2020-04-03T07:02:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhijith\_chandran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhijith_chandran/32/60470_2.png) [@abhijith\_chandran](https://discuss.elastic.co/u/abhijith_chandran)\
**Post date:** [April 3, 2020, 7:02am UTC](https://discuss.elastic.co/t/how-to-give-more-importance-to-recent-dates-within-a-certain-range/226347/1 "2020-04-03T07:02:37Z")

</div>

Hi,  
I wanted to know whether it is possible to sort queries by most relevant within a specified range.  
For example, lets take three scores that have been returned by a query.  
Doc 1 = 85.1 - Date = 2 March 2020  
Doc 2 = 84.2 - Date = 9 March 2020  
Doc 3 = 83.8 - Date = 1 March 2020

In this case, all the three are within a range of +1 to -1 of each other. Normally this will get returned in the order Doc 1, Doc 2, Doc 3. I want it to return as Doc 2, Doc 1, Doc 3.  
How do I do that?

I know we can sort by date, but I want it only for a certain range(in this case -1 to +1).  
Any help will be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [April 3, 2020, 7:29am UTC](https://discuss.elastic.co/t/how-to-give-more-importance-to-recent-dates-within-a-certain-range/226347/2 "2020-04-03T07:29:25Z")

</div>

Have you tried the distance feature query?

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-distance-feature-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-distance-feature-query.html)

---

<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:** [May 1, 2020, 7:29am UTC](https://discuss.elastic.co/t/how-to-give-more-importance-to-recent-dates-within-a-certain-range/226347/3 "2020-05-01T07:29:26Z")

</div>

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