Hi Samanth,
I have started working on elasticsearch recently. I'm trying to get some
result exactly like what you have tried. But the problem is I'm getting sum
value same for all buckets ( Total price of the document where the prod
type exists )
For your example the search json I wrote is
{
"aggs": {
"prod_type": {
"terms": {
"field": "orders.prod_type"
},
"aggs": {
"total_price": {
"sum": {
"field": "price"
}
}
}
}
}
}
The result I got is
"aggregations": {
"prod_type": {
"buckets": [
{
"key": "glp",
"doc_count": 2,
"total_price": {
"value": 400
}
},
{
"key": "olp",
"doc_count": 2,
"total_price": {
"value": 400
}
}
]
}
}
Could you please help me out in this?
Regards,
Raja
On Wednesday, July 9, 2014 9:21:11 AM UTC+5:30, K.Samanth Kumar Reddy wrote:
>
> Thank you very much. Its working.
>
> Thanks,
> Samanth
>
> On Tuesday, July 8, 2014 4:23:18 PM UTC+5:30, K.Samanth Kumar Reddy 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/192cf64d-c704-4dc5-ac49-f896c10b3e26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.