Elasticsearch time decay functions increase the ranking weight of newer content without sacrificing keyword relevance, solving the classic problem of results that are either relevant but outdated or fresh but inaccurate. Core capabilities include function_score-based score blending, smooth gauss decay, and additive business scoring. Keywords: Elasticsearch, time decay, search ranking.
Technical specification snapshot
| Parameter | Details |
|---|---|
| Core topic | Elasticsearch time decay ranking |
| Language | Query DSL / JSON |
| Protocol | REST API |
| Star count | Not provided in the original article |
| Core dependencies | Elasticsearch, BM25, function_score |
| Key functions | gauss, exp, linear |
| Typical fields | publish_time, create_time, post_time |
Time decay is a critical compensation mechanism in search ranking
In news, product, post, and short-video search, users usually want results that are both relevant and as fresh as possible. Sorting only by _score allows older content to dominate for too long, while sorting only by reverse chronological order damages semantic relevance.
The value of a time decay function is that it converts freshness into a continuous score and lets that score participate in ranking together with BM25 relevance. This way, new documents do not jump the queue aggressively, and older documents do not lose exposure abruptly.
The scoring model for time decay can be summarized as multiplicative blending
GET /article/_search
{
"query": {
"function_score": {
"query": {
"match": {
"title": "Elasticsearch"
}
},
"functions": [
{
"gauss": {
"publish_time": {
"origin": "now",
"scale": "7d",
"offset": "1d",
"decay": 0.5
}
}
}
],
"boost_mode": "multiply"
}
}
}
This query first performs keyword matching, then applies Gaussian decay based on the publish time, and finally multiplies the two scores to produce the final ranking score.
Elasticsearch provides three decay functions, and gauss fits time-based scenarios best
Elasticsearch supports three decay functions: gauss, exp, and linear. Each one lowers the score based on how far a field value is from the origin point, but the decay curve differs.
| Function | Curve characteristics | Best-fit scenario |
|---|---|---|
| gauss | Smooth and natural | Preferred for time decay |
| exp | Drops faster | When rapid demotion is required |
| linear | Linear decline | Simple rule-based ranking |
For content retrieval, gauss is the most common choice. It avoids sharp ranking jumps and better matches how users perceive content as gradually becoming stale.
Four parameters define the business shape of the decay curve
origin: The center point. In time-based scenarios, this is usuallynow.offset: The protection window. No decay applies within this time range.scale: The decay scale, which determines how quickly the score drops.decay: The score multiplier at the specified scale.
{
"gauss": {
"publish_time": {
"origin": "now",
"offset": "1d",
"scale": "7d",
"decay": 0.5
}
}
}
This parameter set means the content keeps a full score within 1 day, starts decaying after the protection window, and drops to roughly 0.5 around day 8.
Parameter tuning must reflect the real content lifecycle of the business
If you run a news feed, trending content has a very short lifecycle, so you should use a smaller scale. If you run e-commerce search, product lifecycles are longer, so you should increase both offset and scale. More aggressive parameters are not always better. They must match how users actually consume the content.
A common rule of thumb is this: news is measured in hours and days, products in weeks, job postings in weeks to months, and community posts usually require joint modeling of engagement and time.
Three high-frequency business templates can be used directly
{
"gauss": {
"publish_time": {
"origin": "now",
"offset": "1d",
"scale": "7d",
"decay": 0.5
}
}
}
This template works well for news or article search, where the goal is to protect fresh content within the first 24 hours.
{
"gauss": {
"create_time": {
"origin": "now",
"offset": "7d",
"scale": "30d",
"decay": 0.4
}
}
}
This template fits e-commerce new-product ranking, using a longer protection window to emphasize the launch period.
{
"gauss": {
"post_time": {
"origin": "now",
"offset": "6h",
"scale": "2d",
"decay": 0.3
}
}
}
This template is suitable for short-video or community-post ranking, where content popularity changes quickly.
Production systems usually combine time decay with popularity scoring
Time decay alone is not enough. Most enterprise search systems combine text relevance, publish time, sales, click-through rate, favorites, and other signals into a multi-factor ranking model.
A recommended pattern is to let the query layer handle recall, use function_score to blend ranking signals, and control score combination through boost_mode and score_mode.
Here is a practical multi-factor ranking template you can deploy directly
GET /shop/_search
{
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "手机",
"fields": ["title^3", "desc^1"],
"type": "best_fields",
"tie_breaker": 0.3
}
},
"functions": [
{
"gauss": {
"publish_time": {
"origin": "now",
"offset": "1d",
"scale": "7d",
"decay": 0.5
}
}
},
{
"field_value_factor": {
"field": "sales",
"modifier": "log1p"
}
}
],
"boost_mode": "multiply",
"score_mode": "sum"
}
}
}
This template implements joint ranking across keyword matching, freshness, and sales signals. It fits most product search and content retrieval systems.
The main advantage of time decay is a natural and stable ranking experience
Its first advantage is that it does not damage semantic relevance during recall. Its second advantage is that it avoids cliff-like ranking shifts where a result is first place yesterday and buried today. Its third advantage is that the parameters are intuitive, which makes gradual rollout and tuning easier.
That said, time decay is not a universal ranking strategy. In strongly time-sensitive scenarios, it should be combined with click feedback. For long-tail knowledge content, you should avoid suppressing high-quality older documents too aggressively.

AI Visual Insight: The image is an illustrative visual for the time decay topic. Its core purpose is to highlight the ranking trend in which newer content receives higher scores while older content is smoothly demoted over time. Although the chart does not show explicit axis details, it clearly supports the concept of a decay curve or score change over time and helps explain the technical characteristic of gradual score reduction rather than abrupt ranking shifts.
Best practices should focus on explainability and debuggability
Use gauss first, then consider exp and linear only if needed. Use offset to protect cold-start content, scale to define the business half-life of freshness, and decay to control the demotion strength.
Before going live, validate three things with sampled results: whether new content receives a reasonable boost, whether high-quality older content still remains visible, and whether the final ranking matches human evaluation expectations. Only rankings that are explainable and verifiable are suitable for continuous iteration.
FAQ
1. Why not sort directly by publish time in descending order?
Sorting directly by time ignores text relevance, so the newest but irrelevant content may appear first. The goal of time decay is to make freshness a weighted factor rather than the only ranking criterion.
2. Why is gauss usually recommended for time decay?
Because the gauss curve is the smoothest, ranking changes feel more natural and result volatility is reduced. In most content search and recommendation scenarios, it provides a better user experience than exp and linear.
3. How should I choose boost_mode?
For time decay scenarios, prefer multiply. This makes the freshness score act as a multiplier on the relevance score, preserving the dominance of keyword matching while allowing freshness to influence ranking in a stable way.
Core summary: This article systematically reconstructs the core principles, parameter semantics, and production practices of Elasticsearch time decay functions. It focuses on how to use gauss decay in content retrieval, e-commerce recommendation, and community ranking, helping you balance keyword relevance, publish-time freshness, and business popularity with function_score.