Values Aggregation
Edit pageA multi-bucket value source based aggregation where buckets are dynamically built - one per unique value.
Structuring
Section titled “Structuring”The following snippet captures the structure of values aggregations:
"<aggregation_name>": { "_values": { "_field": "<field_name>" }, ...}Also supports all other functionality as explained in Bucket Aggregations.
The <field_name> in the _field parameter defines the field on which the
aggregation will act upon.
Assuming the data consists of documents representing bank accounts, as shown in the sample dataset of Data Exploration section, listing all favorite fruits of all account holders:
SEARCH /bank/
{ "_query": "*", "_limit": 0, "_check_at_least": 1000, "_aggregations": { "favorite_fruits": { "_values": { "_field": "favoriteFruit" } } }}Response:
{ "aggregations": { "_doc_count": 1000, "favorite_fruits": [ { "_doc_count": 89, "_key": "apple" }, { "_doc_count": 76, "_key": "strawberry" }, { "_doc_count": 64, "_key": "banana" } ] }, ...}_values takes a field of any type except geospatial (400) and counts the values the field
stores: a keyword keeps its case ("Red" and "red" are two buckets).
Ordering
Section titled “Ordering”By default, the returned buckets are sorted by their _doc_count descending,
though the order behaviour can be controlled using the _sort setting. Supports
the same order functionality as explained in Bucket Ordering.