# Decrease score over time

**URL:** <https://discuss.elastic.co/t/decrease-score-over-time/154735>\
**Category:** Elasticsearch\
**Created:** [October 31, 2018, 12:22am UTC](https://discuss.elastic.co/t/decrease-score-over-time/154735 "2018-10-31T00:22:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandronu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pandronu/32/37126_2.png) [@pandronu](https://discuss.elastic.co/u/pandronu)\
**Post date:** [October 31, 2018, 12:22am UTC](https://discuss.elastic.co/t/decrease-score-over-time/154735/1 "2018-10-31T00:22:37Z")

</div>

Hi.

I've got a 'post' index, which has a 'createdAt' date field.

I'm trying to create a query that will return all posts, however, it should apply negative scoring for every day from now to the past.

So, if a post was created today, the scoring would be unaffected, but a post created for example 5 days ago, should have -5 penalty applied. So for every day it would have an extra -1 score applied.

I've tried to achieve this with "linear" decay function but it seems to cover only a very specific date range and I'm rather looking for something more open.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 31, 2018, 12:29am UTC](https://discuss.elastic.co/t/decrease-score-over-time/154735/2 "2018-10-31T00:29:24Z")

</div>

If you shared your existing query it might help someone to offer alternatives or improvements.

---

<div class="post-metadata">

**Author:** ![pandronu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pandronu/32/37126_2.png) [@pandronu](https://discuss.elastic.co/u/pandronu)\
**Post date:** [October 31, 2018, 6:52am UTC](https://discuss.elastic.co/t/decrease-score-over-time/154735/3 "2018-10-31T06:52:20Z")

</div>

Thanks

Here's the query I have so far:

```
GET /post/_doc/_search
{
  "explain": false,
  "query": {
    "function_score": {
      "score_mode": "sum",
      "functions": [
        {
            "field_value_factor": {
              "field": "totalVotes"
            },
            "weight": 0.1
        },
        {
            "field_value_factor": {
              "field": "score"
            },
            "weight": 0.05
        },
        {
            "field_value_factor": {
              "field": "totalComments"
            },
            "weight": 0.5
        },
        {
          "filter": {"match": { "hot": true }},
          "weight": 0
        },
        {
          "linear": {
            "createdAt": {
              "scale": "1h",
              "offset": 0,
              "decay": 0.1
            }
          },
          "weight": 100
        }
      ]
    }
  }
}    

```

Everything apart from the linear function seems to work fine. Just need to find a way to prioritize posts based on their number of days since they're added.

---

<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:** [November 28, 2018, 6:52am UTC](https://discuss.elastic.co/t/decrease-score-over-time/154735/4 "2018-11-28T06:52:21Z")

</div>

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