# Order by date field (descending): gauss or field\_value\_factor?

**URL:** <https://discuss.elastic.co/t/order-by-date-field-descending-gauss-or-field-value-factor/62633>\
**Category:** Elasticsearch\
**Created:** [October 10, 2016, 1:18pm UTC](https://discuss.elastic.co/t/order-by-date-field-descending-gauss-or-field-value-factor/62633 "2016-10-10T13:18:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [October 10, 2016, 1:18pm UTC](https://discuss.elastic.co/t/order-by-date-field-descending-gauss-or-field-value-factor/62633/1 "2016-10-10T13:18:29Z")

</div>

Hi,

I have an issue concerning the modification of the score document according to its creation date. I have tried gauss function and field\_value\_factor.

The fist one is:

```
gauss:{
                              date_field: {
                                  origin: "now",
                                  scale: "1d",
                                  decay: 0.5
                              }
                          } 

```

With this configuration, I am telling elastic that the last documents must have a higher score. When I execute the query with it, the result is totally the opposite! The oldest documents are being returned firstly. Even if I change the origin to

```
origin: "2010-05-01 00:00:00"

```

which is the date of the first document, the oldest ones are also being retrieved firstly. What am I doing wrong?

With field\_value\_factor, the things are better, but not yet what I am waiting for....

```
field_value_factor: {
                                 field: "date_field",
                                 factor : 100,
                                  modifier: "sqrt"
                               }

```

With this other configuration, the documents from 2016 and 2015 are being returned firstly, however there are tons of documents from 2016 that receive less score than others from 2015, even if I set a modifier "sqrt" with factor: 100 !!!!

I suppose guass function would be the appropriate solution. How can I invert this gauss result? Or how can I increase the field\_value\_factor so that the 2016 comes before the 2015??

Thanks a lot,

Guilherme

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [October 11, 2016, 4:13pm UTC](https://discuss.elastic.co/t/order-by-date-field-descending-gauss-or-field-value-factor/62633/2 "2016-10-11T16:13:33Z")

</div>

Hi,

I got the answer at [http://stackoverflow.com/questions/39964256/elasticsearch-order-by-date-field-descending-gauss-or-field-value-factor](http://stackoverflow.com/questions/39964256/elasticsearch-order-by-date-field-descending-gauss-or-field-value-factor)

I had to increase the function weight and the scale parameter. It was also suggested to increase the decay so the least recent documents have lower relevance.

```
"functions": [{
            "gauss": {
                "date_field": {
                    "origin": "now"
                    "scale": "30d",
                    "decay": "0.8"
                }
            },
            "weight": 20
        }]

```

Thank you!

---

<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 5, 2017, 10:13pm UTC](https://discuss.elastic.co/t/order-by-date-field-descending-gauss-or-field-value-factor/62633/3 "2017-07-05T22:13:23Z")

</div>


