Optimize multiple queries with the same filters

Hi I have a question related with optimization, I have a page lets call it global page that haves N components on each.

Each component will perform an elasticsearch query that is going to be composed of two parts

  1. Query is set at global page level
  2. Aggregation is created by the component.

The current way of things make each component to generate a full query using the global page generated query and the component's aggregation. Which results in the global page making >= N requests all of them using the same query.

The requests have size=0 encouraging caching of the aggregated results and that didn't resulted since the cache key is the full query json and it won't work when it changes. I wonder if there is a way to improve this.

I was looking solutions like locking results but so far I have found none.

I also tried running a prep query fetching the document ids and then aggregating on each component over a query matching the ids with the specific aggregation but since we have too many documents for some cases the payload can get pretty big since the ids are long strings.

Any advice?

Hi Solenom85,
Instead of running query from each component I would try to collect component aggregations at the global page level and run a single query with all aggregates.

As for caching, if you have a primary and a replica your first query may go to primary and second may go to replica.

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