Created
October 29, 2012 13:46
-
-
Save imotov/3973641 to your computer and use it in GitHub Desktop.
Sorting mixed integer/string field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XDELETE 'http://localhost:9200/test-idx' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx' -d ' | |
{ | |
"mappings": { | |
"doc": { | |
"properties" : { | |
"mixed" : {"type": "string", "store": "yes"} | |
} | |
} | |
} | |
}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/1' -d '{"mixed": "1"}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/2' -d '{"mixed": "2"}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/3' -d '{"mixed": "3"}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/4' -d '{"mixed": "10"}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/5' -d '{"mixed": "12"}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/6' -d '{"mixed": "test"}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/7' -d '{"mixed": "foo"}' | |
echo | |
curl -XPUT 'http://localhost:9200/test-idx/doc/8' -d '{"mixed": "bar"}' | |
echo | |
curl -XPOST 'http://localhost:9200/test-idx/_refresh' | |
echo | |
echo | |
curl -XGET 'http://localhost:9200/test-idx/doc/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"match_all": {} | |
}, | |
"sort": { | |
"_script":{ | |
"script" : "s = doc['\''mixed'\''].value; n = org.elasticsearch.common.primitives.Ints.tryParse(s); if (n != null) { String.format(\"%010d\",n)} else { s }", | |
"type" : "string" | |
} | |
} | |
}' | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@imotov
Can you provide a NEST example please