What kind of aggregation are you looking to perform? Regardless, you can include a query and an aggregation in a single request to the Search API, which sounds like what you might be after. The resulting aggregation will only compute across search results that match the query criteria.
For example,
If SP is the only category with a need for a filter, you could split your aggregation into two buckets for spDetails.isActive: true and spDetails.isActive: false using a filter or terms agg. From there, you could aggregate categories in each bucket and use something like a bucket selector agg for the false bucket to filter out SP results.
This obviously gets unwieldy pretty quickly if you have multiple isActive filters for each category. In that case, I would consider if it would make sense to model your categories as a nested field with category and isActive properties. With this structure you could aggregate across all of your categories within the context of a nested aggregation that filters on categories.isActive. Nested queries can be computationally expensive, so it ultimately comes down to a cost/benefit analysis.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.