Skip to content

Instantly share code, notes, and snippets.

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