Hi,
I'm currently migrating my project to use the new client co.elastic.clients:elasticsearch-java:7.17.22. Previously, with org.elasticsearch:elasticsearch:7.8.1, I created nested aggregations in my JUnit tests like this:
TermsAggregationBuilder expectedTerms = new TermsAggregationBuilder("agg"); expectedTerms.field("data.Nested.NestedInner.NestedInnerField"); expectedTerms.size(1000); NestedAggregationBuilder expectedInnerNested = new NestedAggregationBuilder("nested", "data.Nested.NestedInner"); expectedInnerNested.subAggregation(expectedTerms); NestedAggregationBuilder expectedParentNested = new NestedAggregationBuilder("nested", "data.Nested"); expectedParentNested.subAggregation(expectedInnerNested); This would return a JSON structure like:
{ "nested": { "nested": { "path": "data.Nested" }, "aggregations": { "nested": { "nested": { "path": "data.Nested.NestedInner" }, "aggregations": { "agg": { "terms": { "field": "data.Nested.NestedInner.NestedInnerField", "size": 1000, "min_doc_count": 1, "shard_min_doc_count": 0, "show_term_doc_count_error": false, "order": [ { "_count": "desc" }, { "_key": "asc" } ] } } } } } } } Now, with the new client, I tried to create the same nested aggregation using:
String jsonString = "{\"nested\":{\"nested\":{\"path\":\"data.Nested\"},\"aggregations\":{\"nested\":{\"nested\":{\"path\":\"data.Nested.NestedInner\"},\"aggregations\":{\"agg\":{\"terms\":{\"field\":\"data.Nested.NestedInner.NestedInnerField\",\"size\":1000,\"min_doc_count\":1,\"shard_min_doc_count\":0,\"show_term_doc_count_error\":false,\"order\":[{\"_count\":\"desc\"},{\"_key\":\"asc\"}]}}}}}}}"; return new NestedAggregation.Builder() .withJson(stringReader) .build(); or
new Aggregation .Builder() .withJson(stringReader) .build(); However, I received the following error:
co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch._types.aggregations.NestedAggregation: Unknown field 'nested' (JSON path: nested) (line no=1, column no=10, offset=9) or
Caused by: co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch._types.aggregations.NestedAggregation: Unknown field 'nested' (JSON path: nested.nested) (line no=1, column no=20, offset=19) at co.elastic.clients.json.ObjectDeserializer.parseUnknownField Can anyone help me understand what I'm doing wrong? How can I properly create a NestedAggregation with sub-aggregations using the new client?
Thanks!