# Query with union and group in elasticsearch

**URL:** <https://discuss.elastic.co/t/query-with-union-and-group-in-elasticsearch/101954>\
**Category:** Elasticsearch\
**Created:** [September 27, 2017, 9:03am UTC](https://discuss.elastic.co/t/query-with-union-and-group-in-elasticsearch/101954 "2017-09-27T09:03:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackl](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jackl](https://discuss.elastic.co/u/jackl)\
**Post date:** [September 27, 2017, 9:03am UTC](https://discuss.elastic.co/t/query-with-union-and-group-in-elasticsearch/101954/1 "2017-09-27T09:03:32Z")

</div>

select table.x, sum(table.y) from(  
select a x, sum(b) y from table1 group by a  
union all  
select c x, sum(d) y from table1 group by c  
)

I don't know how to implement the SQL above in elasticsearch(5.5)，

Does anyone know how it works? Thank you very much!

---

<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:** [October 25, 2017, 9:03am UTC](https://discuss.elastic.co/t/query-with-union-and-group-in-elasticsearch/101954/2 "2017-10-25T09:03:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
