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

Allow bucket paths to specify _count within a bucket #85720

Merged
merged 7 commits into from
Apr 29, 2022

Conversation

benwtrent
Copy link
Member

Users should be able to specify specific metrics/keys within a specific bucket key.

An example is agg["bucket_foo"]._count.

This change now allows that.

closes: #76320

@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Apr 6, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Hi @benwtrent, I've created a changelog YAML for you.

Copy link
Member

@not-napoleon not-napoleon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That path parser is a house of cards, and we should rewrite the whole thing to be more sensible, but that's out of scope for this I think.

assertInvalidPath("foo[]", "empty brackets in the token expression");
assertInvalidPath("foo[bar]baz", "brackets not enclosing at the end of the token expression");
assertInvalidPath(".foo", "dot separator at the beginning of the token expression");
assertInvalidPath("foo.", "dot separator at the end of the token expression");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave these reasons as comments then? It may not be immediately obvious why some of these are wrong.

int keyIndex = element.lastIndexOf('[');
int metricIndex = element.lastIndexOf('.');
if (keyIndex >= 0) {
if (keyIndex == 0 || keyIndex > element.length() - 3) {
throw new AggregationExecutionException("Invalid path element [" + element + "] in path [" + path + "]");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but AggregationExecutionException is the wrong thing to throw here. That's a 500 class error, but this is a user error that should not be retried, which is what 400 class is for. I opened #86273 to try to not lose track of it.

* <li>
* {@code agg1["foo"]._count} - where agg1 is multi-bucket, and the path expects a bucket "foo".
* This would extract the doc_count for that specific bucket.
* </li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples should probably also land in the user facing docs

@benwtrent
Copy link
Member Author

@not-napoleon

That path parser is a house of cards, and we should rewrite the whole thing to be more sensible, but that's out of scope for this I think.

I 100% agree. It is out of the scope of this particular PR. But, it strikes me that agg paths should reflect the aggregation DAG and be able to walk it. Seems like it would be good to refactor this into an N node tree that can be walked given Builders or Aggregators

@benwtrent benwtrent merged commit c49b92e into elastic:master Apr 29, 2022
@benwtrent benwtrent deleted the feature/agg-bucket-path-refactor branch April 29, 2022 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Aggregations Aggregations >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_count buckets_path syntax doesn't work with filters aggregation
4 participants