Name queries in multisearch to know which result belongs to which query

I am creating a multisearch query that consists of several queries and I need to know which query provided which result.

Example _msearch:

{"index": "myindex"}
{"query": {"bool": {"must":{...}, "filter":{...}}}}
{"index": "mysecondindex"}
{"query": {"bool": {"must":{...}, "filter":{...}}}}

The result of this search will be something like this:

{
   "responses":[
      {
         "took":7,
         "timed_out":false,
         "_shards":{
            "total":2,
            "successful":2,
            "failed":0
         },
         "hits":{
            "total":0,
            "max_score":null,
            "hits":[...]
         },
         "status":200
      },
	        {
         "took":7,
         "timed_out":false,
         "_shards":{
            "total":2,
            "successful":2,
            "failed":0
         },
         "hits":{
            "total":0,
            "max_score":null,
            "hits":[...]
         },
         "status":200
      }
	]
}

How do I know which result belongs to the first query and which belongs to the second query? I do not want to rely on the order of the results.

I've looked into naming queries. And I figured it is possible to name a query like this:

{ 
   "query":{
      "bool":{
          "_name": "test_query",
         "must":{},
         "filter":{}
      }
   }
}

But I want to move the "_name" to the root of the query, not within the bool-query, like this (but this does not work):

{ 
   "query":{
       "_name": "test_query",
      "bool":{
         "must":{},
         "filter":{}
      }
   }
}

Can someone tell me how I can name a query? Or if there is another solution to this problem that I am overlooking :slight_smile:

Your bool query is the root query. It cannot have a sibling

Yes, I understand that now :slight_smile:

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