Nested Aggregation Query with Java OpenSearchClient

Versions :
org.opensearch.client:opensearch-java:2.0.0
org.opensearch.client:opensearch-rest-client:1.3.6

Describe the issue:
I have one nested type and i have to aggregate by nested type’s field. SearchResponse class returns NestedAggregate and this class doesn’t hold TermsAggregate. And i don’t know how can i get buckets with these configuration.

Configuration:


final String agg = "agg";

final String subAgg = "subAggr";

org.opensearch.client.opensearch.OpenSearchClient client = ...

final org.opensearch.client.opensearch.core.SearchResponse<Void> searchResponse = client.search(b -> b
                            .index("index")
                            .aggregations(agg,
                                    x ->  x.nested(NestedAggregation.of(xy -> xy.path("nesteTypeObjectName")))
                                            .aggregations(subAgg,
                                                    Aggregation.of(
                                                            a -> a.terms(xz -> xz.field("fieldOfNestedTypeObject")
                                                                    .size(2000)))))
                    , Void.class);

final Map<String, org.opensearch.client.opensearch._types.aggregations.Aggregate> aggregations = searchResponse.aggregations();
final org.opensearch.client.opensearch._types.aggregations.NestedAggregate nestedAggregation = aggregations.get(agg);

// aggregations map holds just one aggr, doc_count returns correct but there is nothing another related with subAggregation.

Relevant Logs or Screenshots:

It works correctly from dashboard.
example request :

GET index/_search
{
  "aggs": {
    "agg": {
      "nested": {
        "path": "nestedObjectName"
      },
      "aggs": {
        "subAggr": {
          "terms": {
            "field": "fieldOfNestedTypeObject",
            "size": 1000
          }
        }
      }
    }
  }
}

And response

{
  "took" : 67,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 6558,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [...]
  },
"aggregations" : {
    "agg" : {
      "doc_count" : 1,
      "subAggr" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 1,
        "buckets" : [
          {
            "key" : "any data",
            "doc_count" : 1
          }
        ]
      }
    }
  }

Bucket aggregations | Java Transport Client (deprecated) [7.17] | Elastic - need something like that

[BUG] Nested/Sub Aggregations are not sending back buckets containing the data · Issue #197 · opensearch-project/opensearch-java · GitHub - fixed in here if someone needs.