Repository navigation
Description
Introduction
This RFC proposes the introduction of implicit time modifiers and functions in PPL to improve user experience when working with time-based queries. Currently, users must explicitly specify timestamp fields in queries involving time operations, which leads to repetitive code and reduced readability.
The proposal addresses several key use cases:
- Applying time range filters (
earliest=-1d) without explicitly naming the @timestamp field - Using time-based aggregations (
span=5m) with implicit @timestamp field references - Leveraging time functions (
_time) that automatically use the @timestamp field
Background
Current Behavior
Currently in PPL, timestamp operations require explicit field specification:
search source=my-index @timestamp >= "2023-01-01" | stats count() by span(@timestamp, 1h)This approach:
- Requires repetitive field references
- Reduces query readability
- Makes time-based operations more verbose than necessary
Industry Context
Other query languages and analytics platforms often provide implicit timestamp handling:
- SPL has the
_timefield which serves as the default timestamp
Expected Query Behavior
The following query behaviors will be implemented:
Time Range Operations
When using time range shorthand like earliest and latest, the default timestamp field will be used:
-- Before: Explicit timestamp reference
search source=my-index @timestamp >= now() - 1d
-- After: Implicit use of default timestamp field
search source=my-index earliest=-1dTime-based Aggregations
When specifying span without an explicit field, the default timestamp field will be used:
-- Before: Explicit timestamp in span
search source=my-index | stats count() by span(@timestamp, 5m)
-- After: Implicit use of default timestamp field
search source=my-index | stats count() by span(5m)Time Functions
The _time() function will return the value of the default @timestamp field:
-- Before: No direct equivalent, would require explicit field access
search source=my-index | eval hour_of_day=hour(@timestamp)
-- After: Using _time function with default timestamp
search source=my-index | eval hour_of_day=hour(_time)Implementation Approach
The system will implement the following approach:
- All implicit time operations (
earliest,latest,spanwithout field,_time()function) will use@timestampas the default field - If the
@timestampfield is not present in an index, any implicit time operation will throw an "@timestamp not found" exception - For backward compatibility, existing queries with explicit timestamp references will continue to work without modification
Frequently Asked Questions
Q1: My index has a date field, but it's named "time" instead of "@timestamp". How do I query it with PPL?
Option 1: You can add a field alias in your index mapping that points "time" field to "@timestamp":
PUT my-index/_mapping
{
"properties": {
"@timestamp": {
"type": "alias",
"path": "time"
}
}
}After adding this alias, all queries using the default timestamp field (or explicitly referencing @timestamp) will work as expected.
Option 2: You can continue using explicit field references in your queries:
search source=my-index time>="2023-07-31 00:00:00" | stats count() by span(time, 5m)Q2: My index doesn't have any date field. How do I query it with PPL?
For indices without a timestamp field, time-based operations will behave as follows:
- Time range operations (
earliest,latest) will throw a "@timestamp not found" exception - Time-based aggregations (
spanwithout a field) will throw a "@timestamp not found" exception - The
_timefunction will return null or throw a "@timestamp not found" exception
For such indices, you should avoid using timestamp-dependent features or explicitly provide field references where applicable.
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
penghuo commentedon Aug 1, 2025
Related Issue, #3883
yuancu commentedon Aug 21, 2025
Hi @penghuo , regarding time range operations, is earliest parameter already supported in source command? e.g.
search source=my-index earliest='2025-08-21'I did not find its implementation as a parameter. If it is not yet supported, shall we implement it in another pull request? (or is there already someone implementing this?)
For time functions with
_time, according to my understanding,_timewill be re-mapped to@timestamp. I wonder what if a user creates an index with_timefield, possibly with incompatible types.Besides, should the implicit
_timefunction be referred as_time()or_timeor both? You mentioned_time()multiple times, but in the example, it's referred to as_time:search source=my-index | eval hour_of_day=hour(_time).Moreover, I think the reference to
_timeis expected to be supported not only in functions, but also various commands? E.g.timechart@timestampfield access in span #4136toepkerd commentedon Oct 3, 2025
In the future, let's support these time-based key words in such a way that the presence of the @timestamp field in the queried indices does not need to be assumed as a precondition in order for the PPL query to run successfully. Perhaps we can add a PPL function that specifies what the timestamp field is, or, more fundamentally/long term, have some kind of a default "document index time" field in all OpenSearch indices/docs.
yuancu commentedon Oct 29, 2025
Close as all sub issues resolved.