Sorting for IDs query or filter using the ID's list

Hi there,

I want to query ES with a specific list of document ID's (
http://www.elasticsearch.org/guide/reference/query-dsl/ids-query/),
but the results are sorted in a strange way - they all have a score of 1
but they are not ordered with my ids order.

I can't use mget for this, I want to use Facets, pagination & all the ES
power.

The only method I see to sort my results against the ID list is to use some
sort of custom score script...
But I hope someone here can push me a better idea! :slight_smile:

Here is a gif to thank you for your help:

http://i.imgur.com/uCmIF.gif

Cheers from France,
Damien.

--
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.

Hey Damien,

Can't you sort using _id field?

Something like:

{
"sort" : [
{ "_id" : {"order" : "asc"} }
],
"query" : {
"ids" : {
"type" : "my_type",
"values" : ["1", "4", "100"]
}
}
}

Does it help?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 3 juin 2013 à 16:55, Damien Alexandre dalexandre@jolicode.com a écrit :

Hi there,

I want to query ES with a specific list of document ID's (http://www.elasticsearch.org/guide/reference/query-dsl/ids-query/),
but the results are sorted in a strange way - they all have a score of 1 but they are not ordered with my ids order.

I can't use mget for this, I want to use Facets, pagination & all the ES power.

The only method I see to sort my results against the ID list is to use some sort of custom score script...
But I hope someone here can push me a better idea! :slight_smile:

Here is a gif to thank you for your help:

Cheers from France,
Damien.

--
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 wish I could,
but the list of ID's I want to fetch is not in a natural order,
my users want ids 1, 7, 12, 3... in that specific order. And I have plenty
of those ids list to deal with, so I can't add a custom field for sort to
the documents.

Thx!
Damien

On 3 June 2013 17:40, David Pilato david@pilato.fr wrote:

Hey Damien,

Can't you sort using _id field?

Something like:

{
"sort" : [
{ "_id" : {"order" : "asc"} }
],
"query" : {
"ids" : {
"type" : "my_type",
"values" : ["1", "4", "100"]
}
}
}

Does it help?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 3 juin 2013 à 16:55, Damien Alexandre dalexandre@jolicode.com a
écrit :

Hi there,

I want to query ES with a specific list of document ID's (
http://www.elasticsearch.org/guide/reference/query-dsl/ids-query/),
but the results are sorted in a strange way - they all have a score of 1
but they are not ordered with my ids order.

I can't use mget for this, I want to use Facets, pagination & all the ES
power.

The only method I see to sort my results against the ID list is to use
some sort of custom score script...
But I hope someone here can push me a better idea! :slight_smile:

Here is a gif to thank you for your help:

http://i.imgur.com/uCmIF.gif

Cheers from France,
Damien.

--
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.

FYI, I got it done with a CustomScript (as recommanded by NarinderKaur
Makkar).

I use org.elasticsearch.index.mapper.Uid.idFromUid(doc['_uid'].value); to
get the document ID - not sure this is the best way?

Full source here:
http://damienalexandre.fr/post/elasticsearch-ids-query-order

Thx !

On 3 June 2013 17:51, Damien Alexandre dalexandre@jolicode.com wrote:

I wish I could,
but the list of ID's I want to fetch is not in a natural order,
my users want ids 1, 7, 12, 3... in that specific order. And I have plenty
of those ids list to deal with, so I can't add a custom field for sort to
the documents.

Thx!
Damien

On 3 June 2013 17:40, David Pilato david@pilato.fr wrote:

Hey Damien,

Can't you sort using _id field?

Something like:

{
"sort" : [
{ "_id" : {"order" : "asc"} }
],
"query" : {
"ids" : {
"type" : "my_type",
"values" : ["1", "4", "100"]
}
}
}

Does it help?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 3 juin 2013 à 16:55, Damien Alexandre dalexandre@jolicode.com a
écrit :

Hi there,

I want to query ES with a specific list of document ID's (
http://www.elasticsearch.org/guide/reference/query-dsl/ids-query/),
but the results are sorted in a strange way - they all have a score of 1
but they are not ordered with my ids order.

I can't use mget for this, I want to use Facets, pagination & all the ES
power.

The only method I see to sort my results against the ID list is to use
some sort of custom score script...
But I hope someone here can push me a better idea! :slight_smile:

Here is a gif to thank you for your help:

http://i.imgur.com/uCmIF.gif

Cheers from France,
Damien.

--
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.