Skip to content

[FEATURE] Support earliest and latest in search command #4135

Closed

Description

@yuancu

Is your feature request related to a problem?

Currently, earliest and latest options are supported in conditions (doc) and aggregation functions (#4100), but not yet supported in search command. E.g. search source=emps earliest=-1d

What solution would you like?

Support earliest and latest parameter in search command

  • absolute time: search source=emps earliest=2020-12-10
  • relative time: search source=emps earliest=-30s
  • relative time aligned to weekday: search source=emps earliest=@w2 (Tuesday of the current week)
  • keyword: search source=emps earliest=2020-12-10 latest=now
  • keyword combined with modifier: search source=emps earliest=2020-12-10 latest=now-1d
  • implicit time with alignment: search source=emps latest=-1h@h (one hour in the past, aligned to hour)

What alternatives have you considered?

--

Do you have any additional context?

--

Activity

  1. added
    enhancement
    on Aug 27, 2025
  2. added
    PPL
    and removed on Aug 28, 2025
  3. yuancu commented on Sep 10, 2025

    @yuancu
    CollaboratorAuthor

    I encountered a design decision dilemma.

    With #4152 , we will push down all search options as query string queries.

    I found that OpenSearch already supports relative time in query string queries (and other queries like range query and match query). E.g. GET time_test/_search

    {
      "query": {
        "query_string": {
          "query": "timestamp:[* TO now-1d/d]"
        }
      }
    }

    Supported formats include (compared with our expectation in the description):

    • Absolute time: 2099-12-01T23:59:59.999999999Z
    • Relative time: now-30s, now+1h
    • Keyword: now
    • Keyword combined with modifier: (already exemplified)
    • Implicit time with alignment: now-1h/d (an hour in the past round down to day)

    What is not supported is week reference like @w0.

    Should we favor this format over the format stated in the description as this is a query language for OpenSearch? Or is it better to stick with the described representation like -1h@d. cc @penghuo @LantaoJin

    In this way, we can easily push down the time modifiers without defining a new grammar.

    As an alternative, it is also totally OK to convert the described time reference format to OpenSearch's reference format.

    Update: the latest implementation still uses the PPL grammar. The underlying implementation translates them to OpenSearch date math expressions.

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

Metadata

Metadata

Assignees

Labels

PPLenhancementv3.3.0

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions