Skip to content

ESQL: optimize date grouping with formatting #114772

@costin

Description

@costin

Description

It's common when dealing with date grouping/histograms to perform date truncation and formatting at the same time - for example, assume I want to group by month AND format the date to something else:
The natural way to do that is :

FROM mydata
| STATS my_sum = SUM(fieldtosum) BY month = DATE_FORMAT("yyyy-MM", @timestamp)

However a more efficient way to do this would be:

FROM mydata 
// group on date trunction first
| STATS my_sum = SUM(fieldtosum) BY month= DATE_TRUNC(1 month, @timestamp) 
// then perform the formatting
| EVAL group = DATE_FORMAT("yyyy-MM", month) 

That is, we'd like to first group on the date (using truncation) - potentially by applying filters and apply the formatting just on the results.

P.S. Since at the moment DATE_TRUNC is not optimized, there's not much difference between the two.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions