# Sorting issue with space

**URL:** <https://discuss.elastic.co/t/sorting-issue-with-space/106461>\
**Category:** Elasticsearch\
**Created:** [November 6, 2017, 5:13am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461 "2017-11-06T05:13:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aneesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aneesh/32/37819_2.png) [@aneesh](https://discuss.elastic.co/u/aneesh)\
**Post date:** [November 6, 2017, 5:13am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/1 "2017-11-06T05:13:13Z")

</div>

After Sort I am getting result like this

Adfgsdh  
Bhdfaf  
Dbsdf  
Z Edfghf  
Mkjldfhd  
Zdhgj

Word **Z Edfghf** came on wrong place. When I removed space it came on proper place

ElasticsearchResponse objElasticResponse = objClient.Search(strIndex, strType, @"  
{  
""from"": 0,  
""size"": 10000,  
""sort"" :[  
{ ""Name"": { ""order"" : ""asc"" , ""missing"" : ""\_last"" , ""unmapped\_type"" : ""long""} }  
],  
""query"": {  
""bool"": {  
""must"": [  
],  
""should"":[  
]  
}  
}  
}");

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 6, 2017, 5:34am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/2 "2017-11-06T05:34:10Z")

</div>

What's the mapping on the field?

---

<div class="post-metadata">

**Author:** ![aneesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aneesh/32/37819_2.png) [@aneesh](https://discuss.elastic.co/u/aneesh)\
**Post date:** [November 6, 2017, 6:06am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/3 "2017-11-06T06:06:17Z")

</div>

"Name" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
},  
"fielddata" : true  
}

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 6, 2017, 9:33pm UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/4 "2017-11-06T21:33:35Z")

</div>

Use the `Name.keyword` field and you should be ok.

---

<div class="post-metadata">

**Author:** ![aneesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aneesh/32/37819_2.png) [@aneesh](https://discuss.elastic.co/u/aneesh)\
**Post date:** [November 7, 2017, 4:39am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/5 "2017-11-07T04:39:53Z")

</div>

ElasticsearchResponse objElasticResponse = objClient.Search(strIndex, strType, @"  
{  
""from"": 0,  
""size"": 10000,  
""sort"" :[  
{ ""Name.keyword"": { ""order"" : ""asc"" , ""missing"" : ""\_last"" , ""unmapped\_type"" : ""long""} }  
],  
""query"": {  
""bool"": {  
""must"": [  
],  
""should"":[  
]  
}  
}  
}");

Query like this

---

<div class="post-metadata">

**Author:** ![aneesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aneesh/32/37819_2.png) [@aneesh](https://discuss.elastic.co/u/aneesh)\
**Post date:** [November 10, 2017, 9:45am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/6 "2017-11-10T09:45:12Z")

</div>

Hi.

Sorting is still not coming as expected

AbcEdf  
Abc Zgdfg

if sort above, Second word is coming first because of that space

---

<div class="post-metadata">

**Author:** ![aneesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aneesh/32/37819_2.png) [@aneesh](https://discuss.elastic.co/u/aneesh)\
**Post date:** [November 10, 2017, 9:45am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/7 "2017-11-10T09:45:35Z")

</div>

Hi.

Sorting is still not coming as expected

AbcEdf  
Abc Zgdfg

if sort above, Second word is coming first because of that space

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 10, 2017, 11:01am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/8 "2017-11-10T11:01:05Z")

</div>

That is as far as I can see the correct and expected [ASCII sorting order](http://www.asciitable.com). I am not sure if it is possible to override this.

---

<div class="post-metadata">

**Author:** ![aneesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aneesh/32/37819_2.png) [@aneesh](https://discuss.elastic.co/u/aneesh)\
**Post date:** [November 13, 2017, 3:34am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/9 "2017-11-13T03:34:18Z")

</div>

Ok. Anyway Thanks Christian\_Dahlqvist.

---

<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:** [December 11, 2017, 3:34am UTC](https://discuss.elastic.co/t/sorting-issue-with-space/106461/10 "2017-12-11T03:34:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
