# Preventing a Gauss decay function from returning 0 inside a function score query

**URL:** <https://discuss.elastic.co/t/preventing-a-gauss-decay-function-from-returning-0-inside-a-function-score-query/117462>\
**Category:** Elasticsearch\
**Created:** [January 29, 2018, 1:13pm UTC](https://discuss.elastic.co/t/preventing-a-gauss-decay-function-from-returning-0-inside-a-function-score-query/117462 "2018-01-29T13:13:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortenxd](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mortenxd](https://discuss.elastic.co/u/mortenxd)\
**Post date:** [January 29, 2018, 1:13pm UTC](https://discuss.elastic.co/t/preventing-a-gauss-decay-function-from-returning-0-inside-a-function-score-query/117462/1 "2018-01-29T13:13:18Z")

</div>

Hello,

I'm using a Gauss decay function to decrease relevance of old documents in my index (origin is current time). Is there a way to prevent a Gauss decay function from returning 0 for very old documents in this case?

I am using a function score query with both score mode and boost mode 'multiply'. For very old documents in my index, the score is always 0 because of multiplication with 0 from the Gauss Decay function (since current time is the origin and the date field of the document is so long ago). Is there a way to prevent this?

I could use boost\_mode 'avg' instead of the default 'multiply', but my function score query is quite big and other functions in it make a lot more sense with multiplication. Is there a way to specify boost\_mode for only one function inside a function score query?

I would not mind the Gauss decay returning something exceptionally small as long as it is not 0. Currently there is no way to distinguish between the relevance of a 3 year old document and a 5 year old document since they are both multiplied by 0 and thus end up with a score of 0. I could also mention that the function parameters (offset, scale etc.) are all customizable by an administrator other than me as a developer. Thus it would be nice to have a system in which the administrator could not "break" the query (as in specifying a minimum score that the Gauss function can return regardless of its parameters somehow).

Thanks for your time, I appreciate any feedback 🙂

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [February 4, 2018, 8:54pm UTC](https://discuss.elastic.co/t/preventing-a-gauss-decay-function-from-returning-0-inside-a-function-score-query/117462/2 "2018-02-04T20:54:00Z")

</div>

The best strategy for you is to adjust `scale` and `decay` values. For example, to distinguish between 3 year and 5 year old, increase your `scale` to something bigger, e.g : `"scale": "365d"`.

If it is not possible for you to adjust `scale` and `decay`, consider adding an arbitrary small value to your gaussian score, by introducing another function with `"score_mode" : "sum"`. Something like this: [Function\_score, gaussian decay, handling multiple by zero](https://discuss.elastic.co/t/function-score-gaussian-decay-handling-multiple-by-zero/117086/2?u=mayya)

---

<div class="post-metadata">

**Author:** ![mortenxd](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mortenxd](https://discuss.elastic.co/u/mortenxd)\
**Post date:** [February 5, 2018, 11:38am UTC](https://discuss.elastic.co/t/preventing-a-gauss-decay-function-from-returning-0-inside-a-function-score-query/117462/3 "2018-02-05T11:38:37Z")

</div>

Hi Mayya,

Thanks a lot for your response. I will definitely try your second suggested option, it sounds exactly like what I am looking for. Cheers.

---

<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:** [March 5, 2018, 11:38am UTC](https://discuss.elastic.co/t/preventing-a-gauss-decay-function-from-returning-0-inside-a-function-score-query/117462/4 "2018-03-05T11:38:39Z")

</div>

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