How to use aggregations in elasticsearch 1.0?


(Daniel Guo) #1

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.
To view this discussion on the web visit 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.


(Binh Ly-2) #2

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.
To view this discussion on the web visit 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.


(Teemu Kurppa) #3

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/965fe771-5e28-42e5-9e0f-b391cda52cd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4