Hi guys. When sorting on a field that's a string, strings that contain
numbers aren't sorted properly.
For example, with these documents:
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
When ES sorts on the "name" field, the documents are returned in this order:
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
How can we get ES to return the documents in the following order?
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
Hi guys. When sorting on a field that's a string, strings that contain numbers aren't sorted properly.
For example, with these documents:
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
When ES sorts on the "name" field, the documents are returned in this order:
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
How can we get ES to return the documents in the following order?
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
Hi David. Prefixing numbers with zeros won't work because that assumes that
there's a constant number of digits in the number.
On Sunday, 28 October 2012 15:01:37 UTC-4, David Pilato wrote:
IMHO you should index docs with 02 instead of 2.
--
David
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
Le 28 oct. 2012 à 17:48, Nick Hoffman <ni...@deadorange.com <javascript:>>
a écrit :
Hi guys. When sorting on a field that's a string, strings that contain
numbers aren't sorted properly.
For example, with these documents:
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
When ES sorts on the "name" field, the documents are returned in this
order:
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
How can we get ES to return the documents in the following order?
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
Hi guys. When sorting on a field that's a string, strings that contain
numbers aren't sorted properly.
For example, with these documents:
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
When ES sorts on the "name" field, the documents are returned in this
order:
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
How can we get ES to return the documents in the following order?
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
Could you split the data into multiple fields? So have a name field "Bob,
Anne, etc" which is a string and a points field "3, 10, 2" which is a
number. Then sort both fields together, name coming first?
On Monday, October 29, 2012 5:48:12 AM UTC+13, Nick Hoffman wrote:
Hi guys. When sorting on a field that's a string, strings that contain
numbers aren't sorted properly.
For example, with these documents:
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
When ES sorts on the "name" field, the documents are returned in this
order:
{ name: "Bob: 10 points" }
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
How can we get ES to return the documents in the following order?
{ name: "Bob: 2 points" }
{ name: "Bob: 3 points" }
{ name: "Bob: 10 points" }
I'd definitely do that if I could, Chris. The strings that I'm indexing are
names of objects that can't be split, unfortunately. E.g.
Megatron (UN-04)
The Amazing Spider-Man #44
G2 Optimus Prime
This is why the sorting has to happen within ES.
On Sunday, 28 October 2012 22:40:02 UTC-4, Chris Male wrote:
Could you split the data into multiple fields? So have a name field "Bob,
Anne, etc" which is a string and a points field "3, 10, 2" which is a
number. Then sort both fields together, name coming first?
thanks for your inspiration. It's a great idea. I just hacked together a
plugin that can perform the desired sort by using a natural sort key in a
Lucene token filter.
As a bonus, a collator key sort is included (since the natural sort key
extends the collator key, you have to add a "locale" parameter to the token
filter if you want locale-sensitive sort)
Cheers,
Jörg
On Monday, October 29, 2012 3:54:01 AM UTC+1, Nick Hoffman wrote:
I'd definitely do that if I could, Chris. The strings that I'm indexing
are names of objects that can't be split, unfortunately. E.g.
Megatron (UN-04)
The Amazing Spider-Man #44
G2 Optimus Prime
This is why the sorting has to happen within ES.
On Sunday, 28 October 2012 22:40:02 UTC-4, Chris Male wrote:
Could you split the data into multiple fields? So have a name field "Bob,
Anne, etc" which is a string and a points field "3, 10, 2" which is a
number. Then sort both fields together, name coming first?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.