# Index sorting with Elasticsearch 6.2.4 for query performance

**URL:** <https://discuss.elastic.co/t/index-sorting-with-elasticsearch-6-2-4-for-query-performance/175325>\
**Category:** Elasticsearch\
**Created:** [April 4, 2019, 6:31am UTC](https://discuss.elastic.co/t/index-sorting-with-elasticsearch-6-2-4-for-query-performance/175325 "2019-04-04T06:31:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShilpiRachna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shilpirachna/32/42261_2.png) [@ShilpiRachna](https://discuss.elastic.co/u/ShilpiRachna)\
**Post date:** [April 4, 2019, 6:31am UTC](https://discuss.elastic.co/t/index-sorting-with-elasticsearch-6-2-4-for-query-performance/175325/1 "2019-04-04T06:31:41Z")

</div>

Hi,

We are working on improving our query performance. Our queries are always filtered by customer account id and project id. Multiple accounts can exist on the same shard. We use routing based on account id to query the right shard. Would sorting by account id and project id improve query performance? We believe that the filter matches would be extremely fast due to sorting and the number of documents that need to be matched for the actual term queries would also be in same / sequential segments, thus improving their performance as well. Has anyone tried sorting in a similar scenario and seen query performance improvement?

If not sorting, is there any other way to logically partition account and project data? We cannot have one index per account as the number of accounts is huge and the data size per account / project is not very large (on average).

Thanks!  
Shilpi

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [April 4, 2019, 7:32am UTC](https://discuss.elastic.co/t/index-sorting-with-elasticsearch-6-2-4-for-query-performance/175325/2 "2019-04-04T07:32:16Z")

</div>

Index sorting can improve conjunctions as explained here:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-index-sorting-conjunctions.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-index-sorting-conjunctions.html)  
It could also improve the compression on disk if documents that share the same account id have similar content. This blogpost summarizes the benefit of this approach:

> **[Space Savings: A Lesser Known Benefit of Index Sorting in Elasticsearch
	  	...](https://www.elastic.co/blog/space-savings-a-lesser-known-benefit-of-index-sorting-in-elasticsearch)**
>
> In Elasticsearch 6.0, we released a new feature called index sorting. Read up more on this on the linked blog, but in short, what this does is to take the documents at index time and sort them by a ke...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 2, 2019, 7:32am UTC](https://discuss.elastic.co/t/index-sorting-with-elasticsearch-6-2-4-for-query-performance/175325/3 "2019-05-02T07:32:38Z")

</div>

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