# Sort on "long" type field

**URL:** <https://discuss.elastic.co/t/sort-on-long-type-field/5424>\
**Category:** Elasticsearch\
**Created:** [September 21, 2011, 7:04am UTC](https://discuss.elastic.co/t/sort-on-long-type-field/5424 "2011-09-21T07:04:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arien](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@arien](https://discuss.elastic.co/u/arien)\
**Post date:** [September 21, 2011, 7:04am UTC](https://discuss.elastic.co/t/sort-on-long-type-field/5424/1 "2011-09-21T07:04:35Z")

</div>

# Hi all; As per the tutorial provided in search api-sort(Elastic search guide),I am trying to sort results according to "Size" of the file field(long type). But as per my observation it works perfectly fine in String types fields. if i want to apply it to "Size" field i would be doing something like this as an example:

# { "sort" : { { "Size" : {"order" : "asc"} } }, "query" : { "term" : { "user" : "arien" } } }

But as mentioned in the guide at the end that if one wants to apply it to  
other than String type fields one must mention "type" explicitly

So i tried with following query say;

# =========================================== { "sort" : { { "Size" : {"order" : "asc" ,"type" : "long"} } }, "query" : { "term" : { "user" : "arien" } } }

With above too i m not getting sorted results in "Size",

Please guide me if i m doing something wrong in this for which i will be  
very grateful.  
Thanks

---

<div class="post-metadata">

**Author:** ![Kun\_Niu](https://avatars.discourse-cdn.com/v4/letter/k/8c91f0/32.png) [@Kun\_Niu](https://discuss.elastic.co/u/Kun_Niu)\
**Post date:** [September 21, 2011, 7:15am UTC](https://discuss.elastic.co/t/sort-on-long-type-field/5424/2 "2011-09-21T07:15:41Z")

</div>

I don't think this will work because the column is already analyzed.

You can search for not\_analyzed from this group.

You should specify the type in the column definition request instead of the search request.

From: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] On Behalf Of arien  
Sent: 2011年9月21日 15:05  
To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Subject: Sort on "long" type field

Hi all;

As per the tutorial provided in search api-sort(Elastic search guide),I am trying to sort results according to "Size" of the file field(long type).

But as per my observation it works perfectly fine in String types fields.

if i want to apply it to "Size" field i would be doing something like this as an example:

======================================

{ "sort" : { { "Size" : {"order" : "asc"} } }, "query" : { "term" : { "user" : "arien" } } }

===========================================

But as mentioned in the guide at the end that if one wants to apply it to other than String type fields one must mention "type" explicitly

So i tried with following query say;

===========================================

{ "sort" : { { "Size" : {"order" : "asc" ,"type" : "long"} } }, "query" : { "term" : { "user" : "arien" } } }

===========================================

With above too i m not getting sorted results in "Size",

Please guide me if i m doing something wrong in this for which i will be very grateful.

Thanks

---

<div class="post-metadata">

**Author:** ![arien](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@arien](https://discuss.elastic.co/u/arien)\
**Post date:** [September 22, 2011, 4:57am UTC](https://discuss.elastic.co/t/sort-on-long-type-field/5424/3 "2011-09-22T04:57:55Z")

</div>

hi;  
The type of the mapping i am creating for "Size" column is shown in  
following sample.

"Size" : {  
"type" : "long",  
"fields" : {  
"Size" : { "term\_vector":"with\_positions\_offsets", "store":"yes" }  
}  
},

can u elaborate more on what u wanted to explain on already analyzed and  
not-analyzed because i m not using any custom analysers anywhere and may be  
all fields are having default analyzers applicable.

Thanks

On Wed, Sep 21, 2011 at 12:45 PM, Kun Niu [haoniukun@gmail.com](mailto:haoniukun@gmail.com) wrote:

> I don't think this will work because the column is already analyzed.\*\*\*\*
> 
> You can search for not\_analyzed from this group.\*\*\*\*
> 
> You should specify the type in the column definition request instead of the  
> search request.\*\*\*\*
> 
> * * *
> 
> _From:_ [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) [mailto:  
> [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] _On Behalf Of arien  
> Sent: 2011年9月21日 15:05  
> To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> Subject: Sort on "long" type field_\*\*
> 
> * * *
> 
> Hi all;\*\*\*\*
> 
> As per the tutorial provided in search api-sort(Elastic search guide),I am  
> trying to sort results according to "Size" of the file field(long type).\*\*  
> \*\*
> 
> But as per my observation it works perfectly fine in String types fields.\*
> 
> * * *
> 
> if i want to apply it to "Size" field i would be doing something like this  
> as an example:\*\*\*\*
> 
> ======================================\*\*\*\*
> 
> * * *
> 
> { "sort" : { { "Size" : {"order" : "asc"} } }, "query" : { "term" : {  
> "user" : "arien" } } }\*\*\*\*
> 
> ===========================================\*\*\*\*
> 
> * * *
> 
> * * *
> 
> But as mentioned in the guide at the end that if one wants to apply it to  
> other than String type fields one must mention "type" explicitly\*\*\*\*
> 
> * * *
> 
> So i tried with following query say;\*\*\*\*
> 
> * * *
> 
> * * *
> 
> ===========================================\*\*\*\*
> 
> { "sort" : { { "Size" : {"order" : "asc" ,"type" : "long"} } }, "query" :  
> { "term" : { "user" : "arien" } } }\*\*\*\*
> 
> ===========================================\*\*\*\*
> 
> * * *
> 
> * * *
> 
> * * *
> 
> With above too i m not getting sorted results in "Size",\*\*\*\*
> 
> * * *
> 
> Please guide me if i m doing something wrong in this for which i will be  
> very grateful.\*\*\*\*
> 
> Thanks\*\*\*\*

---

<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:** [September 22, 2011, 11:00am UTC](https://discuss.elastic.co/t/sort-on-long-type-field/5424/4 "2011-09-22T11:00:55Z")

</div>

You can easily sort on fields with mapping of type long (analyzed or  
not\_analyzed are not relevant for numeric types, just if its indexed or  
not), it works. Does the Size field really is of type long? You can use the  
get mapping API to check.

On Thu, Sep 22, 2011 at 7:57 AM, ajay padvi [ajaypadvi@gmail.com](mailto:ajaypadvi@gmail.com) wrote:

> hi;  
> The type of the mapping i am creating for "Size" column is shown in  
> following sample.
> 
> "Size" : {  
> "type" : "long",  
> "fields" : {  
> "Size" : { "term\_vector":"with\_positions\_offsets", "store":"yes" }  
> }  
> },
> 
> can u elaborate more on what u wanted to explain on already analyzed and  
> not-analyzed because i m not using any custom analysers anywhere and may be  
> all fields are having default analyzers applicable.
> 
> Thanks
> 
> On Wed, Sep 21, 2011 at 12:45 PM, Kun Niu [haoniukun@gmail.com](mailto:haoniukun@gmail.com) wrote:
> 
> > I don't think this will work because the column is already analyzed.\*\*\*\*
> > 
> > You can search for not\_analyzed from this group.\*\*\*\*
> > 
> > You should specify the type in the column definition request instead of  
> > the search request.\*\*\*\*
> > 
> > * * *
> > 
> > _From:_ [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) [mailto:  
> > [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] _On Behalf Of arien  
> > Sent: 2011年9月21日 15:05  
> > To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > Subject: Sort on "long" type field_\*\*
> > 
> > * * *
> > 
> > Hi all;\*\*\*\*
> > 
> > As per the tutorial provided in search api-sort(Elastic search guide),I am  
> > trying to sort results according to "Size" of the file field(long type).\*
> > 
> > * * *
> > 
> > But as per my observation it works perfectly fine in String types fields.
> > 
> > * * *
> > 
> > if i want to apply it to "Size" field i would be doing something like this  
> > as an example:\*\*\*\*
> > 
> > ======================================\*\*\*\*
> > 
> > * * *
> > 
> > { "sort" : { { "Size" : {"order" : "asc"} } }, "query" : { "term" : {  
> > "user" : "arien" } } }\*\*\*\*
> > 
> > ===========================================\*\*\*\*
> > 
> > * * *
> > 
> > * * *
> > 
> > But as mentioned in the guide at the end that if one wants to apply it to  
> > other than String type fields one must mention "type" explicitly\*\*\*\*
> > 
> > * * *
> > 
> > So i tried with following query say;\*\*\*\*
> > 
> > * * *
> > 
> > * * *
> > 
> > ===========================================\*\*\*\*
> > 
> > { "sort" : { { "Size" : {"order" : "asc" ,"type" : "long"} } }, "query" :  
> > { "term" : { "user" : "arien" } } }\*\*\*\*
> > 
> > ===========================================\*\*\*\*
> > 
> > * * *
> > 
> > * * *
> > 
> > * * *
> > 
> > With above too i m not getting sorted results in "Size",\*\*\*\*
> > 
> > * * *
> > 
> > Please guide me if i m doing something wrong in this for which i will be  
> > very grateful.\*\*\*\*
> > 
> > Thanks\*\*\*\*

---

<div class="post-metadata">

**Author:** ![Kun\_Niu](https://avatars.discourse-cdn.com/v4/letter/k/8c91f0/32.png) [@Kun\_Niu](https://discuss.elastic.co/u/Kun_Niu)\
**Post date:** [September 22, 2011, 10:13pm UTC](https://discuss.elastic.co/t/sort-on-long-type-field/5424/5 "2011-09-22T22:13:11Z")

</div>

Yes. If you set type to long, it should work. You should verify the  
setting of the column.  
How did you set the type of the column, using a configuration file or  
using your program?

On Thu, Sep 22, 2011 at 4:00 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> You can easily sort on fields with mapping of type long (analyzed or  
> not\_analyzed are not relevant for numeric types, just if its indexed or  
> not), it works. Does the Size field really is of type long? You can use the  
> get mapping API to check.
> 
> On Thu, Sep 22, 2011 at 7:57 AM, ajay padvi [ajaypadvi@gmail.com](mailto:ajaypadvi@gmail.com) wrote:
> 
> > hi;  
> > The type of the mapping i am creating for "Size" column is shown in  
> > following sample.
> > 
> > "Size" : {  
> > "type" : "long",  
> > "fields" : {  
> > "Size" : { "term\_vector":"with\_positions\_offsets", "store":"yes" }  
> > }  
> > },
> > 
> > can u elaborate more on what u wanted to explain on already analyzed and  
> > not-analyzed because i m not using any custom analysers anywhere and may be  
> > all fields are having default analyzers applicable.  
> > Thanks
> > 
> > On Wed, Sep 21, 2011 at 12:45 PM, Kun Niu [haoniukun@gmail.com](mailto:haoniukun@gmail.com) wrote:
> > 
> > > I don't think this will work because the column is already analyzed.
> > > 
> > > You can search for not\_analyzed from this group.
> > > 
> > > You should specify the type in the column definition request instead of  
> > > the search request.
> > > 
> > > From: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > > [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] On Behalf Of arien  
> > > Sent: 2011年9月21日 15:05  
> > > To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > > Subject: Sort on "long" type field
> > > 
> > > Hi all;
> > > 
> > > As per the tutorial provided in search api-sort(Elastic search guide),I  
> > > am trying to sort results according to "Size" of the file field(long type).
> > > 
> > > But as per my observation it works perfectly fine in String types fields.
> > > 
> > > if i want to apply it to "Size" field i would be doing something like  
> > > this as an example:
> > > 
> > > ======================================
> > > 
> > > { "sort" : { { "Size" : {"order" : "asc"} } }, "query" : { "term" : {  
> > > "user" : "arien" } } }
> > > 
> > > ===========================================
> > > 
> > > But as mentioned in the guide at the end that if one wants to apply it to  
> > > other than String type fields one must mention "type" explicitly
> > > 
> > > So i tried with following query say;
> > > 
> > > ===========================================
> > > 
> > > { "sort" : { { "Size" : {"order" : "asc" ,"type" : "long"} } }, "query"  
> > > : { "term" : { "user" : "arien" } } }
> > > 
> > > ===========================================
> > > 
> > > With above too i m not getting sorted results in "Size",
> > > 
> > > Please guide me if i m doing something wrong in this for which i will be  
> > > very grateful.
> > > 
> > > Thanks

--  
牛坤  
[MSN:haoniukun@hotmail.com](mailto:MSN:haoniukun@hotmail.com)

---

<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:53am UTC](https://discuss.elastic.co/t/sort-on-long-type-field/5424/6 "2017-07-06T03:53:44Z")

</div>


