This is a cache of https://www.elastic.co/search-labs/blog/Elasticsearch-sorting-speed-up. It is a snapshot of the page at 2025-07-01T01:01:22.013+0000.
<strong>elasticsearch</strong> sorting just got up to 900x faster - <strong>elasticsearch</strong> Labs

elasticsearch sorting just got up to 900x faster

Discover how we sped up elasticsearch sorting with faster float/half_float sorting and latency improvements in integer sorting

elasticsearch is packed with new features to help you build the best search solutions for your use case. Dive into our sample notebooks to learn more, start a free cloud trial, or try Elastic on your local machine now.

elasticsearch continues to improve on sorting speed for field types, with version 9.0.1 now having accelerated float/half_float sorting. Additionally, the upcoming elasticsearch 9.1 will also include enhancements that will deliver remarkable latency improvements in integer sorting.

Not only are these new sorting enhancements available in Elastic Cloud Serverless, they will be backported to elasticsearch 8.19, allowing customers not yet ready to move to elasticsearch 9.x to also benefit from improved sorting speed.

Using 2 different benchmarks, we see a wide array of improved latencies:

  • NYC Taxis for float and half_float sorting: 83x to 920x
  • Http_logs for integer sorting: 41x to 531x

Check out our nightly benchmarks for http_logs here. (Note: additional sort latencies were added to the benchmarks in May 2025).

Background

In 2020, with elasticsearch 7.6, we made a significant investment in optimizing sort on long and date field types. As a result of this, for example, retrieving logs sorted by recent timestamps became much faster. We followed this optimization with an enhancement in 7.16 where we enabled search_after parameter (which enabled the common pagination use case).

This time, we are applying the same optimization to integer, short, and byte field types, as well as float and half_float field types.

Depending on your data and its distribution across segments, you may observe speedups ranging from a few to several hundred times for sorted queries on integer, short, byte, float and half_float data types.

How do we do it?

Instead of relying on index sorting, we employed the novel approach of combining BKD (Block k-dimensional) Trees with distance queries. BKD Trees have leaf blocks properties that lend themselves to being skipped since the field min and max values of the block are available for comparison.

Combining this with using the distance_feature query, we can rapidly determine during comparison which blocks are non-competitive. This enables significant time savings as we skip non-competitive data regions.

Whether we measure the distance from the global minimum or maximum depends on whether we are sorting ascending or descending.

This implies that the field must be indexed and cannot be null.

Further details can be found in a previous blog on optimizing sort queries.

Now on to the results….


Results

NYC Taxis benchmark

On the NYC Taxis benchmark (with half_float added), the speedup range is from 83x to 920x (calculated by dividing the prior P90 latency with the new P90 latency):

Visually, in log scale, we see the significant improvement:

This acceleration in sorting of float, half_float is already available in elasticsearch 9.0.1 and is also available in Elastic Cloud Serverless. It will be backported to elasticsearch 8.19.

Http_logs benchmark

We used the http_logs track from the open-source Rally tool. We ran with the default settings available here.

For the improvements in integer sort, we see speedups between 41x and 531x in the http_logs benchmark (again calculated by dividing the prior P90 latency with the new P90 latency) across eight different use cases.

Again, we see the stark improvement contrast even in log scale:

The improvement in integer sorting is dramatic according to our nightly benchmarks, replicated here:

A whole host of use cases benefit from this speedup, including analytics dashboards in Observability, Security and Search. Lower latencies also lead to more efficient computation and lower infrastructure costs for users.

Looking forward to elasticsearch 9.1

Elastic 9.1 will also include other exciting enhancements, including but not limited to:

We’re committed to continuous innovation so you can build the fastest search apps.



Related content

Ready to build state of the art search experiences?

Sufficiently advanced search isn’t achieved with the efforts of one. elasticsearch is powered by data scientists, ML ops, engineers, and many more who are just as passionate about search as your are. Let’s connect and work together to build the magical search experience that will get you the results you want.

Try it yourself