# Sorting problem for just plain integer

**URL:** <https://discuss.elastic.co/t/sorting-problem-for-just-plain-integer/6316>\
**Category:** Elasticsearch\
**Created:** [January 9, 2012, 1:19am UTC](https://discuss.elastic.co/t/sorting-problem-for-just-plain-integer/6316 "2012-01-09T01:19:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tuner/32/3023_2.png) [@tuner](https://discuss.elastic.co/u/tuner)\
**Post date:** [January 9, 2012, 1:19am UTC](https://discuss.elastic.co/t/sorting-problem-for-just-plain-integer/6316/1 "2012-01-09T01:19:38Z")

</div>

I'm trying to sort:  
{  
"query": {  
"match\_all": {}  
},  
"sort": [  
{  
"data\_publikacji": "desc"  
}  
]  
}

And I'm getting for all documents, responses (see: sort) like this:  
{  
\_index: warehouse  
\_type: uzp\_fast  
\_id: 6995  
\_score: null  
\_source: {  
data\_publikacji: 1221177600  
nazwa\_zamowienia: Dostawa sprzętu endoskopowego do 109 Szpitala  
Wojskowego z Przychodnią SP ZOZ w Szczecinie.  
nazwa: 109 Szpital Wojskowy z Przychodnią SP ZOZ  
miejscowosc: Szczecin  
wojewodztwo: zachodniopomorskie  
\_pk: 6995  
\_insertDateTime: 1326069131  
\_insertUsec: 849  
}  
sort: [  
T  
]  
}

Sorting then dosen't work. It works for some values but for some - it  
don't.

---

<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:** [January 9, 2012, 9:26am UTC](https://discuss.elastic.co/t/sorting-problem-for-just-plain-integer/6316/2 "2012-01-09T09:26:44Z")

</div>

Check in the mapping (use get mapping) that the type of the field  
data\_publikacji  
is really numeric.

2012/1/9 Tuner [turneliusz@gmail.com](mailto:turneliusz@gmail.com)

> I'm trying to sort:  
> {  
> "query": {  
> "match\_all": {}  
> },  
> "sort": [  
> {  
> "data\_publikacji": "desc"  
> }  
> ]  
> }
> 
> And I'm getting for all documents, responses (see: sort) like this:  
> {  
> \_index: warehouse  
> \_type: uzp\_fast  
> \_id: 6995  
> \_score: null  
> \_source: {  
> data\_publikacji: 1221177600  
> nazwa\_zamowienia: Dostawa sprzętu endoskopowego do 109 Szpitala  
> Wojskowego z Przychodnią SP ZOZ w Szczecinie.  
> nazwa: 109 Szpital Wojskowy z Przychodnią SP ZOZ  
> miejscowosc: Szczecin  
> wojewodztwo: zachodniopomorskie  
> \_pk: 6995  
> \_insertDateTime: 1326069131  
> \_insertUsec: 849  
> }  
> sort: [  
> T  
> ]  
> }
> 
> Sorting then dosen't work. It works for some values but for some - it  
> don't.

---

<div class="post-metadata">

**Author:** ![tuner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tuner/32/3023_2.png) [@tuner](https://discuss.elastic.co/u/tuner)\
**Post date:** [January 9, 2012, 10:28pm UTC](https://discuss.elastic.co/t/sorting-problem-for-just-plain-integer/6316/3 "2012-01-09T22:28:50Z")

</div>

Yeah, you are right, "data\_publikacji" is boolean but why?

Source:  
uzp\_fast: {  
properties: {  
wojewodztwo: {  
type: string  
}  
\_pk: {  
type: long  
}  
\_insertDateTime: {  
type: long  
}  
miejscowosc: {  
type: string  
}  
\_insertUsec: {  
type: long  
}  
nazwa\_zamowienia: {  
type: string  
}  
nazwa: {  
type: string  
}  
data\_publikacji: {  
type: boolean  
}  
$id: {  
type: string  
}  
}  
}  
}

On Jan 9, 10:26 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Check in the mapping (use get mapping) that the type of the field  
> data\_publikacji  
> is really numeric.
> 
> 2012/1/9 Tuner [turneli...@gmail.com](mailto:turneli...@gmail.com)
> 
> > I'm trying to sort:  
> > {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "sort": [  
> > {  
> > "data\_publikacji": "desc"  
> > }  
> > ]  
> > }
> 
> > And I'm getting for all documents, responses (see: sort) like this:  
> > {  
> > \_index: warehouse  
> > \_type: uzp\_fast  
> > \_id: 6995  
> > \_score: null  
> > \_source: {  
> > data\_publikacji: 1221177600  
> > nazwa\_zamowienia: Dostawa sprzętu endoskopowego do 109 Szpitala  
> > Wojskowego z Przychodnią SP ZOZ w Szczecinie.  
> > nazwa: 109 Szpital Wojskowy z Przychodnią SP ZOZ  
> > miejscowosc: Szczecin  
> > wojewodztwo: zachodniopomorskie  
> > \_pk: 6995  
> > \_insertDateTime: 1326069131  
> > \_insertUsec: 849  
> > }  
> > sort: [  
> > T  
> > ]  
> > }
> 
> > Sorting then dosen't work. It works for some values but for some - it  
> > don't.

---

<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:** [January 10, 2012, 8:52am UTC](https://discuss.elastic.co/t/sorting-problem-for-just-plain-integer/6316/4 "2012-01-10T08:52:39Z")

</div>

Because the first value you indexed into it was a boolean, and thats the  
type that was used for it.

2012/1/10 Tuner [turneliusz@gmail.com](mailto:turneliusz@gmail.com)

> Yeah, you are right, "data\_publikacji" is boolean but why?
> 
> Source:  
> uzp\_fast: {  
> properties: {  
> wojewodztwo: {  
> type: string  
> }  
> \_pk: {  
> type: long  
> }  
> \_insertDateTime: {  
> type: long  
> }  
> miejscowosc: {  
> type: string  
> }  
> \_insertUsec: {  
> type: long  
> }  
> nazwa\_zamowienia: {  
> type: string  
> }  
> nazwa: {  
> type: string  
> }  
> data\_publikacji: {  
> type: boolean  
> }  
> $id: {  
> type: string  
> }  
> }  
> }  
> }
> 
> On Jan 9, 10:26 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Check in the mapping (use get mapping) that the type of the field  
> > data\_publikacji  
> > is really numeric.
> > 
> > 2012/1/9 Tuner [turneli...@gmail.com](mailto:turneli...@gmail.com)
> > 
> > > I'm trying to sort:  
> > > {  
> > > "query": {  
> > > "match\_all": {}  
> > > },  
> > > "sort": [  
> > > {  
> > > "data\_publikacji": "desc"  
> > > }  
> > > ]  
> > > }
> > 
> > > And I'm getting for all documents, responses (see: sort) like this:  
> > > {  
> > > \_index: warehouse  
> > > \_type: uzp\_fast  
> > > \_id: 6995  
> > > \_score: null  
> > > \_source: {  
> > > data\_publikacji: 1221177600  
> > > nazwa\_zamowienia: Dostawa sprzętu endoskopowego do 109 Szpitala  
> > > Wojskowego z Przychodnią SP ZOZ w Szczecinie.  
> > > nazwa: 109 Szpital Wojskowy z Przychodnią SP ZOZ  
> > > miejscowosc: Szczecin  
> > > wojewodztwo: zachodniopomorskie  
> > > \_pk: 6995  
> > > \_insertDateTime: 1326069131  
> > > \_insertUsec: 849  
> > > }  
> > > sort: [  
> > > T  
> > > ]  
> > > }
> > 
> > > Sorting then dosen't work. It works for some values but for some - it  
> > > don't.

---

<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:43am UTC](https://discuss.elastic.co/t/sorting-problem-for-just-plain-integer/6316/5 "2017-07-06T03:43:17Z")

</div>


