Hi,
I am using Java high level rest client to search for hundreds of products stored in elastic search.
I am using term query.
Since, there are hundreds of products that needs to be searched, I have used async request for term query in for loop.
But I need to make sure that all requests have been completed once the loop is exited and a new statement needs to be executed.
I am not sure how to do this.
My code looks like this:
for(ProductField field: fields) {
String type = field.getType();
String value = field.getValue();
searchSourceBuilder.query(QueryBuilders.termQuery(type,value));
request.source(searchSourceBuilder);
client.searchAsync(request, new ActionListener<SearchResponse>() {
@Override
public void onResponse(SearchResponse searchResponse) {
}
@Override
public void onFailure(Exception e) {
}
});
}
After for loop the next statement should be executed only if all async requests have been completed.
How should I do this?