# DECAY

Calculates a relevance score that decreases based on the distance of a numeric, spatial, or date value from a target origin, using configurable decay functions. The score ranges from 0 to 1, depending on how far the field value is from the specified origin. The distance can be numeric, spatial, or temporal, depending on the data type. Additional options for the decay function can be specified using function named parameters. For spatial queries, scale and offset for geo points use distance units (such as "10km" or "5mi"), while cartesian points use numeric values. For date queries, scale and offset use time duration values. For numeric queries, numeric values are used.

## Syntax

`DECAY(value, origin, scale, options, offset, type, decay)`

### Parameters

#### value

The input value to apply decay scoring to.

#### origin

The central point from which distances are calculated.

#### scale

The distance from the origin where the function returns the decay value.

#### options

Function named parameters that allow you to specify additional options for the decay function.

#### offset

(Optional) The distance from the origin where no decay occurs. Can be a double, integer, long, time_duration, keyword, or text.

#### type

(Optional) The decay function to use. Supported values are: linear, exponential, or gaussian.

#### decay

(Optional) The multiplier value returned at the scale distance from the origin.

## Examples

Calculates a decay score for each employee's salary using a linear decay function, with 0 as the origin, 100,000 as the scale, an offset of 5, and a decay multiplier of 0.5, then sorts the results by the decay score in descending order.

```esql
FROM employees
| EVAL decay_result = decay(salary, 0, 100000, {"offset": 5, "decay": 0.5, "type": "linear"})
| SORT decay_result DESC
```

This example calculates a decay score for each employee's salary, using 0 as the origin, 100,000 as the scale, an offset of 5, a decay multiplier of 0.5, and the linear decay function, then sorts the results by the decay score in descending order.
