Hi Samanth ,

First you will need to make that array into nested type. -
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html#mapping-nested-type

Then you need to do a 2 level agg with term aggregation at parent on field
prod_type and sum aggregation on price field.

Term aggregation -
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
Sum aggregation -
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html

Thanks
          Vineeth


On Tue, Jul 8, 2014 at 4:23 PM, K.Samanth Kumar Reddy <
samanthkuma...@gmail.com> wrote:

> Hi,
>
> I am working on elasticsearch for last 2 months. It is really providing
> awesome searching capabilities, good json structure documents etc...
> Currently I am stuck up with the problem on How to write group by query
> and get the data.
>
> Ex:- In this example company, prod_type are defined as 'not_analyzed'
>
> Example Documents:
>
> {"company":"ABC","orders":[{"order_no":"OL1", "prod_type" : "OLP",
> "price":20}, {"order_no":"OL2", "prod_type" : "OLP", "price":50},
> {"order_no":"OL3", "prod_type" : "GLP", "price":100} ]}
>
> {"company":"XYZ","orders":[{"order_no":"OL10", "prod_type" : "GLP",
> "price":50}, {"order_no":"OL20", "prod_type" : "OLP", "price":80},
> {"order_no":"OL30", "prod_type" : "GLP", "price":100} ]}
>
>
> My Requirement: I want the elasticsearch query to get the count,
> sum(price) based on prod_type
> SQL Comparision Qry: SELECT COUNT(*), SUM(PRICE) FROM TABLE_NAME GROUP BY
> PROD_TYPE
>
>
> Can anyone please help me this?
>
> Please let me know if you need more information.
>
>
> Thanks,
> Samanth
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/227ad9cc-0327-48de-9df9-bc0c159d9250%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/227ad9cc-0327-48de-9df9-bc0c159d9250%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAGdPd5n1PKoXYgg0Y9y-6K%3DBN3UX920DYV%2BEpv9wGgPZZOgxsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to