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

**URL:** <https://discuss.elastic.co/t/name-queries-in-multisearch-to-know-which-result-belongs-to-which-query/96756>\
**Category:** Elasticsearch\
**Created:** [August 11, 2017, 11:13am UTC](https://discuss.elastic.co/t/name-queries-in-multisearch-to-know-which-result-belongs-to-which-query/96756 "2017-08-11T11:13:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karolinebryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karolinebryn/32/17095_2.png) [@Karolinebryn](https://discuss.elastic.co/u/Karolinebryn)\
**Post date:** [August 11, 2017, 11:13am UTC](https://discuss.elastic.co/t/name-queries-in-multisearch-to-know-which-result-belongs-to-which-query/96756/1 "2017-08-11T11:13:13Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [August 11, 2017, 12:04pm UTC](https://discuss.elastic.co/t/name-queries-in-multisearch-to-know-which-result-belongs-to-which-query/96756/2 "2017-08-11T12:04:45Z")

</div>

> [@Karolinebryn](#):
>
> But I want to move the “\_name” to the root of the query,

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

---

<div class="post-metadata">

**Author:** ![Karolinebryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karolinebryn/32/17095_2.png) [@Karolinebryn](https://discuss.elastic.co/u/Karolinebryn)\
**Post date:** [August 15, 2017, 10:22am UTC](https://discuss.elastic.co/t/name-queries-in-multisearch-to-know-which-result-belongs-to-which-query/96756/3 "2017-08-15T10:22:52Z")

</div>

Yes, I understand that now 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 12, 2017, 10:23am UTC](https://discuss.elastic.co/t/name-queries-in-multisearch-to-know-which-result-belongs-to-which-query/96756/4 "2017-09-12T10:23:06Z")

</div>

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