# decayDateGauss gives different results depending on the amount of hits

**URL:** <https://discuss.elastic.co/t/decaydategauss-gives-different-results-depending-on-the-amount-of-hits/339415>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 27, 2023, 9:56am UTC](https://discuss.elastic.co/t/decaydategauss-gives-different-results-depending-on-the-amount-of-hits/339415 "2023-07-27T09:56:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Massimo\_Redaelli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/massimo_redaelli/32/123964_2.png) [@Massimo\_Redaelli](https://discuss.elastic.co/u/Massimo_Redaelli)\
**Post date:** [July 27, 2023, 9:56am UTC](https://discuss.elastic.co/t/decaydategauss-gives-different-results-depending-on-the-amount-of-hits/339415/1 "2023-07-27T09:56:27Z")

</div>

I'm using a `script_score` query where the score script is this:

```plaintext
double decay = params.decays.getOrDefault(doc['spider'].value, 0.1);
def ts = doc['last_update'].size()!=0 ? doc['last_update'].value : doc['timestamp'].value;
def boost = params['boosts'].getOrDefault(doc['spider'].value, 1.0);
def decay = (decayDateGauss(params.now, "1200d", "90d", decay, ts)*(1-0.2)+0.2)
return _score * boost * decay;

```

Investigating why a document scored higher than another, I tried to limit the query to those two documents, and got very different scores.

To isolate what changed, I `return`ed all three parts of the score separately, once with all documents, once limiting to those two.

To my great surprise, `_score` and `boost` gave the same value for each document, regardless of the number of documents returned.  
But `decay` changed from .96 to .68, for one of the documents (lower when returning only the two results, and this is the correct result I would expect).

In each case (two docs/all the docs), calculating the product of the three components returned this way gives me the original, complete score.

So my question is: why does the output of `decayDateGauss` change?

---

<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:** [August 24, 2023, 9:56am UTC](https://discuss.elastic.co/t/decaydategauss-gives-different-results-depending-on-the-amount-of-hits/339415/2 "2023-08-24T09:56:47Z")

</div>

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