# Sorting String values in a manner similar to Number "missing" : "\_last"

**URL:** <https://discuss.elastic.co/t/sorting-string-values-in-a-manner-similar-to-number-missing--last/8610>\
**Category:** Elasticsearch\
**Created:** [August 2, 2012, 3:45pm UTC](https://discuss.elastic.co/t/sorting-string-values-in-a-manner-similar-to-number-missing--last/8610 "2012-08-02T15:45:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ABC](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@ABC](https://discuss.elastic.co/u/ABC)\
**Post date:** [August 2, 2012, 3:45pm UTC](https://discuss.elastic.co/t/sorting-string-values-in-a-manner-similar-to-number-missing--last/8610/1 "2012-08-02T15:45:58Z")

</div>

Hi,

The documentation states we can use "missing" : "\_last" for sorting  
Numbers. This is extremely useful.

Is there a similar mechanism for sorting on String values? (or am I missing  
something very obvious)

Any pointers would be very useful.

Thanks!

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 2, 2012, 4:54pm UTC](https://discuss.elastic.co/t/sorting-string-values-in-a-manner-similar-to-number-missing--last/8610/2 "2012-08-02T16:54:19Z")

</div>

If I'm correct if you try to missing option for a string field an  
error will be returned.  
Right now I can't think of an easy way to have this sorting behavior  
other then setting this the sort field  
with lexicographically high value during indexing. Which should result  
in the behavior you want.

I see that there is an issue open for this:

> <https://github.com/elastic/elasticsearch/issues/896>
>
> This is a follow up to #772 that supports special sorting for 'null' values for …numeric fields. The same would be very useful for (not analyzed) string fields as well. If feasible, special handling for empty and blank strings would be useful. The latter is however optional as it is possible to achieve uniform handling by filtering out blank values at indexing time.

Martijn

On 2 August 2012 17:45, ABC [satish.bhatia@gmail.com](mailto:satish.bhatia@gmail.com) wrote:

> Hi,
> 
> The documentation states we can use "missing" : "\_last" for sorting Numbers.  
> This is extremely useful.
> 
> Is there a similar mechanism for sorting on String values? (or am I missing  
> something very obvious)
> 
> Any pointers would be very useful.
> 
> Thanks!

--  
Met vriendelijke groet,

Martijn van Groningen

---

<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:17am UTC](https://discuss.elastic.co/t/sorting-string-values-in-a-manner-similar-to-number-missing--last/8610/3 "2017-07-06T03:17:58Z")

</div>


