# How to write this query using Composite aggregation using Terms with the new Elastic.Clients.Elasticsearch client in c#

**URL:** https://discuss.elastic.co/t/how-to-write-this-query-using-composite-aggregation-using-terms-with-the-new-elastic-clients-elasticsearch-client-in-c/354832
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [March 6, 2024, 10:46am UTC](https://discuss.elastic.co/t/how-to-write-this-query-using-composite-aggregation-using-terms-with-the-new-elastic-clients-elasticsearch-client-in-c/354832 "2024-03-06T10:46:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Patrice\_MARIN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrice_marin/32/132334_2.png) [@Patrice\_MARIN](https://discuss.elastic.co/u/Patrice_MARIN)
#### Post date: [March 6, 2024, 10:46am UTC](https://discuss.elastic.co/t/how-to-write-this-query-using-composite-aggregation-using-terms-with-the-new-elastic-clients-elasticsearch-client-in-c/354832/1 "2024-03-06T10:46:47Z")

</div>

Hi,  
Hope you will be able to help me on this.  
I have the following query

```auto
GET /catalog-20240302194411/_search
{
  "aggs": {
    "filtered_aggregations": {
      "aggs": {
        "paginated_unique_products": {
          "aggs": {
            "lowest_price": {
              "top_hits": {
                "size": 1,
                "sort": [
                  {
                    "price": {
                      "order": "asc"
                    }
                  }
                ]
              }
            }
          },
          "composite": {
            "size": 30,
            "sources": [
              {
                "product": {
                  "terms": {
                    "field": "productId"
                  }
                }
              }
            ]
          }
        },
        "accommodation_type_terms": {
          "terms": {
            "field": "accommodationTypes"
          }
        },
        "boards_terms": {
          "terms": {
            "field": "boards"
          }
        },
        "destination_terms": {
          "terms": {
            "field": "destinations"
          }
        },
        "establishment_rating_terms": {
          "terms": {
            "field": "establishmentRatings"
          }
        },
        "locations_terms": {
          "terms": {
            "field": "locations"
          }
        },
        "notorious_brand_terms": {
          "terms": {
            "field": "notoriousBrand"
          }
        },
        "payment_facilities_terms": {
          "terms": {
            "field": "paymentFacilities"
          }
        },
        "thematics_terms": {
          "terms": {
            "field": "thematics"
          }
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "destinations": [
                  6100004
                ]
              }
            },
            {
              "term": {
                "siteId": {
                  "value": 1
                }
              }
            }
          ]
        }
      }
    }
  },
  "size": 0
}

```

I'm able to write it using the NEST client but since we are using Elasticsearch v8, I'm using the latest (v8.12) **Elastic.Clients.Elasticsearch** and I'm not able to write in c# the composite aggregration bassed on terms.

I did not find any documentation or examples.  
Can you have a look a it please?

Thanks in advance.

Patrice

---

<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: [March 6, 2024, 11:08am UTC](https://discuss.elastic.co/t/how-to-write-this-query-using-composite-aggregation-using-terms-with-the-new-elastic-clients-elasticsearch-client-in-c/354832/2 "2024-03-06T11:08:49Z")

</div>

Hi @Patrice_MARIN, we currently have a long running open bug about this one. The `CompositeAggregationSource` is generated incorrectly (without properties) and does not provide the required functionality. I hope to be able to finally fix this in about a month when I release a new version of the client that is based on a completely reworked code generator.

---

<div class="post-metadata">

### Author: ![Patrice\_MARIN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrice_marin/32/132334_2.png) [@Patrice\_MARIN](https://discuss.elastic.co/u/Patrice_MARIN)
#### Post date: [March 6, 2024, 12:36pm UTC](https://discuss.elastic.co/t/how-to-write-this-query-using-composite-aggregation-using-terms-with-the-new-elastic-clients-elasticsearch-client-in-c/354832/3 "2024-03-06T12:36:32Z")

</div>

Hi @flobernd

Thanks for your quick reply.  
I hope you will be able to fix it in the new version. I will keep an eye on it.  
Thanks again.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 3, 2024, 12:36pm UTC](https://discuss.elastic.co/t/how-to-write-this-query-using-composite-aggregation-using-terms-with-the-new-elastic-clients-elasticsearch-client-in-c/354832/4 "2024-04-03T12:36:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
