Skip to content

Instantly share code, notes, and snippets.

@weekwood
Forked from jprante/scriptsort.sh
Created November 28, 2012 18:53
Show Gist options
  • Save weekwood/4163220 to your computer and use it in GitHub Desktop.
Save weekwood/4163220 to your computer and use it in GitHub Desktop.
Scripted sorting
curl -XDELETE 'localhost:9200/scriptsort'
curl -XPOST 'localhost:9200/scriptsort' -d '
{
"mappings": {
"test": {
"_id": {
"index" : "not_analyzed",
"stored": "yes"
}
}
}
}
'
curl -XPUT 'localhost:9200/scriptsort/test/abc' -d '
{
"name": "1"
}
'
curl -XPUT 'localhost:9200/scriptsort/test/def' -d '
{
"name": "2"
}
'
curl -XPUT 'localhost:9200/scriptsort/test/ghi' -d '
{
"name": "3"
}
'
curl -XGET 'localhost:9200/_refresh'
curl -XPOST 'localhost:9200/scriptsort/_search?pretty' -d '
{
"query": {
"match_all": {}
},
"sort" : {
"_script" : {
"script" : "ids.contains(doc[\u0027_id\u0027].stringValue)",
"type" : "string",
"order" : "asc",
"params" : {
"ids" : [
"def", "ghi"
]
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment