When a bookstore search groups books by rating, release year, or author and title, each bucket reports how many documents it contains. That value is doc_count. section 13.3.1 section 13.3.5
A bucket response commonly contains key and doc_count. key identifies the bucket; doc_count counts the documents that fit it. This differs from the _count API’s count variable, which reports documents across an index or query scope. section 2.2.1 section 13.3.1
Read doc_count according to the aggregation:
- A rating histogram can report two books in one rating range and 35 in another. section 13.3.1
- A date histogram can show yearly release totals, such as five books in 2020 and six in 2021. section 13.3.1
- A multi_terms aggregation can count documents for each author-title combination. section 13.3.5
Listing 13.10 A histogram aggregation for books
GET books/_search
{
"size": 0,
"aggs": {
"ratings_histogram": { #1
"histogram": { #2
"field": "amazon_rating", #3
"interval": 1 #4
}
}
}
}
Run the histogram query to see how aggregation buckets produce document counts. section 13.3.1
Listing 13.18 Aggregation for authors and their book titles as a map
GET books/_search?size=0
{
"aggs": {
"author_title_map": {
"multi_terms": { #1
"terms": [ #2
{
"field": "author.keyword"
},
{
"field": "title.keyword"
}
]
}
}
}
}
Compare author-title keys with the doc_count returned for each combined key. section 13.3.5
