Skip to content

Instantly share code, notes, and snippets.

@jprante
Created November 28, 2012 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jprante/4162665 to your computer and use it in GitHub Desktop.
Save jprante/4162665 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