Skip to content

Instantly share code, notes, and snippets.

@imotov imotov/gist:3973641
Created Oct 29, 2012

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

chugh97 commented Nov 4, 2016

@imotov
Can you provide a NEST example please

@chugh97

This comment has been minimized.

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
You can’t perform that action at this time.