{"id":3029,"date":"2026-09-11T13:46:49","date_gmt":"2026-09-11T13:46:49","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=3029"},"modified":"2026-09-12T06:35:33","modified_gmt":"2026-09-12T06:35:33","slug":"aggregations-in-elasticsearch","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/","title":{"rendered":"Aggregations in ElasticSearch:"},"content":{"rendered":"<h1>Aggregations in Elasticsearch: Types, Syntax and Examples<\/h1>\n<p><strong><b>Aggregations<\/b><\/strong> are one of Elasticsearch&#8217;s most powerful features outside plain full-text search. They let you summarise and analyse data directly inside your index like group records, calculate statistics, and answer questions instead of scanning documents one by one.<\/p>\n<p>Because Elasticsearch runs this across a distributed index rather than a single table, it computes aggregations far faster than a traditional RDBMS running the equivalent GROUP BY logic. That speed is a big reason Elasticsearch is used for big data analytics, not only search.<\/p>\n<h2>What is an &#8220;aggs&#8221; Query in Elasticsearch?<\/h2>\n<p>Every aggregation runs inside the <strong><b>aggs<\/b><\/strong> (short for aggregations) parameter of a search request. You give each aggregation a name, then define what it should compute, for example,\u00a0 grouping documents, calculating a metric, or both together in the same query.<\/p>\n<h2>Types of Aggregations in Elasticsearch<\/h2>\n<ul>\n<li><b><\/b><strong><b>Bucket aggregations<\/b><\/strong>group documents into buckets based on field values, ranges or other criteria, the rough equivalent of SQL&#8217;s GROUP BY.<\/li>\n<li><b><\/b><strong><b>Metric aggregations<\/b><\/strong>compute a single statistic, such as avg, sum, min, max or count, from a numeric field.<\/li>\n<li><b><\/b><strong><b>Pipeline aggregations<\/b><\/strong>run on the output of other aggregations rather than on raw documents, useful for things like moving averages or cumulative sums.<\/li>\n<\/ul>\n<p>Most real queries combine a bucket aggregation with one or more metric aggregations, which is exactly what the three examples below show.<\/p>\n<h2>Example 1: Grouping Documents With a Bucket Aggregation<\/h2>\n<p>The query below defines a <strong><b>bucket aggregation<\/b><\/strong>\u00a0named popular_cars inside the aggs component. It groups documents by the make field, so each distinct car make becomes its own bucket, with a count of how many documents fall into it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3030\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png\" alt=\"\" width=\"850\" height=\"495\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png 340w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss-300x175.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h2>Example 2: Running Multiple Aggregations Together<\/h2>\n<p>An aggs component isn&#8217;t limited to one aggregation. It can hold several, each independent of the others. In the example below, popular_cars (a bucket aggregation) runs alongside avg_price, max_price, and min_price,\u00a0 three separate <strong><b>metric aggregations<\/b><\/strong>, all inside the same request.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3031\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/multiple-aggs.png\" alt=\"\" width=\"850\" height=\"790\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/multiple-aggs.png 340w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/multiple-aggs-300x279.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h2>Example 3: Nesting an Aggregation Inside Another<\/h2>\n<p>Aggregations can also be <strong><b>nested<\/b><\/strong>, so one runs inside the scope of another. Here, popular_cars still groups documents by make, but inside each bucket we add a second aggregation called stats_price using the <strong><b>stats<\/b><\/strong> clause. The stats aggregation returns the average, minimum, maximum, and sum of the price field,\u00a0 but scoped only to the documents inside that specific make&#8217;s bucket, not the whole index.<\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3032\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggs_output.png\" alt=\"\" width=\"850\" height=\"1493\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggs_output.png 283w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggs_output-171x300.png 171w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><br \/>\nWhy Aggregations Matter for Big Data Analytics?<\/h2>\n<p>Because bucket, metric, and pipeline aggregations can be combined and nested this way, a single Elasticsearch query can replace what would otherwise need several SQL queries plus application-side processing to group and summarise. That&#8217;s the main reason aggregations are why teams reach for Elasticsearch on large, fast-moving datasets.<\/p>\n<p>This covers the core aggregation types and syntax in Elasticsearch. To go deeper into building full-scale search and analytics pipelines, explore <a href=\"https:\/\/prwatech.in\/big-data-course-in-bangalore\/\"><strong><b>Prwatech&#8217;s Big Data training<\/b><\/strong>\u00a0program<\/a>, which includes placement assistance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Aggregations in Elasticsearch: Types, Syntax and Examples Aggregations are one of Elasticsearch&#8217;s most powerful features outside plain full-text search. They let you summarise and analyse data directly inside your index like group records, calculate statistics, and answer questions instead of scanning documents one by one. Because Elasticsearch runs this across a distributed index rather than [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57,1702],"tags":[],"class_list":["post-3029","post","type-post","status-publish","format-standard","hentry","category-elastic-search","category-elasticsearch-modules"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Aggregations in Elasticsearch: Types, Syntax &amp; Examples<\/title>\n<meta name=\"description\" content=\"Understand Elasticsearch aggregations, like bucket, metric and nested aggs with clear syntax examples for grouping and analyzing data. Learn more today!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Aggregations in Elasticsearch: Types, Syntax &amp; Examples\" \/>\n<meta property=\"og:description\" content=\"Understand Elasticsearch aggregations, like bucket, metric and nested aggs with clear syntax examples for grouping and analyzing data. Learn more today!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-11T13:46:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-12T06:35:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png\" \/>\n\t<meta property=\"og:image:width\" content=\"340\" \/>\n\t<meta property=\"og:image:height\" content=\"198\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/\",\"url\":\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/\",\"name\":\"Aggregations in Elasticsearch: Types, Syntax & Examples\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png\",\"datePublished\":\"2026-09-11T13:46:49+00:00\",\"dateModified\":\"2026-09-12T06:35:33+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Understand Elasticsearch aggregations, like bucket, metric and nested aggs with clear syntax examples for grouping and analyzing data. Learn more today!\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png\",\"width\":340,\"height\":198},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Aggregations in ElasticSearch:\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Aggregations in Elasticsearch: Types, Syntax & Examples","description":"Understand Elasticsearch aggregations, like bucket, metric and nested aggs with clear syntax examples for grouping and analyzing data. Learn more today!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/","og_locale":"en_US","og_type":"article","og_title":"Aggregations in Elasticsearch: Types, Syntax & Examples","og_description":"Understand Elasticsearch aggregations, like bucket, metric and nested aggs with clear syntax examples for grouping and analyzing data. Learn more today!","og_url":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2026-09-11T13:46:49+00:00","article_modified_time":"2026-09-12T06:35:33+00:00","og_image":[{"width":340,"height":198,"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png","type":"image\/png"}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/","url":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/","name":"Aggregations in Elasticsearch: Types, Syntax & Examples","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png","datePublished":"2026-09-11T13:46:49+00:00","dateModified":"2026-09-12T06:35:33+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Understand Elasticsearch aggregations, like bucket, metric and nested aggs with clear syntax examples for grouping and analyzing data. Learn more today!","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/11\/aggssss.png","width":340,"height":198},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/elastic-search\/elasticsearch-modules\/aggregations-in-elasticsearch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Aggregations in ElasticSearch:"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/3029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=3029"}],"version-history":[{"count":8,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/3029\/revisions"}],"predecessor-version":[{"id":11710,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/3029\/revisions\/11710"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=3029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=3029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=3029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}