# 0.90.4 recency example for Function Score Query

**URL:** <https://discuss.elastic.co/t/0-90-4-recency-example-for-function-score-query/14605>\
**Category:** Elasticsearch\
**Created:** [November 26, 2013, 8:53pm UTC](https://discuss.elastic.co/t/0-90-4-recency-example-for-function-score-query/14605 "2013-11-26T20:53:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevins/32/946_2.png) [@kevins](https://discuss.elastic.co/u/kevins)\
**Post date:** [November 26, 2013, 8:53pm UTC](https://discuss.elastic.co/t/0-90-4-recency-example-for-function-score-query/14605/1 "2013-11-26T20:53:22Z")

</div>

I would like to apply recency to a simple match query.

I was heading in the direction of using \_timestamp in a script such as  
this: "script": "\_score + log(doc['\_timestamp'].value)/100"

However, after reading this post regarding 90.4 function\_score\_query I am  
confused. The document mentions recency and then goes on to use a geo  
distance example. Does an example of applying recency exist?

In my use case recent docs would have some minor influence and docs older  
than say a year would have 0.

Thank you.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 27, 2013, 11:03am UTC](https://discuss.elastic.co/t/0-90-4-recency-example-for-function-score-query/14605/2 "2013-11-27T11:03:30Z")

</div>

Hi Kevin,

There are examples on the function\_score documentation page about dates and  
prices that should help:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Don't hesitate to let me know if it doesn't!

On Tue, Nov 26, 2013 at 9:53 PM, Kevin S [kevinsteger@gmail.com](mailto:kevinsteger@gmail.com) wrote:

> I would like to apply recency to a simple match query.
> 
> I was heading in the direction of using \_timestamp in a script such as  
> this: "script": "\_score + log(doc['\_timestamp'].value)/100"
> 
> However, after reading this post regarding 90.4 function\_score\_query I am  
> confused. The document mentions recency and then goes on to use a geo  
> distance example. Does an example of applying recency exist?
> 
> In my use case recent docs would have some minor influence and docs older  
> than say a year would have 0.
> 
> Thank you.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4ucbv7%3Dv%3Dqt-XYmexNrEipdQrfnwbKpv6zM9EZyVNGKg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4ucbv7%3Dv%3Dqt-XYmexNrEipdQrfnwbKpv6zM9EZyVNGKg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![kevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevins/32/946_2.png) [@kevins](https://discuss.elastic.co/u/kevins)\
**Post date:** [November 29, 2013, 4:39am UTC](https://discuss.elastic.co/t/0-90-4-recency-example-for-function-score-query/14605/3 "2013-11-29T04:39:11Z")

</div>

That is the page I intended to link to in my original post.

It is still not clear how to use \_timestamp in the calculations.

What I would love to see in an example that would contrast: Heavy weight  
on \_score, light on recency. vs Heavy on recency, light on \_score.

This functionality was very easy to do on the platform I am moving from  
where an "age" variable was available allowing calculations such as: (-age

- relevance^2) or (-age^2 + relevance). I'm trying to duplicate that.

Thanks.

On Wednesday, November 27, 2013 3:03:30 AM UTC-8, Adrien Grand wrote:

> Hi Kevin,
> 
> There are examples on the function\_score documentation page about dates  
> and prices that should help:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
> 
> Don't hesitate to let me know if it doesn't!
> 
> On Tue, Nov 26, 2013 at 9:53 PM, Kevin S \<[kevin...@gmail.com](mailto:kevin...@gmail.com) \<javascript:\>
> 
> > wrote:
> 
> > I would like to apply recency to a simple match query.
> > 
> > I was heading in the direction of using \_timestamp in a script such as  
> > this: "script": "\_score + log(doc['\_timestamp'].value)/100"
> > 
> > However, after reading this post regarding 90.4 function\_score\_query I am  
> > confused. The document mentions recency and then goes on to use a geo  
> > distance example. Does an example of applying recency exist?
> > 
> > In my use case recent docs would have some minor influence and docs older  
> > than say a year would have 0.
> > 
> > Thank you.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d1ce1614-e980-4169-b4a7-548aa751f61b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1ce1614-e980-4169-b4a7-548aa751f61b%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Britta\_Weber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/britta_weber/32/1113_2.png) [@Britta\_Weber](https://discuss.elastic.co/u/Britta_Weber)\
**Post date:** [November 29, 2013, 11:07pm UTC](https://discuss.elastic.co/t/0-90-4-recency-example-for-function-score-query/14605/4 "2013-11-29T23:07:50Z")

</div>

Hi Kevin,

if you need arbitrarily complex functions, I think the script score as  
you described is most useful. But you have to compute distance and  
decay yourself in the script.  
The decay functions are separate from the script scoring and can only  
be combined with other functions as described in the documentation  
(sum, avg,...). The only weighting can be achieved in a sum by using a  
"bool" query with "disable\_coord": true.  
I hope that helps.

Cheers,  
Britta

On Fri, Nov 29, 2013 at 5:39 AM, Kevin S [kevinsteger@gmail.com](mailto:kevinsteger@gmail.com) wrote:

> That is the page I intended to link to in my original post.
> 
> It is still not clear how to use \_timestamp in the calculations.
> 
> What I would love to see in an example that would contrast: Heavy weight on  
> \_score, light on recency. vs Heavy on recency, light on \_score.
> 
> This functionality was very easy to do on the platform I am moving from  
> where an "age" variable was available allowing calculations such as: (-age +  
> relevance^2) or (-age^2 + relevance). I'm trying to duplicate that.
> 
> Thanks.
> 
> On Wednesday, November 27, 2013 3:03:30 AM UTC-8, Adrien Grand wrote:
> 
> > Hi Kevin,
> > 
> > There are examples on the function\_score documentation page about dates  
> > and prices that should help:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
> > 
> > Don't hesitate to let me know if it doesn't!
> > 
> > On Tue, Nov 26, 2013 at 9:53 PM, Kevin S [kevin...@gmail.com](mailto:kevin...@gmail.com) wrote:
> > 
> > > I would like to apply recency to a simple match query.
> > > 
> > > I was heading in the direction of using \_timestamp in a script such as  
> > > this: "script": "\_score + log(doc['\_timestamp'].value)/100"
> > > 
> > > However, after reading this post regarding 90.4 function\_score\_query I am  
> > > confused. The document mentions recency and then goes on to use a geo  
> > > distance example. Does an example of applying recency exist?
> > > 
> > > In my use case recent docs would have some minor influence and docs older  
> > > than say a year would have 0.
> > > 
> > > Thank you.
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/01593ddc-94bb-4fa0-8d56-aa3014a9f8b3%40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > Adrien Grand
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d1ce1614-e980-4169-b4a7-548aa751f61b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1ce1614-e980-4169-b4a7-548aa751f61b%40googlegroups.com).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALhJbBhpvJHjCy0GyjjiBCfEYHx7DqCEu3q9nU0\_ShAzUXAj5Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALhJbBhpvJHjCy0GyjjiBCfEYHx7DqCEu3q9nU0_ShAzUXAj5Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:04am UTC](https://discuss.elastic.co/t/0-90-4-recency-example-for-function-score-query/14605/5 "2017-07-06T02:04:08Z")

</div>


