-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Meta data support with each aggregation request/response #8279
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
Conversation
} | ||
} | ||
return null; | ||
} |
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.
The second method looks unnecessary? I mean you could just cast the result from readOptionalGenericValue? (null pointers can be casted to any class)
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.
Thats good to know (not the case in C# :)), since this method is called in a bunch of places i did not want to introduce to many nullchecks and casts. Will change it to casts on readOptionalGenericValue()
Hey @Mpdreamz the change looks good. The comment on the PR seems to suggest that any json document can be used as metadata (eg. a number) but the Java API requires a hash, is it intended? |
Thanks for the review @jpountz ! No this is an oversight from copying it over from the previous PR that did allow any Json construct as meta, but now it has to be a hash (based on feedback on that PR). |
@jpountz incorporated your feedback in the PR. |
@@ -222,7 +222,8 @@ | |||
# Set a custom port to listen for HTTP traffic: | |||
# | |||
#http.port: 9200 | |||
|
|||
http.cors.enabled: true | |||
http.cors.allow-origin: http://localhost:8000 |
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.
Left-over? :)
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.
Argh! good catch, i'm an idiot :)
I tried to look at how likely it would be to forget adding support to custom metadata, and I like the fact that you made the metadata a compulsory constructor argument of the aggregators, and that the parsing logic is shared. I think my only concern is that it would be easy to forget to read the metadata in the InternalAggregation objects, so maybe we could try to refactor InternalAggregation so that you could never forget to serialize/deserialize the metadata? I'm thinking about something like: class InternalAggregation {
public final void writeTo(StreamOutput out) { // final so that sub-classes cannot extend
out.writeGenericValue(metaData);
doWriteTo(out);
}
protected abstract void doWriteTo(StreamOutput out); // this is the method sub-classes should extend instead
} (and similarly for |
++ I briefly discussed this with @spinscale but opted out for now to keep the PR simple, happy to refactor it! Should I also bump writing and reading the |
That would be great! |
import org.elasticsearch.test.ElasticsearchIntegrationTest; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
import sun.security.util.BigInt; |
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.
hmm?
I just left two minor comments, but other than that it looks good to me, so feel free to push without further reviews. Can you update the example request in the description of the PR to replace |
This commit adds the ability to associate a bit of state with each individual aggregation. The aggregation response can be hard to stitch back together without having a reference to the aggregation request. In many cases this is not available, many json serializer frameworks cache types globally or have a static deserialisation override mechanism. In these cases making the original request available, if at all possible, would be a hack. The old facets returned `_type` which was just enough metadata to know what the originating facet type in the request was. This PR takes `_type` one step further by introducing ANY arbitrary meta data. This could be further <strike>ab</strike>used for instance by generic/automated aggregations that include UI state (color information, thresholds, user input states, etc) per aggregation.
}, | ||
"meta": { | ||
"color": "blue" | ||
}, |
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.
this "," can be removed ;)
I'd be happy either way: the change has the appropriate version checks to be compatible with 1.x releases. I'm removing the tag until the change is backported (if we backport it). |
This commit adds the ability to associate a bit of state with each individual aggregation.
The aggregation response can be hard to stitch back together without having a reference to the aggregation request. In many cases this is not available, many json serializer frameworks cache types globally or have a static deserialisation override mechanism. In these cases making the original request available, if at all possible, would be a hack.
The old facets returned
_type
which was just enough metadata to know what the originating facet type in the request was.This PR takes
_type
one step further by introducing ANY arbitrary meta data. This could be furtherabused for instance by generic/automated aggregations that include UI state (color information, thresholds, user input states, etc) per aggregation.Here's a gist of a sense session you can use to review this branch
This PR supersedes #6465 which got stale and horribly out of date with all the new aggregations in
1.2-1.4
.Tested on a cluster of multiple nodes as well.
Example request:
Example response: