How to name an empty query

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 ?

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?

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.

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].

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.

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

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?

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.

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:

createGraph(index, response);

Why not doing something like:

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.

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