opensearch-java
opensearch-java copied to clipboard
Typed keys in aggregation results cannot be switched off
What is the bug?
The client always adds a type prefix to aggregation keys in responses which breaks compatibility with other clients or with frontend applications that directly work on aggregation responses.
This is a breaking change compared to other clients' behavior.
The Elasticsearch client API has a switch for turning off that behavior and thus returning compatible results. See Serializing aggregations and suggestions without typed keys
How can one reproduce the bug?
Each aggregation result contains aggregation names combined as [type]#[name]
What is the expected behavior?
There should be a compatibility setting that allows returning aggregation names without type prefix like the one provided by Elasticsearch.
What is your host/environment?
OpenSearch 2.11.0 OpenSearch Java Client 2.8.1 Java 17
Do you have any screenshots?
Do you have any additional context?
./.
This is an awkward feature. Are those typed keys added client or server side? Can you get two aggregations with the same name and different type? Either way giving the option make sense, want to try to implement it @fs-chris?
Long story is that I'd prefer a non-ambiguous response where the key is always the same, and that the body of the aggregation response contains either the separate name of the aggregation and the type, or vice-versa.
I suppose (without having looked into the code) that this is added by the client. The client prefixes the aggregation's name in the request which then occurs identically in the response, since the server does not touch the aggregation's name. So, this simply preserves the type information beyond the request/response round trip.
In the response it is then used for determining the target type before parsing the aggregation's result. I.e., the aggregation's key contains the target type that is used to decide how to parse the actual result body.