Skip to content

ESQL: Add decay functions #121526

@ioanatia

Description

@ioanatia
Contributor

We already support the following decay functions in painless for the script_score query:

double decayNumericLinear(double origin, double scale, double offset, double decay, double docValue)
double decayNumericExp(double origin, double scale, double offset, double decay, double docValue)
double decayNumericGauss(double origin, double scale, double offset, double decay, double docValue)

double decayGeoLinear(String originStr, String scaleStr, String offsetStr, double decay, GeoPoint docValue)
double decayGeoExp(String originStr, String scaleStr, String offsetStr, double decay, GeoPoint docValue)
double decayGeoGauss(String originStr, String scaleStr, String offsetStr, double decay, GeoPoint docValue)

double decayDateLinear(String originStr, String scaleStr, String offsetStr, double decay, JodaCompatibleZonedDateTime docValueDate)
double decayDateExp(String originStr, String scaleStr, String offsetStr, double decay, JodaCompatibleZonedDateTime docValueDate)
double decayDateGauss(String originStr, String scaleStr, String offsetStr, double decay, JodaCompatibleZonedDateTime docValueDate)

Decay functions are used to penalize scores based on recency (for date types) or distance (numeric and geo types) and this is a useful feature we want to add to ES|QL.

We do not want to add 9 different decay functions.

We will have 3 decay functions:

decay_linear(origin, scale, offset, decay, value)
decay_exp(origin, scale, offset, decay, value)
decay_gauss(origin, scale, offset, decay, value)

For parameters:

Origin: numeric, spatial, date types
Scale: numeric, spatial, date types
Offset: numeric, spatial, date types
Decay: numeric
Value: numeric, spatial, date types

The return type should be double.

In terms of priority - it would make sense to add support for linear and exponential first, with gauss decay being used less in practice.

As a note we could potentially have a single function:

decay(type, origin, scale, offset, decay, value)

where type can be "linear", "exp" or "gauss".

Activity

elasticsearchmachine

elasticsearchmachine commented on Feb 3, 2025

@elasticsearchmachine
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

added
priority:normalA label for assessing bug priority to be used by ES engineers
on Feb 6, 2025
elasticsearchmachine

elasticsearchmachine commented on Mar 19, 2025

@elasticsearchmachine
Collaborator

Pinging @elastic/kibana-esql (ES|QL-ui)

changed the title [-]ESQL: Add decay function[/-] [+]ESQL: Add decay functions[/+] on Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

:Search Relevance/SearchCatch all for Search Relevance>featureES|QL-uiImpacts ES|QL UITeam:Search RelevanceMeta label for the Search Relevance team in Elasticsearchpriority:normalA label for assessing bug priority to be used by ES engineers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @ioanatia@timgrein@elasticsearchmachine@ChrisHegarty

      Issue actions

        ESQL: Add decay functions · Issue #121526 · elastic/elasticsearch