When you want to order the elaticsearch document in the order of Ids you have provided in Ids query, then following function score query can be used to get required result:
{
"query":{
"function_score":{
"query":{
"ids":{
"type":"_doc",
"values":[
"4",
"3",
"1",
"5",
"2",
"6"
]
}
},
"script_score":{
"script":{
"params":{
"ids":[
"4",
"3",
"1",
"5",
"2",
"6"
]
},
"source":"params.ids.size() - params.ids.indexOf(doc['_id'].getValue())"
}
}
}
}
}