diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java
index ed0043c801c7b..9d75132a903c3 100644
--- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java
@@ -26,6 +26,8 @@
import org.elasticsearch.client.watcher.ActivateWatchResponse;
import org.elasticsearch.client.watcher.AckWatchRequest;
import org.elasticsearch.client.watcher.AckWatchResponse;
+import org.elasticsearch.client.watcher.ExecuteWatchRequest;
+import org.elasticsearch.client.watcher.ExecuteWatchResponse;
import org.elasticsearch.client.watcher.GetWatchRequest;
import org.elasticsearch.client.watcher.GetWatchResponse;
import org.elasticsearch.client.watcher.StartWatchServiceRequest;
@@ -269,6 +271,33 @@ public void activateWatchAsync(ActivateWatchRequest request, RequestOptions opti
ActivateWatchResponse::fromXContent, listener, singleton(404));
}
+ /**
+ * Execute a watch on the cluster
+ * See
+ * the docs for more.
+ * @param request the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @return the response
+ * @throws IOException if there is a problem sending the request or parsing the response
+ */
+ public ExecuteWatchResponse executeWatch(ExecuteWatchRequest request, RequestOptions options) throws IOException {
+ return restHighLevelClient.performRequestAndParseEntity(request, WatcherRequestConverters::executeWatch, options,
+ ExecuteWatchResponse::fromXContent, emptySet());
+ }
+
+ /**
+ * Asynchronously execute a watch on the cluster
+ * See
+ * the docs for more.
+ * @param request the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @param listener the listener to be notifed upon request completion
+ */
+ public void executeWatchAsync(ExecuteWatchRequest request, RequestOptions options, ActionListener listener) {
+ restHighLevelClient.performRequestAsyncAndParseEntity(request, WatcherRequestConverters::executeWatch, options,
+ ExecuteWatchResponse::fromXContent, listener, emptySet());
+ }
+
/**
* Get the watcher stats
* See
diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java
index 1da7ef4c617ff..3cc6826e837dc 100644
--- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java
@@ -25,16 +25,20 @@
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
-import org.elasticsearch.client.watcher.DeactivateWatchRequest;
-import org.elasticsearch.client.watcher.ActivateWatchRequest;
import org.elasticsearch.client.watcher.AckWatchRequest;
+import org.elasticsearch.client.watcher.ActivateWatchRequest;
+import org.elasticsearch.client.watcher.DeactivateWatchRequest;
import org.elasticsearch.client.watcher.DeleteWatchRequest;
+import org.elasticsearch.client.watcher.ExecuteWatchRequest;
import org.elasticsearch.client.watcher.GetWatchRequest;
import org.elasticsearch.client.watcher.PutWatchRequest;
import org.elasticsearch.client.watcher.StartWatchServiceRequest;
import org.elasticsearch.client.watcher.StopWatchServiceRequest;
import org.elasticsearch.client.watcher.WatcherStatsRequest;
import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.xcontent.XContentType;
+
+import java.io.IOException;
final class WatcherRequestConverters {
@@ -108,6 +112,28 @@ static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) {
return request;
}
+ static Request executeWatch(ExecuteWatchRequest executeWatchRequest) throws IOException {
+ String endpoint = new RequestConverters.EndpointBuilder()
+ .addPathPartAsIs("_xpack", "watcher", "watch")
+ .addPathPart(executeWatchRequest.getId()) // will ignore if ID is null
+ .addPathPartAsIs("_execute").build();
+
+ Request request = new Request(HttpPost.METHOD_NAME, endpoint);
+ RequestConverters.Params params = new RequestConverters.Params(request);
+ if (executeWatchRequest.isDebug()) {
+ params.putParam("debug", "true");
+ }
+ if (executeWatchRequest.ignoreCondition()) {
+ params.putParam("ignore_condition", "true");
+ }
+ if (executeWatchRequest.recordExecution()) {
+ params.putParam("record_execution", "true");
+ }
+
+ request.setEntity(RequestConverters.createEntity(executeWatchRequest, XContentType.JSON));
+ return request;
+ }
+
public static Request ackWatch(AckWatchRequest ackWatchRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack", "watcher", "watch")
diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java
new file mode 100644
index 0000000000000..689f82f18b9a6
--- /dev/null
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.client.common;
+
+import org.elasticsearch.common.xcontent.ObjectPath;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.XContentUtils;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Encapsulates the xcontent source
+ */
+public class XContentSource {
+
+ private final Object data;
+
+ /**
+ * Constructs a new XContentSource out of the given parser
+ */
+ public XContentSource(XContentParser parser) throws IOException {
+ this.data = XContentUtils.readValue(parser, parser.nextToken());
+ }
+
+ /**
+ * @return true if the top level value of the source is a map
+ */
+ public boolean isMap() {
+ return data instanceof Map;
+ }
+
+ /**
+ * @return The source as a map
+ */
+ @SuppressWarnings("unchecked")
+ public Map getAsMap() {
+ return (Map) data;
+ }
+
+ /**
+ * @return true if the top level value of the source is a list
+ */
+ public boolean isList() {
+ return data instanceof List;
+ }
+
+ /**
+ * @return The source as a list
+ */
+ @SuppressWarnings("unchecked")
+ public List