Search code examples
elasticsearchnest

How can I define the size of the ElasticSearch aggregations response, using NEST?


I'm using NEST to write an aggregation query which should result in all possible values for a certain field.

The json variant of what I wish to implement:

GET /my_index/_search
{
  "size": 0,
  "aggs": {
    "user-name": {
      "terms": {
        "field": "name",
        "size": 1000    <== 
      }
    }
  }
}

Using the AggregationContainerDescriptor I currently have:

var descriptor = new AggregationContainerDescriptor<User>();
descriptor.Terms("user-name", x => x.Field("username"))

This would return by default 10 results. How can set the response size to 1000?


Solution

  • var descriptor = new AggregationContainerDescriptor<User>();
    descriptor.Terms("user-name", x => x.Size(1000).Field("username"));