# How do I construct a query with join query and aggs ？

**URL:** <https://discuss.elastic.co/t/how-do-i-construct-a-query-with-join-query-and-aggs/71302>\
**Category:** Elasticsearch\
**Created:** [January 12, 2017, 2:56am UTC](https://discuss.elastic.co/t/how-do-i-construct-a-query-with-join-query-and-aggs/71302 "2017-01-12T02:56:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![a943013827](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@a943013827](https://discuss.elastic.co/u/a943013827)\
**Post date:** [January 12, 2017, 2:56am UTC](https://discuss.elastic.co/t/how-do-i-construct-a-query-with-join-query-and-aggs/71302/1 "2017-01-12T02:56:44Z")

</div>

This is the case：  
I have two type

```
sessions's mapping:
    u'sessions': {u'_all': {u'enabled': False},
                           u'dynamic': u'false',
                           u'properties': {
                                    u'rt': {u'index': u'not_analyzed', u'type': u'string'},
                                    u'sid': {u'index': u'not_analyzed', u'type': u'string'},
                                    u'ch': {u'index': u'not_analyzed', u'type': u'string'}
                                    }
                     }

u'events': {
                   u'_all': {u'enabled': False}, 
                   u'_parent': {u'type': u'sessions'},
                   u'_routing': {u'required': True},
                   u'properties':{
                               u'eid': {u'index': u'not_analyzed', u'type': u'string'}
                   }
            }

```

i want to aggs the events by sessions's ch

like this:  
{  
"ch1" : 22, // 22 is event count  
"ch2":45,  
}  
How do I construct a query?

---

<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:** [February 9, 2017, 2:56am UTC](https://discuss.elastic.co/t/how-do-i-construct-a-query-with-join-query-and-aggs/71302/2 "2017-02-09T02:56:58Z")

</div>

Closed on February 9, 2017, 2:56am UTC

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