# Sorting of numeric 'null' fields

**URL:** <https://discuss.elastic.co/t/sorting-of-numeric-null-fields/4082>\
**Category:** Elasticsearch\
**Created:** [March 11, 2011, 2:43pm UTC](https://discuss.elastic.co/t/sorting-of-numeric-null-fields/4082 "2011-03-11T14:43:09Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [March 11, 2011, 2:43pm UTC](https://discuss.elastic.co/t/sorting-of-numeric-null-fields/4082/1 "2011-03-11T14:43:09Z")

</div>

When sorting results by a numeric (integer) field I noticed that  
documents with missing values are sorted as if the value would be  
numeric 0. Is this intended behavior? I know that I can provide a  
default value to be indexed as part of the mapping definition.  
However, without such a mapping the default behavior is not to add the  
field at all (this is what the doc says and what I want). What I need  
from a business prospective is that documents with 'null' values for  
the sort field are always at the end of the sorted result (independent  
of sort order). I kind of remember this to be referred to as  
'sortMissingLast' in the Lucene / SOLR community.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 12, 2011, 8:05am UTC](https://discuss.elastic.co/t/sorting-of-numeric-null-fields/4082/2 "2011-03-12T08:05:47Z")

</div>

Yes, thats the current behavior. This can be added quite easily, care to open an issue for htis?  
On Friday, March 11, 2011 at 4:43 PM, Jan Fiedler wrote:

> When sorting results by a numeric (integer) field I noticed that  
> documents with missing values are sorted as if the value would be  
> numeric 0. Is this intended behavior? I know that I can provide a  
> default value to be indexed as part of the mapping definition.  
> However, without such a mapping the default behavior is not to add the  
> field at all (this is what the doc says and what I want). What I need  
> from a business prospective is that documents with 'null' values for  
> the sort field are always at the end of the sorted result (independent  
> of sort order). I kind of remember this to be referred to as  
> 'sortMissingLast' in the Lucene / SOLR community.

---

<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:** [March 12, 2011, 12:21pm UTC](https://discuss.elastic.co/t/sorting-of-numeric-null-fields/4082/3 "2011-03-12T12:21:54Z")

</div>

Filed enhancement request: [Sort: Support "missing" specific handling, include \_last, \_first, and custom value (for numeric values) · Issue #772 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/772)  
Looking forward to it ... 😉

On Mar 12, 9:05 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Yes, thats the current behavior. This can be added quite easily, care to open an issue for htis?
> 
> On Friday, March 11, 2011 at 4:43 PM, Jan Fiedler wrote:
> 
> > When sorting results by a numeric (integer) field I noticed that  
> > documents with missing values are sorted as if the value would be  
> > numeric 0. Is this intended behavior? I know that I can provide a  
> > default value to be indexed as part of the mapping definition.  
> > However, without such a mapping the default behavior is not to add the  
> > field at all (this is what the doc says and what I want). What I need  
> > from a business prospective is that documents with 'null' values for  
> > the sort field are always at the end of the sorted result (independent  
> > of sort order). I kind of remember this to be referred to as  
> > 'sortMissingLast' in the Lucene / SOLR community.

---

<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, 4:10am UTC](https://discuss.elastic.co/t/sorting-of-numeric-null-fields/4082/4 "2017-07-06T04:10:13Z")

</div>


