# Function\_score, gaussian decay, handling multiple by zero

**URL:** <https://discuss.elastic.co/t/function-score-gaussian-decay-handling-multiple-by-zero/117086>\
**Category:** Elasticsearch\
**Created:** [January 25, 2018, 5:09pm UTC](https://discuss.elastic.co/t/function-score-gaussian-decay-handling-multiple-by-zero/117086 "2018-01-25T17:09:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Hunt](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@Chris\_Hunt](https://discuss.elastic.co/u/Chris_Hunt)\
**Post date:** [January 25, 2018, 5:09pm UTC](https://discuss.elastic.co/t/function-score-gaussian-decay-handling-multiple-by-zero/117086/1 "2018-01-25T17:09:48Z")

</div>

Hi

I have a function score using a gaussian decay. I would like the scores to never be zero after the multiplier so that when the gaussian function gets to zero, the documents still retained some relevance score.

Ideally, if we could add an arbitrary value to the gaussian value before the multiplication, this would solve my issue.

Does anyone have any consideration how to get this to work?

My interim (but not ideal) solution is to filter on the decay function to a certain radius to prevent multiply by zero and then add another function with a filter beyond that same radius and multiply by a very small value.

Thanks

Chris

---

<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:26pm UTC](https://discuss.elastic.co/t/function-score-gaussian-decay-handling-multiple-by-zero/117086/2 "2018-02-04T20:26:40Z")

</div>

`function_score` allows you to combine functions in any arbitrary way. For example, to avoid 0 scores, you can add an arbitrary value `0.001` to your gaussian values by using `weight` of `0.001` and `score_mode` of `sum`:

```
"function_score" : {
		"functions": [
			{
				"gauss": {
					"geo.coordinates": {
						"origin": { "lat": 14.18, "lon": -169.67 },
						"scale": "2km"
					}
				}
			},
			{
				"weight" : 0.001
			}
		],
		"score_mode" : "sum"
	}

```

Will this solve your problem?

---

<div class="post-metadata">

**Author:** ![Chris\_Hunt](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@Chris\_Hunt](https://discuss.elastic.co/u/Chris_Hunt)\
**Post date:** [February 10, 2018, 8:38am UTC](https://discuss.elastic.co/t/function-score-gaussian-decay-handling-multiple-by-zero/117086/3 "2018-02-10T08:38:42Z")

</div>

Hi.

Thank you for the reply and the suggestion. I think that's something I'll look at working with. I need to run some tests but I think that'll work. Thank you

Chris

---

<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 10, 2018, 8:38am UTC](https://discuss.elastic.co/t/function-score-gaussian-decay-handling-multiple-by-zero/117086/4 "2018-03-10T08:38:49Z")

</div>

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