Sorting a string field numerically

Hi Radu. That's an interesting idea. How would you score fields that aren't
numeric, though?

On Monday, 29 October 2012 05:49:37 UTC-4, Radu Gheorghe wrote:

Hello,

You can use the _source field, if you got it stored, in a script
within a custom_score query. For example, assuming "foo" is the name
of our field:

curl -XPOST localhost:9200/test/test/_search?pretty=true -d '{
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "if (_source.foo is Integer) { _source.foo }
else { _score/5 }"
}
}
}'

This will get your numeric values sorted as numbers. You'd need to
fill out the "else" part of the script with whatever values you want
to give to your non-numeric fields.

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Sun, Oct 28, 2012 at 9:10 PM, Nick Hoffman <ni...@deadorange.com<javascript:>>
wrote:

Hah, I asked the exact same question:
Redirecting to Google Groups

On Sunday, 28 October 2012 14:45:25 UTC-4, James Hu wrote:

I have a field that is string type. Sometimes it will contain integer
values such as 1, 2, 10, 20. Currently how it sorts those is 1, 10, 2,

How do I go aboutsorting that numerically so that it's 1, 2, 10, 20?

--

--