# Terms aggregation with include

**URL:** <https://discuss.elastic.co/t/terms-aggregation-with-include/106345>\
**Category:** Elasticsearch\
**Created:** [November 3, 2017, 4:45pm UTC](https://discuss.elastic.co/t/terms-aggregation-with-include/106345 "2017-11-03T16:45:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natalia\_Kuleniuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/natalia_kuleniuk/32/43727_2.png) [@Natalia\_Kuleniuk](https://discuss.elastic.co/u/Natalia_Kuleniuk)\
**Post date:** [November 3, 2017, 4:45pm UTC](https://discuss.elastic.co/t/terms-aggregation-with-include/106345/1 "2017-11-03T16:45:14Z")

</div>

Hello. Here is my problem:  
I have query to get data for specific vendorCode in specific range - lines 3-13.  
Than I want to get aggregations on videoViews for all data vendor have - lines 14-18  
Than I need to create two buckets - "Channel One" and "Channel Two". Those two buckets should "include" only contentIds that are stated in list of "include" filter: line 23 and line 37.  
The last thing I need to do is to calculate videoViews for each CHANNEL NAME. But what I got here (line 26-30) is calculating videoViews for each CONTENT ID instead.  
How can I get videoViews total FOR EACH CHANNEL INSTEAD of for each content id in this channel?

 ![43 AM](https://us1.discourse-cdn.com/elastic/original/3X/e/2/e26b827061239dc2f4f30cbd7ed3bc0f0b060dbe.png)

\*\*Without changing mapping, adding scripts or adding channel name fields to ES index

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 3, 2017, 5:24pm UTC](https://discuss.elastic.co/t/terms-aggregation-with-include/106345/2 "2017-11-03T17:24:09Z")

</div>

Please don't post images of text as they are hardly readable and not searchable.

Instead paste the text and format it with `</>` icon. Check the preview window.

---

<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:** [December 1, 2017, 5:24pm UTC](https://discuss.elastic.co/t/terms-aggregation-with-include/106345/3 "2017-12-01T17:24:10Z")

</div>

Closed on December 1, 2017, 5:24pm UTC

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