Skip to content

Instantly share code, notes, and snippets.

@imotov
Created October 29, 2012 13:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imotov/3973641 to your computer and use it in GitHub Desktop.
Save imotov/3973641 to your computer and use it in GitHub Desktop.
Sorting mixed integer/string field
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
@chugh97
Copy link

chugh97 commented Nov 4, 2016

@imotov
Can you provide a NEST example please

@chugh97
Copy link

chugh97 commented Nov 4, 2016

@imotov
Can you provide a NEST example please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment