# Sorting cache?

**URL:** <https://discuss.elastic.co/t/sorting-cache/7073>\
**Category:** Elasticsearch\
**Created:** [March 20, 2012, 3:30pm UTC](https://discuss.elastic.co/t/sorting-cache/7073 "2012-03-20T15:30:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@marcus](https://discuss.elastic.co/u/marcus)\
**Post date:** [March 20, 2012, 3:30pm UTC](https://discuss.elastic.co/t/sorting-cache/7073/1 "2012-03-20T15:30:12Z")

</div>

Hi,

A question that is related to my question here:  
[http://elasticsearch-users.115913.n3.nabble.com/Sorting-tables-tt3839391.html](http://elasticsearch-users.115913.n3.nabble.com/Sorting-tables-tt3839391.html)

I'm doing a really slow MVEL sort script and need to solve that in some way. I know that there is a filter cache where you can cache the filter. Does there exist any sorting cache that could save a specific id sort order into memory?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)\
**Post date:** [March 20, 2012, 3:43pm UTC](https://discuss.elastic.co/t/sorting-cache/7073/2 "2012-03-20T15:43:49Z")

</div>

Marcus,

I've looked at your question a few times and have not commented because I  
don't really understand your data or your requirements. Could you try  
restating what it is you're trying to accomplish? Perhaps some samples?

--Mike

On Tue, Mar 20, 2012 at 11:30 AM, marcus [marcus.1.johansson@nokia.com](mailto:marcus.1.johansson@nokia.com)wrote:

> Hi,
> 
> A question that is related to my question here:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Sorting-tables-tt3839391.html](http://elasticsearch-users.115913.n3.nabble.com/Sorting-tables-tt3839391.html)
> 
> I'm doing a really slow MVEL sort script and need to solve that in some  
> way.  
> I know that there is a filter cache where you can cache the filter. Does  
> there exist any sorting cache that could save a specific id sort order into  
> memory?
> 
> Thanks.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Sorting-cache-tp3842734p3842734.html](http://elasticsearch-users.115913.n3.nabble.com/Sorting-cache-tp3842734p3842734.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@marcus](https://discuss.elastic.co/u/marcus)\
**Post date:** [March 20, 2012, 6:26pm UTC](https://discuss.elastic.co/t/sorting-cache/7073/3 "2012-03-20T18:26:09Z")

</div>

So what I want to do is basically use ES in a way it probably wasn't meant to be used. I would like to do the sorting of the filtering/querying against a joined table instead of the natural search score sorting.

So a simple example would be that I have documents with just an id and a text field. I first do a query against the text field to find the matches of the search query, but instead of letting the \_score be used for sorting I want to sort those matches according to a fixed preset sorting on the id's.

I could of course save this preset sorting as a not analyzed field in ES, my problem is that I want to do this sorting different depending on some attributes, so I will have more preset sorting lists then the amount of fields you should have in an index (100000+).

I have solved this problem using memcache to get the preset sorting and then use MVEL to implement that sorting. My problem is that it is to slow, so I was wondering if there is some way to store those different sort lists in memory via some cache.

---

<div class="post-metadata">

**Author:** ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)\
**Post date:** [March 20, 2012, 9:10pm UTC](https://discuss.elastic.co/t/sorting-cache/7073/4 "2012-03-20T21:10:15Z")

</div>

On Tue, Mar 20, 2012 at 2:26 PM, marcus [marcus.1.johansson@nokia.com](mailto:marcus.1.johansson@nokia.com)wrote:

> So what I want to do is basically use ES in a way it probably wasn't meant  
> to  
> be used. I would like to do the sorting of the filtering/querying against a  
> joined table instead of the natural search score sorting.
> 
> So a simple example would be that I have documents with just an id and a  
> text field. I first do a query against the text field to find the matches  
> of  
> the search query, but instead of letting the \_score be used for sorting I  
> want to sort those matches according to a fixed preset sorting on the id's.
> 
> I could of course save this preset sorting as a not analyzed field in ES,  
> my  
> problem is that I want to do this sorting different depending on some  
> attributes, so I will have more preset sorting lists then the amount of  
> fields you should have in an index (100000+).

Have you tried going this route? How many potential sort fields are you  
talking about? How many do you sort by in an average or complex query? I've  
used ES to do 2 and 3 field on reasonably sized collections and it's been  
fine after the caches have warned up.

> I have solved this problem using memcache to get the preset sorting and  
> then  
> use MVEL to implement that sorting. My problem is that it is to slow, so I  
> was wondering if there is some way to store those different sort lists in  
> memory via some cache.

I can imagine a few approaches but would like to know if the vanilla one  
has been tried. ES has been quite speedy for me thus far.

---

<div class="post-metadata">

**Author:** ![marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@marcus](https://discuss.elastic.co/u/marcus)\
**Post date:** [March 22, 2012, 1:24pm UTC](https://discuss.elastic.co/t/sorting-cache/7073/5 "2012-03-22T13:24:17Z")

</div>

Have you tried going this route? How many potential sort fields are you talking about? How many do you sort by in an average or complex query? I've used ES to do 2 and 3 field on reasonably sized collections and it's been fine after the caches have warned up.

We have around 100000 different combinations.

I can imagine a few approaches but would like to know if the vanilla one has been tried. ES has been quite speedy for me thus far.

We have tried the vanilla solution to just create one not analyzed field for each combination, but it was to slow (1 second+).

---

<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:** [July 6, 2017, 3:35am UTC](https://discuss.elastic.co/t/sorting-cache/7073/6 "2017-07-06T03:35:10Z")

</div>


