Skip to content

[RFC] Support Implicit Time Modifiers and Time Functions in PPL #3969

Closed
2 of 2 issues completed
Closed

Description

@penghuo

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:

  1. Applying time range filters (earliest=-1d) without explicitly naming the @timestamp field
  2. Using time-based aggregations (span=5m) with implicit @timestamp field references
  3. 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 _time field 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=-1d

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

  1. All implicit time operations (earliest, latest, span without field, _time() function) will use @timestamp as the default field
  2. If the @timestamp field is not present in an index, any implicit time operation will throw an "@timestamp not found" exception
  3. 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 (span without a field) will throw a "@timestamp not found" exception
  • The _time function 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

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added
    PPL
    on Aug 1, 2025
  2. added
    enhancement
    and removed on Aug 1, 2025
  3. penghuo commented on Aug 1, 2025

    @penghuo
    CollaboratorAuthor

    Related Issue, #3883

  4. yuancu commented on Aug 21, 2025

    @yuancu
    Collaborator

    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, _time will be re-mapped to @timestamp. I wonder what if a user creates an index with _time field, possibly with incompatible types.

    Besides, should the implicit _time function be referred as _time() or _time or 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 _time is expected to be supported not only in functions, but also various commands? E.g. timechart

  5. toepkerd commented on Oct 3, 2025

    @toepkerd

    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.

  6. yuancu commented on Oct 29, 2025

    @yuancu
    Collaborator

    Close as all sub issues resolved.

  7. moved this from Not Started to Done in PPL Trackeron Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions