Custom sorting query results by index name with scripting

I have 4 indexes: first, second, third, fourth.

I have a query that searches text on a field called "name" against all indexes.

POST /_all/_search?pretty
{
  "_source": ["name"], 
  "query": {
    "match": {
      "name": {
        "query": "testing"
      }
    }
  },
  "sort": {
    ????
  }
}

I want my query results to be sorted like so:

  • All matching docs from index "first"
  • All matching docs from index "second"
  • All matching docs from index "third"
  • All matching docs from index "fourth"

How can I do this, what do I put in the place of ???? above!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.