# How to name an empty query

**URL:** <https://discuss.elastic.co/t/how-to-name-an-empty-query/166141>\
**Category:** Elasticsearch\
**Created:** [January 29, 2019, 10:20am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141 "2019-01-29T10:20:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wassim\_Ben\_Amor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wassim_ben_amor/32/39799_2.png) [@Wassim\_Ben\_Amor](https://discuss.elastic.co/u/Wassim_Ben_Amor)\
**Post date:** [January 29, 2019, 10:20am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/1 "2019-01-29T10:20:27Z")

</div>

Hello,  
I have a simple elasticsearch query

```
POST test/_search
{
"size": 0
}

```

this return a simple response :

```
   {
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 185,
    "max_score" : 0.0,
    "hits" : []
  }
}

```

The goal is to make a label of the query, to identify it later in a big \_msearch, at least when making aggregations we have a custom field we can label it, but here how can we do it ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 29, 2019, 10:26am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/2 "2019-01-29T10:26:41Z")

</div>

You can't but I don't understand what is the problem with `_msearch` as the responses are sent in the same order as the original requests?

---

<div class="post-metadata">

**Author:** ![Wassim\_Ben\_Amor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wassim_ben_amor/32/39799_2.png) [@Wassim\_Ben\_Amor](https://discuss.elastic.co/u/Wassim_Ben_Amor)\
**Post date:** [January 29, 2019, 10:30am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/3 "2019-01-29T10:30:27Z")

</div>

Thank you for your reply,  
I don't believe it's safe to rely on requests order. it's too specific I think. when changing the order requests, or we delete a request, we must modify all the code which depends on static index numbers ?  
I prefer to loop on response and testing on labels.  
Well, thank you again.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 29, 2019, 10:35am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/4 "2019-01-29T10:35:50Z")

</div>

If you send `[A, B, C]` you will get back `[A, B, C]`.  
The next request, if you send `[C, B, A]` you will get back `[C, B, A]`.

---

<div class="post-metadata">

**Author:** ![Wassim\_Ben\_Amor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wassim_ben_amor/32/39799_2.png) [@Wassim\_Ben\_Amor](https://discuss.elastic.co/u/Wassim_Ben_Amor)\
**Post date:** [January 29, 2019, 10:39am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/5 "2019-01-29T10:39:36Z")

</div>

Imagine if you have a very big project.  
You want to make a big \_msearch, so after the request, we have to make  
if (index == 0)  
else if (index == 1)  
...  
else if (index == 23)

when we delete a request and we don't need it anymore, we have to modify all the indexes.  
This is a specific use case, but I can list a lot of problems if we rely only on requests order.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 29, 2019, 10:56am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/6 "2019-01-29T10:56:05Z")

</div>

I don't know your project so I can't comment more but this kind of code does not look right to me.

```auto
if (index == 0)
else if (index == 1)
...
else if (index == 23)

```

I'd more be doing a `for` loop or something like this... But again I don't know your project so I don't understand what the real problem is.

I mean: are you sure you need to use `_msearch`?

---

<div class="post-metadata">

**Author:** ![Wassim\_Ben\_Amor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wassim_ben_amor/32/39799_2.png) [@Wassim\_Ben\_Amor](https://discuss.elastic.co/u/Wassim_Ben_Amor)\
**Post date:** [January 29, 2019, 11:03am UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/7 "2019-01-29T11:03:06Z")

</div>

Let's say the goal is to create a dashboard containing multiple graphs, each graph is the result of an elasticsearch query.  
So if we rely only on responses order, we will have

> responses.forEach((response,index)=\> {  
> if (index == 0) {  
> //format response and create graph "test0"  
> }  
> else if (index == 1) {  
> //format response and create graph "test1"  
> }  
> ...  
> else if (index == 30) {  
> //format response and create graph "test30"  
> }  
> }

as you can see, this is not dynamic, if one day, we delete the graph 25 for example.  
we must edit the condition from 25 to 30. but If we had the queries tagged, we can test directly on the key or the label.  
this is just coding comfortability, because even here we can create a map containing keys and requests and use it later.  
Thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 29, 2019, 2:06pm UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/8 "2019-01-29T14:06:59Z")

</div>

I wonder what is happening in there:

```
//format response and create graph "test0"

```

I mean let say that to create a graph you can call something like:

```auto
createGraph(index, response);

```

Why not doing something like:

```auto
MultiSearchResponse response = client.msearch(request, RequestOptions.DEFAULT);
for (int i = 0; i < response.getResponses().length; i++) {
    createGraph(i, response.getResponses()[i]);
}

```

I don't really see what is the difference of calling graphs by a number or by a name.  
I mean that you should never have to change your code in a dramatic way because the list of requests/graphs you want to generate is changing. Whatever the key to access the response is, a String or a Number.

My 0.05 cents but I'm probably missing something.

---

<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:** [February 26, 2019, 2:07pm UTC](https://discuss.elastic.co/t/how-to-name-an-empty-query/166141/9 "2019-02-26T14:07:00Z")

</div>

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