Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES|QL: Named parameters #107029

Open
dgieselaar opened this issue Apr 3, 2024 · 3 comments · May be fixed by #108421
Open

ES|QL: Named parameters #107029

dgieselaar opened this issue Apr 3, 2024 · 3 comments · May be fixed by #108421
Assignees
Labels
:Analytics/ES|QL AKA ESQL >enhancement ES|QL-ui Impacts ES|QL UI Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@dgieselaar
Copy link
Member

Description

Currently, ES|QL supports positional parameters, which allows the query author to inject variables into the query. This is useful for dashboards, where there are often global parameters, like a time range filter, or a KQL string. However, there's no way to use positional parameters for this, as the dashboard doesn't know with what intent the queries were written.

Named parameters can solve this:

FROM traces-apm*
	| WHERE @timestamp >= ${earliest} AND @timestamp < ${latest}
	| EVAL date_bucket = DATE_TRUNC(${bucketSize}, @timestamp)
	| STATS AVG(transaction.duration.us) BY ${groupingField}

One issue here is that in some cases the variable might be null. Consider groupingField being optional. If it were empty, it would lead to a syntactically invalid query:

FROM traces-apm*
	| WHERE @timestamp >= NOW()-24 hours AND @timestamp < NOW()
	| EVAL date_bucket = DATE_TRUNC(1 hour, @timestamp)
	| STATS AVG(transaction.duration.us) BY

Possibly we can solve this by allowing some kind of syntax for conditional templating:

FROM traces-apm*
	| WHERE @timestamp >= ${earliest} AND @timestamp < ${latest}
	| EVAL date_bucket = DATE_TRUNC(${bucketSize}, @timestamp)
	| STATS AVG(transaction.duration.us) ${groupingField ? "BY " + groupingField : ""}
@dgieselaar dgieselaar added >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) needs:triage Requires assignment of a team area label :Analytics/ES|QL AKA ESQL labels Apr 3, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Apr 3, 2024
@stratoula
Copy link

This is important for kibana. Right now we have the following limitation:

  • timepicker works only if the index has @timestamp field
  • if there is no @timestamp field then the user gets all the data (both in dashboards and Discover)
  • the user might want to use a different time field with the time picker
  • the timepicker working only with the @timestamp field creates confusion to the users (Why the timepicker is disabled in Discover? I am using the timepicker in a dashboard but my charts are not filtered etc)

@ChrisHegarty
Copy link
Contributor

Seems related to this (currently draft) PR #104618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >enhancement ES|QL-ui Impacts ES|QL UI Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants