﻿---
title: ES|QL DECAY function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/2988/reference/query-languages/esql/functions-operators/search-functions/decay
products:
  - Elasticsearch
---

# ES|QL DECAY function
<applies-to>
  - Elastic Cloud Serverless: Preview
  - Elastic Stack: Preview since 9.3
</applies-to>


## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/2988/reference/query-languages/esql/images/functions/decay.svg)


## Parameters

<definitions>
  <definition term="value">
    The input value to apply decay scoring to.
  </definition>
  <definition term="origin">
    Central point from which the distances are calculated.
  </definition>
  <definition term="scale">
    Distance from the origin where the function returns the decay value.
  </definition>
  <definition term="options">
    (Optional) Additional options such as `decay`, `offset` and `type`.
  </definition>
</definitions>


## Description

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](/elastic/docs-builder/docs/2988/reference/query-languages/esql/esql-syntax#esql-function-named-params) 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.

## Supported types


| 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 |


### Supported function named parameters

<definitions>
  <definition term="offset">
    (double, integer, long, time_duration, keyword, text) Distance from the origin where no decay occurs.
  </definition>
  <definition term="decay">
    (double) Multiplier value returned at the scale distance from the origin.
  </definition>
  <definition term="type">
    (keyword) Decay function to use: linear, exponential or gaussian.
  </definition>
</definitions>


## Example

```esql
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             |