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

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

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

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.

1 Like

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.

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