[ES 5.2.2] How to 'annotate' results with additional inner_hit/child related data?

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.

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