Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.apache.http.HttpStatus;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -128,18 +129,22 @@ private void waitForWatcher() throws Exception {
() -> "Exception when waiting for [" + template + "] template to be created");
}

boolean existsWatcherIndex = adminClient().performRequest("HEAD", ".watches").getStatusLine().getStatusCode() == 200;
boolean existsWatcherIndex = adminClient()
.performRequest(new Request("HEAD", ".watches"))
.getStatusLine().getStatusCode() == 200;
if (existsWatcherIndex == false) {
return;
}
Response response = adminClient().performRequest("GET", ".watches/_search", Collections.singletonMap("size", "1000"));
Request searchWatchesRequest = new Request("GET", ".watches/_search");
searchWatchesRequest.addParameter("size", "1000");
Response response = adminClient().performRequest(searchWatchesRequest);
ObjectPath objectPathResponse = ObjectPath.createFromResponse(response);
int totalHits = objectPathResponse.evaluate("hits.total");
if (totalHits > 0) {
List<Map<String, Object>> hits = objectPathResponse.evaluate("hits.hits");
for (Map<String, Object> hit : hits) {
String id = (String) hit.get("_id");
assertOK(adminClient().performRequest("DELETE", "_xpack/watcher/watch/" + id));
adminClient().performRequest(new Request("DELETE", "_xpack/watcher/watch/" + id));
}
}
}
Expand Down