Value count aggregation

Value count aggregation #

A single-value metrics aggregation that counts the number of values that are extracted from the aggregated documents. Typically, this aggregator will be used in conjunction with other single-value aggregations. For example, when computing the avg one might be interested in the number of values the average is computed over.

value_count does not de-duplicate values, so even if a field has duplicates each value will be counted individually.

Examples #

Assuming the data consists of documents representing sales records we can sum the sale price of all hats with:

POST /sales/_search
{
  "aggs" : {
    "types_count" : {
      "value_count" : {
        "field" : "type"
      }
    }
  }
}

Response:

{
  ...
  "aggregations": {
    "types_count": {
      "value": 7
    }
  }
}

The name of the aggregation (types_count above) also serves as the key by which the aggregation result can be retrieved from the returned response.

Parameters for avg #

  • field
    (Required, string) Field you wish to aggregate.