# Sorting on the first non-stop word in Elasticsearch

**URL:** <https://discuss.elastic.co/t/sorting-on-the-first-non-stop-word-in-elasticsearch/5377>\
**Category:** Elasticsearch\
**Created:** [September 13, 2011, 11:09pm UTC](https://discuss.elastic.co/t/sorting-on-the-first-non-stop-word-in-elasticsearch/5377 "2011-09-13T23:09:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottM\_2](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@ScottM\_2](https://discuss.elastic.co/u/ScottM_2)\
**Post date:** [September 13, 2011, 11:09pm UTC](https://discuss.elastic.co/t/sorting-on-the-first-non-stop-word-in-elasticsearch/5377/1 "2011-09-13T23:09:08Z")

</div>

Apologies if this has been asked before, but various searches didn't  
turn up an answer (that I was able to understand).

What I would like to be able to do is to have a document field that is  
that can be used to sort on the first non-stop word in the string. The  
use case is similar to having a list of musical artist names:

The Shins  
The Beatles  
Everything but the Girl  
Wilco

When sorted this list should be:

The Beatles  
Everything but the Girl  
The Shins  
Wilco

If I use an non-analyzed field the sorting will be:

Everything but the Girl  
The Beatles  
The Shins  
Wilco

If I use an analyzed field (default analyzer) then I can't sort on it.

Does that make sense? I can't find an analyzer in Elasticsearch that  
would allow me to do this.

---

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [September 14, 2011, 8:03am UTC](https://discuss.elastic.co/t/sorting-on-the-first-non-stop-word-in-elasticsearch/5377/2 "2011-09-14T08:03:29Z")

</div>

You need an analyzed field to get rid of the stop words (e.g. a whitespace  
tokenizer and a stop word filter). Sorting works on analyzed fields - you  
just have to make sure the analyzer generates a single token for your field.  
This is exactly the problem in your case - you will end up with multiple  
tokes after the stop word removal. I am not aware of a token filter that  
would let you merge tokens (after the stop word filter). You may get lucky  
with a token filter that creates collator keys (for locale specific sorting

- like the ICU plugin). However, I have not tested that (I only use it with  
a single token out of the keyword tokenizer) so please do not take my word  
for it.

---

<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:54am UTC](https://discuss.elastic.co/t/sorting-on-the-first-non-stop-word-in-elasticsearch/5377/3 "2017-07-06T03:54:25Z")

</div>


