All articles
  • Absolute Intelligence
  • LISSA
  • Worth knowing

Optimising OpenSearch aggregations with high cardinality

3 minute read

Aggregations in OpenSearch are a useful tool for analysing indexed data. Once the data holds an extreme number of unique values, however, the cost of these operations grows significantly. Is it even possible to aggregate more than a hundred billion e-mail addresses, almost 90% of which are unique?

Daniel Štrbák

Summary

  • Aggregations over more than a billion highly variable documents required tens of billions of buckets and quickly exhausted the memory dedicated to OpenSearch.
  • Commonly recommended practices, and advanced options such as partitions, sampling or routing queries to selected shards, did not solve the situation on their own.
  • The combination of approaches we chose handles samples of hundreds of millions to a few billion records within minutes without endangering the stability of the cluster.

Challenges of working with high cardinality

Working with a volume of data like this, we soon ran into the limits of the standard OpenSearch options, especially when an aggregation required creating tens of billions of buckets. Even optimising the cluster or the hardware is often not enough in such situations, and when such requests are processed, the memory dedicated to OpenSearch is used up very quickly and the query fails.

First we tried commonly recommended practices, such as limiting the size of the queried datasets or splitting the data into smaller indices. In some cases these methods can be useful, because they reduce the load on memory and make the cluster easier to manage. In our scenario, however, they were not flexible enough: limiting the dataset was impractical because we needed to aggregate any part of the data, and splitting it into several indices would have meant frequent reindexing.

Fortunately, OpenSearch offers several advanced options for configuring search queries. It is possible to adjust the parameters of aggregations, to use partitioning for step-by-step processing of queries, or to use sampling, which analyses only a representative sample of documents and so reduces the load on the system. Another option is to route queries only to selected shards of the OpenSearch cluster, which limits the volume of data processed in one request. These tools too have their limits: with extreme volumes of data and high cardinality they often reach the limits of scalability and of the memory available.

None of these practices was therefore able to solve our situation on its own. To be able to run aggregations even on such a large dataset, we had to analyse, experiment and carefully set a whole range of parameters. The solution we finally chose required a thorough understanding not only of the internal principles of how OpenSearch works, but also of its configuration options and how to adapt it to the requirements of extremely high cardinality.

Conclusion

Instead of relying on one particular setting or a universal procedure, we found a combination of approaches that made it possible to turn queries that were originally infeasible into an effective analytical tool, even where common advice and the available documentation were not enough. The result was a significant improvement in the speed and success rate of processing samples of data of hundreds of millions to a few billion records within minutes, without having to endanger the stability of the cluster.

Our experience shows that even extremely demanding analytical scenarios can be handled in OpenSearch if they are given enough attention and effort. By using advanced options and a deeper knowledge of how the system works, a solution can be found even where standard practices fail. The result allowed us to analyse a massive dataset with high cardinality effectively and to create a tool that meets the requirements of even the most demanding cases, without endangering the availability or performance of the OpenSearch cluster.

Get in touch

A few sentences about what you are working on will help us prepare.

We describe how we handle personal data in our privacy policy.

You can also call us on +420 228 227 418 or email us at info@datera.cz.