Loading

ES|QL DECAY function

Embedded
value
The input value to apply decay scoring to.
origin
Central point from which the distances are calculated.
scale
Distance from the origin where the function returns the decay value.
options

Calculates a relevance score that decays based on the distance of a numeric, spatial or date type value from a target origin, using configurable decay functions.

DECAY calculates a score between 0 and 1 based on how far a field value is from a specified origin point (called distance). The distance can be a numeric distance, spatial distance or temporal distance depending on the specific data type.

DECAY can use function named parameters to specify additional options for the decay function.

For spatial queries, scale and offset for geo points use distance units (e.g., "10km", "5mi"), while cartesian points use numeric values. For date queries, scale and offset use time_duration values. For numeric queries you also use numeric values.

value origin scale options result
cartesian_point cartesian_point double named parameters double
date date time_duration named parameters double
date_nanos date_nanos time_duration named parameters double
double double double named parameters double
geo_point geo_point keyword named parameters double
geo_point geo_point text named parameters double
integer integer integer named parameters double
long long long named parameters double
offset
(double, integer, long, time_duration, keyword, text) Distance from the origin where no decay occurs.
type
(keyword) Decay function to use: linear, exponential or gaussian.
decay

(double) Multiplier value returned at the scale distance from the origin.

FROM employees
| EVAL decay_result = decay(salary, 0, 100000, {"offset": 5, "decay": 0.5, "type": "linear"})
| SORT decay_result DESC
		
decay_result:double
0.873405
0.8703
0.870145
0.867845
0.86395