# Migrating from Elastic NEST v7 to .NET Elastic Client v9: Aggregation with Nested clause

**URL:** <https://discuss.elastic.co/t/migrating-from-elastic-nest-v7-to-net-elastic-client-v9-aggregation-with-nested-clause/383958>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 10, 2025, 2:22pm UTC](https://discuss.elastic.co/t/migrating-from-elastic-nest-v7-to-net-elastic-client-v9-aggregation-with-nested-clause/383958 "2025-12-10T14:22:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vadym\_Romanenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadym_romanenko/32/78657_2.png) [@Vadym\_Romanenko](https://discuss.elastic.co/u/Vadym_Romanenko)\
**Post date:** [December 10, 2025, 2:22pm UTC](https://discuss.elastic.co/t/migrating-from-elastic-nest-v7-to-net-elastic-client-v9-aggregation-with-nested-clause/383958/1 "2025-12-10T14:22:37Z")

</div>

I’m moving code from the NEST client to the Elasticsearch client v9.2. I’m trying to generate aggregation that contains a nested filter. Here is sample of the old code with NEST:  
`AggregationContainerDescriptor<T> ret; `  
`BoolQueryDescriptor<T> productFilter = new BoolQueryDescriptor<T>();`  
`AggregationContainerDescriptor<T> SKUAggregation = new AggregationContainerDescriptor<T>();`  
`…`  
`ret = ret`  
` .Filter(FILTER_NAME, f => f`  
` .Filter(sf => sf`  
` .Bool(sfb => productFilter)`  
` )`  
` .Aggregations(fa => fa`  
` .Nested(SKU_NAME, fan => fan`  
` .Path(SKUS_NAME)`  
` .Aggregations(skua => SKUAggregation)`  
` )`  
` )`  
`);`

In other words, I need to apply a filter on the main document and then apply an additional filter on a nested document property.

> Document sample:  
> {  
> “product\_name”: “apple”,  
> “skus”: [  
> {  
> “color”: “green”  
> “price”: 11.99  
> }  
> {  
> “color”: “red”  
> “price”: 8.45  
> }  
> {  
> “color”: “yellow”  
> “price”: 9.99  
> }  
> ]  
> }

I’ve asked several AIs how this code could be transformed, and they usually return examples similar to the following:

```auto
var ret = new Dictionary<string, Aggregation>
{
  {
    FILTER_NAME,
    new FilterAggregation
    {
        // Apply the PRODUCT LEVEL FILTER
        Filter = productFilter,

        // Define the NESTED Aggregation hierarchy
        Aggregations = new Dictionary<string, Aggregation>
        {
            {
                SKU_NAME,
                new NestedAggregation
                {
                    Path = SKUS_NAME,
                    // Nest the previously built SKU aggregations
                    Aggregations = SKUAggregation 
                }
            }
        }
    }
}

```

However, the problem is that `NestedAggregation` does **not** have an `Aggregations` property in Elasticsearch 9.2.

So if anyone knows how to properly build this using the new client, I would be really thankful.

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [December 10, 2025, 3:15pm UTC](https://discuss.elastic.co/t/migrating-from-elastic-nest-v7-to-net-elastic-client-v9-aggregation-with-nested-clause/383958/2 "2025-12-10T15:15:08Z")

</div>

Hi @Vadym_Romanenko ,

the usage of sub aggregations is documented here:

[https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/aggregations#\_object\_initializer\_api\_2](https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/aggregations#_object_initializer_api_2)

Basically, change this part a little bit:

```auto
new Aggregation
{
    Nested = new NestedAggregation
    {
        Path = SKUS_NAME
    },
    // Nest the previously built SKU aggregations
    Aggregations = SKUAggregation 
}

```

---

<div class="post-metadata">

**Author:** ![Vadym\_Romanenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadym_romanenko/32/78657_2.png) [@Vadym\_Romanenko](https://discuss.elastic.co/u/Vadym_Romanenko)\
**Post date:** [December 10, 2025, 3:22pm UTC](https://discuss.elastic.co/t/migrating-from-elastic-nest-v7-to-net-elastic-client-v9-aggregation-with-nested-clause/383958/3 "2025-12-10T15:22:45Z")

</div>

Thank you, Florain! That helped.
