Order by date field (descending): gauss or field_value_factor?

(Guilherme Maranhao) #1


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:

                              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 Maranhao) #2


I got the answer at 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!

(system) #3