# Alphabetic sorting strategies

**URL:** <https://discuss.elastic.co/t/alphabetic-sorting-strategies/14554>\
**Category:** Elasticsearch\
**Created:** [November 22, 2013, 7:46pm UTC](https://discuss.elastic.co/t/alphabetic-sorting-strategies/14554 "2013-11-22T19:46:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Painter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_painter/32/1251_2.png) [@Matthew\_Painter](https://discuss.elastic.co/u/Matthew_Painter)\
**Post date:** [November 22, 2013, 7:46pm UTC](https://discuss.elastic.co/t/alphabetic-sorting-strategies/14554/1 "2013-11-22T19:46:53Z")

</div>

Hi all,

We have a field that we would like to (approximately) sort on that is  
unique and unicode - and potentially long.

In order to decrease the amount of memory required by elasticsearch, we  
have been thinking about strategies such as:

- using a multi field and only indexing the first n characters
- mapping the strings to a float

Does anyone have any good suggestions for how to manage this kind of use  
case better?

Thanks 🙂

Matt

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 22, 2013, 9:15pm UTC](https://discuss.elastic.co/t/alphabetic-sorting-strategies/14554/2 "2013-11-22T21:15:35Z")

</div>

Use ICU collation of the ICU plugin for sorting. With the "strength" level,  
sort key length may be affected. Sorting depends on locale, so I do not  
recommend only indexing first n characters.

> **[elastic/elasticsearch-analysis-icu](https://github.com/elastic/elasticsearch-analysis-icu)**
>
> elasticsearch-analysis-icu - ICU Analysis plugin for Elasticsearch

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Matthew\_Painter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_painter/32/1251_2.png) [@Matthew\_Painter](https://discuss.elastic.co/u/Matthew_Painter)\
**Post date:** [November 22, 2013, 10:51pm UTC](https://discuss.elastic.co/t/alphabetic-sorting-strategies/14554/3 "2013-11-22T22:51:46Z")

</div>

Indeed I see that the more loose you are with comparison, the shorter a  
collation key can be.

I can't see what issues taking the first n characters would cause, assuming  
the accents are combined with letters in the normalized Unicode form? Of  
course what would perhaps be a better alternative is only taking the first  
n bytes of the collation key. This should give an approximate ordering with  
a known precision. Doing this, ignoring punctuation in the collator, looks  
best to me to get a good-enough ordering?

Thanks for the input of course 🙂

On Friday, November 22, 2013, [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> Use ICU collation of the ICU plugin for sorting. With the "strength"  
> level, sort key length may be affected. Sorting depends on locale, so I do  
> not recommend only indexing first n characters.
> 
> [GitHub - elastic/elasticsearch-analysis-icu: ICU Analysis plugin for Elasticsearch](https://github.com/elasticsearch/elasticsearch-analysis-icu)
> 
> Jörg
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/tAhq6GbfuPg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/tAhq6GbfuPg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) \<javascript:\_e({}, 'cvml',  
> 'elasticsearch%2Bunsubscribe@googlegroups.com');\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Sent from Gmail Mobile

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 23, 2013, 12:27pm UTC](https://discuss.elastic.co/t/alphabetic-sorting-strategies/14554/4 "2013-11-23T12:27:51Z")

</div>

The length of a sort key can be reduced by many methods, e.g. run length  
encoding, more details are available at the Unicode Collation algorithm  
[http://www.unicode.org/reports/tr10/#Reducing\_Sort\_Key\_Lengths](http://www.unicode.org/reports/tr10/#Reducing_Sort_Key_Lengths)

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:05am UTC](https://discuss.elastic.co/t/alphabetic-sorting-strategies/14554/5 "2017-07-06T02:05:09Z")

</div>


