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 ?
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.
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.
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 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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.