# How to use aggregations in elasticsearch 1.0?

**URL:** <https://discuss.elastic.co/t/how-to-use-aggregations-in-elasticsearch-1-0/16167>\
**Category:** Elasticsearch\
**Created:** [March 5, 2014, 9:56am UTC](https://discuss.elastic.co/t/how-to-use-aggregations-in-elasticsearch-1-0/16167 "2014-03-05T09:56:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [March 5, 2014, 9:56am UTC](https://discuss.elastic.co/t/how-to-use-aggregations-in-elasticsearch-1-0/16167/1 "2014-03-05T09:56:35Z")

</div>

hi, I have a simple SQL:

select sum(count) from mytable group by id;

if I want to implement in elasticsearch, I think I should use aggregations.  
Cloud anybody give me a hint, thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/05d17445-6940-4e2c-8091-2a59581a0354%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/05d17445-6940-4e2c-8091-2a59581a0354%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [March 5, 2014, 1:27pm UTC](https://discuss.elastic.co/t/how-to-use-aggregations-in-elasticsearch-1-0/16167/2 "2014-03-05T13:27:23Z")

</div>

Assuming count is a numeric field and id is a single value:

```
{
  "aggs": {
    "group_by_id": {
      "terms": {
        "field": "id"
      },
      "aggs": {
        "sum_count": {
          "sum": {
            "field": "count"
          }
        }
      }
    }
  }
}

```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e6fbdf9a-ab4e-4b4d-b2fa-3d9426f95bf9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e6fbdf9a-ab4e-4b4d-b2fa-3d9426f95bf9%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Teemu\_Kurppa](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@Teemu\_Kurppa](https://discuss.elastic.co/u/Teemu_Kurppa)\
**Post date:** [March 11, 2014, 1:53pm UTC](https://discuss.elastic.co/t/how-to-use-aggregations-in-elasticsearch-1-0/16167/3 "2014-03-11T13:53:40Z")

</div>

Note that Elasticsearch aggregation behaves somewhat unintuitively: to get  
correct amount of sums you need to set a large enough size parameter to the  
`terms` aggregation:

```
 "terms": {
        "field": "id"
        "size": 10000
      },

```

In Elasticsearch 1.1.0 you are able to set size to 0 to get all the results

On Wednesday, March 5, 2014 3:27:23 PM UTC+2, Binh Ly wrote:

> Assuming count is a numeric field and id is a single value:
> 
> ```
> {
> "aggs": {
> "group_by_id": {
> "terms": {
> "field": "id"
> },
> "aggs": {
> "sum_count": {
> "sum": {
> "field": "count"
> }
> }
> }
> }
> }
> }
> 
> ```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/965fe771-5e28-42e5-9e0f-b391cda52cd3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/965fe771-5e28-42e5-9e0f-b391cda52cd3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:44am UTC](https://discuss.elastic.co/t/how-to-use-aggregations-in-elasticsearch-1-0/16167/4 "2017-07-06T01:44:10Z")

</div>


