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
Added getProperty method to Aggregations #8421
Conversation
} else if (aggName.equals("_key")) { | ||
return getKey(); | ||
} | ||
InternalAggregation aggregation = aggregations.get(aggName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if it makes sense to implement getProperty()
for Aggregations
as well and not just for Aggregation
. For example in a test I would write something like
Aggregations agg = searchResponse.getAggregations();
Object o =agg.get("aggname").getProperty("path");
but if Aggregations also implemented getProperty() I would save another line and it is needed anyway here internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea, and I can't think of a reason why it wouldn't work or not to do it. So I'll give it a go and add it to the PR.
Not sure if this is related to this pull requests, but when I name my aggregations with for example
|
@brwe I was talking to @clintongormley about this the other day. This will need to be fixed but outside of this PR as it also affects sort order for aggregations. For example, currently you cannot order a terms aggregation using the 99.9th percentile from the percentiles aggregation as you would need to specify your order as |
@@ -30,6 +30,8 @@ | |||
*/ | |||
String getName(); | |||
|
|||
Object getProperty(String path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some javadocs since it's a public API?
I like this new API as it is very convenient. I left a couple of comments/questions. I know it's outside of the scope of this PR but I'm wondering if we should make the path syntax compatible with some standard like json path for the next major release, in a way that it would be compatible with calling the same json path expression on the json response from elasticsearch. In addition to making it easier to approach to new users, it would also allow to address data that would be stored in a specific bucket, which is not supported today (although I could imagine sorting or reducers make use of it)? |
I like the idea of supporting JSON path expressions. From looking at the spec for JSON path, we are not that far away in what we do already, although we need to replace the '>' character with '.' in our current syntax. One thing we would need to sort out is what happens if the aggregation name contains a dot. This currently causes issues and we need to come up with a resolution order for resolving names and values with a dot, or remove support for agg names with a dot. |
Added a new issue for the JSONPath suggest here: #8434 |
@@ -392,6 +396,9 @@ public void singleValuedField_WithSubAggregation() throws Exception { | |||
assertThat(range, notNullValue()); | |||
assertThat(range.getName(), equalTo("range")); | |||
assertThat(range.getBuckets().size(), equalTo(3)); | |||
Object[] propertiesKeys = (Object[]) range.getProperty("_key"); | |||
Object[] propertiesDocCounts = (Object[]) range.getProperty("_count"); | |||
Object[] propertiesCounts = (Object[]) range.getProperty("sum"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be Object[] propertiesCounts = (Object[]) histo.getProperty("sum.value");
else the tests don't pass.
} else { | ||
String aggName = path.get(0); | ||
if (aggName.equals("_count")) { | ||
return getDocCount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that there are no more elements in the path before returning?
LGTM |
This allows arbitrary properties to be retrieved from an aggregation tree. The property is specified using the same syntax as the order parameter in the terms aggregation. If a property path contians a multi-bucket aggregation the property values from each bucket will be returned in an array.
This allows arbitrary properties to be retrieved from an aggregation tree. The property is specified using the same syntax as the
order parameter in the terms aggregation. If a property path contians a multi-bucket aggregation the property values from each bucket will be returned in an array.