June 2017
Beginner to intermediate
404 pages
8h 22m
English
The aggregation query is executed using the search API. You can add a query to restrict the document you want to run the aggregations on. Let's start by looking at a simple aggregation to group all the products by their category. In the SQL world, the query would look like the following:
select count(*) from Productgroup by category;
In Elasticsearch, to achieve the same, we would do the following:
POST chapter8/_search{ "aggs" :{ "category_products" : { "terms" : { "field" : "category" } } }}
The basic structure is as follows:
"aggs" :{ // Can be aggs or aggregation. "category_products" : { // Name of the aggregation "terms" : { // Type of the aggregation
The results of the preceding query are as follows:
{.... "aggregations": ...Read now
Unlock full access