ES|QL DECAY function
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Preview
Preview
Stack
Preview
9.3+
Preview since 9.3
Calculates a relevance score that decays with distance from a target origin.
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-
(Optional) Additional options such as
decay,offsetandtype.
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.
Learn more about using ES|QL for search use cases.
| 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 |
| unsigned_long | unsigned_long | unsigned_long | named parameters | double |
offset- (double, integer, long, unsigned_long, time_duration, keyword, text) Distance from the origin where no decay occurs.
decay- (double) Multiplier value returned at the scale distance from the origin.
type-
(keyword) Decay function to use: linear, exponential or gaussian.
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 |