# \[ES 5.2.2\] How to 'annotate' results with additional inner\_hit/child related data?

**URL:** <https://discuss.elastic.co/t/es-5-2-2-how-to-annotate-results-with-additional-inner-hit-child-related-data/79817>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 9:59pm UTC](https://discuss.elastic.co/t/es-5-2-2-how-to-annotate-results-with-additional-inner-hit-child-related-data/79817 "2017-03-23T21:59:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)\
**Post date:** [March 23, 2017, 9:59pm UTC](https://discuss.elastic.co/t/es-5-2-2-how-to-annotate-results-with-additional-inner-hit-child-related-data/79817/1 "2017-03-23T21:59:55Z")

</div>

Is it possible to restrict the scope of aggregations to JUST the page of data coming back from the query?

Meaning, I want to show aggregation data related ONLY to the query results in the range specified by the query's 'page' and 'size' INSTEAD of relating to ALL of the query's results?

* * *

Kind of complicated but here's the situation:

- I have a parent/child document setup: business (parent) -\> class (child)
- both businesses and classes can be tagged (ie. 'Arts' or 'Science', etc)
- I have a bool should query to return businesses that are either (tagged with 'Arts') or (have currently running classes tagged with 'Arts')

The above works fine. I use 'inner\_hits' on the 'has\_child' query to discover the number of 'Arts' classes each business returned has.

**Keeping the same results as the above produces** , I now want to 'annotate' the results to discover how many currently running classes REGARDLESS of what the classes are tagged as. ie. I want the results to include only those businesses tagged with 'Arts' or with classes tagged as 'Arts', but I also want to know if they have any other classes running that might NOT be tagged with 'Arts'. A bool would suffice, but a count would be best.

I was thinking aggregations might help me solve this, but I don't think I can restrict the aggregations to the paginated result set - and if so, I'm not sure it would be efficient. I appreciate any feedback! Thanks.

---

<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:** [April 20, 2017, 10:00pm UTC](https://discuss.elastic.co/t/es-5-2-2-how-to-annotate-results-with-additional-inner-hit-child-related-data/79817/2 "2017-04-20T22:00:19Z")

</div>

Closed on April 20, 2017, 10:00pm UTC

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