Skip to content

How to set Aggregations for a NestedAggregation object #8719

@MikeAlhayek

Description

@MikeAlhayek

Elastic.Clients.Elasticsearch version: 8.19.6

Elasticsearch version: 8.18.4

.NET runtime version: .net9

Operating system version: Cloud Cluster

Description of the problem including expected versus actual behavior:
I need a way to construct the following query

{
  "size": 0,
  "aggs": {
    "nested_metadata": {
      "nested": {
        "path": "AdditionalMetadata"
      },
      "aggs": {
        "distinct_keys": {
          "terms": {
            "field": "AdditionalMetadata.key.keyword",
            "size": 1000
          }
        }
      }
    }
  }
}

I don't see a way to set the aggs with in the nested object. Here is what I have

var searchRequest = new SearchRequest
{
    Size = 0,
    Aggregations = new Dictionary<string, Aggregation>
    {
        {
            "nested_metadata", new NestedAggregation()
            {
                Path = "AdditionalMetadata",
            }
        }
    },
};

I am expecting the NestedAggregation to have a Aggregations property of type IDictionary<string, Aggregation>? but I can't find it. I tried to look for anther class that could be inherited from NestedAggregation but can't find any.

@flobernd what is the trick to set the nested aggregation using the library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions