Sorting by _uid

Hello all,

When sorting by ES's internal ID (_uid), I've noticed that the uid field is
not treated/sorted as numeric, even though ES assigns it a numeric value.
Is this by design?

Example: (Note that "2" comes after "144")

{"query":{"filtered":{"query":{"query_string":{"query":"captain"}}}},"from":
0,"size":50,"sort":{"_uid":{"order":"asc"}}}:

output:

5: {
_index: "comicbook"
_type: "superhero"
_id: "144"
_score: null
_source: {
name: "Bart Allen"
}-
sort: [1]
0: "superhero#144"

}-
6: {
_index: "comicbook"
_type: "superhero"
_id: "2"
_score: null
_source: {
name: "Spider-Man"
}-
sort: [1]
0: "superhero#2"

}-
7: {
_index: "comicbook"
_type: "superhero"
_id: "20"
_score: null
_source: {
name: "Captain Marvel"

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I am not positive, but I don't believe the _uid is indexed by default (_id
is not) and therefore you will not be able to sort on it.

--
Ivan

On Fri, Jul 26, 2013 at 8:09 AM, Roy Russo royrusso@gmail.com wrote:

Hello all,

When sorting by ES's internal ID (_uid), I've noticed that the uid field
is not treated/sorted as numeric, even though ES assigns it a numeric
value. Is this by design?

Example: (Note that "2" comes after "144")

{"query":{"filtered":{"query":{"query_string":{"query":"captain"}}}},
"from":0,"size":50,"sort":{"_uid":{"order":"asc"}}}:

output:

5: {
_index: "comicbook"
_type: "superhero"
_id: "144"
_score: null
_source: {
name: "Bart Allen"
}-
sort: [1]
0: "superhero#144"

}-
6: {
_index: "comicbook"
_type: "superhero"
_id: "2"
_score: null
_source: {
name: "Spider-Man"
}-
sort: [1]
0: "superhero#2"

}-
7: {
_index: "comicbook"
_type: "superhero"
_id: "20"
_score: null
_source: {
name: "Captain Marvel"

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

The _uid fieldhttp://www.elasticsearch.org/guide/reference/mapping/uid-field/is indexed by default, while the _id
field http://www.elasticsearch.org/guide/reference/mapping/id-field/isn't.

The _uid field contains both the _type and the _id field. Since both of
those fields aren't necessarily numeric, _uid is not numeric either. That's
why numbers are not sorted properly. Also, if you sort on the _uid field
when querying multiple types, then all the documents that belong to one of
the types will be listed, then the other type...and so on.

I would define a specific field for sorting, with proper mapping so that
it's indexed and treated as a number.

Cheers
Luca

On Friday, July 26, 2013 11:34:37 PM UTC+2, Ivan Brusic wrote:

I am not positive, but I don't believe the _uid is indexed by default (_id
is not) and therefore you will not be able to sort on it.

--
Ivan

On Fri, Jul 26, 2013 at 8:09 AM, Roy Russo <royr...@gmail.com<javascript:>

wrote:

Hello all,

When sorting by ES's internal ID (_uid), I've noticed that the uid field
is not treated/sorted as numeric, even though ES assigns it a numeric
value. Is this by design?

Example: (Note that "2" comes after "144")

{"query":{"filtered":{"query":{"query_string":{"query":"captain"}}}},
"from":0,"size":50,"sort":{"_uid":{"order":"asc"}}}:

output:

5: {
_index: "comicbook"
_type: "superhero"
_id: "144"
_score: null
_source: {
name: "Bart Allen"
}-
sort: [1]
0: "superhero#144"

}-
6: {
_index: "comicbook"
_type: "superhero"
_id: "2"
_score: null
_source: {
name: "Spider-Man"
}-
sort: [1]
0: "superhero#2"

}-
7: {
_index: "comicbook"
_type: "superhero"
_id: "20"
_score: null
_source: {
name: "Captain Marvel"

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks Luca! This jives with what I read in another post... the _type + _id
= _uid

On Saturday, July 27, 2013 6:22:04 AM UTC-4, Luca Cavanna wrote:

The _uid fieldhttp://www.elasticsearch.org/guide/reference/mapping/uid-field/is indexed by default, while the _id
field http://www.elasticsearch.org/guide/reference/mapping/id-field/isn't.

The _uid field contains both the _type and the _id field. Since both of
those fields aren't necessarily numeric, _uid is not numeric either. That's
why numbers are not sorted properly. Also, if you sort on the _uid field
when querying multiple types, then all the documents that belong to one of
the types will be listed, then the other type...and so on.

I would define a specific field for sorting, with proper mapping so that
it's indexed and treated as a number.

Cheers
Luca

On Friday, July 26, 2013 11:34:37 PM UTC+2, Ivan Brusic wrote:

I am not positive, but I don't believe the _uid is indexed by default
(_id is not) and therefore you will not be able to sort on it.

--
Ivan

On Fri, Jul 26, 2013 at 8:09 AM, Roy Russo royr...@gmail.com wrote:

Hello all,

When sorting by ES's internal ID (_uid), I've noticed that the uid field
is not treated/sorted as numeric, even though ES assigns it a numeric
value. Is this by design?

Example: (Note that "2" comes after "144")

{"query":{"filtered":{"query":{"query_string":{"query":"captain"}}}},
"from":0,"size":50,"sort":{"_uid":{"order":"asc"}}}:

output:

5: {
_index: "comicbook"
_type: "superhero"
_id: "144"
_score: null
_source: {
name: "Bart Allen"
}-
sort: [1]
0: "superhero#144"

}-
6: {
_index: "comicbook"
_type: "superhero"
_id: "2"
_score: null
_source: {
name: "Spider-Man"
}-
sort: [1]
0: "superhero#2"

}-
7: {
_index: "comicbook"
_type: "superhero"
_id: "20"
_score: null
_source: {
name: "Captain Marvel"

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.