2017-03-28 17:23:01 -04:00
[[api-java]]
== Java API
2017-12-01 06:24:26 -05:00
deprecated[7.0.0, The `TransportClient` is deprecated in favour of the {java-rest}/java-rest-high.html[Java High Level REST Client] and will be removed in Elasticsearch 8.0. The {java-rest}/java-rest-high-level-migration.html[migration guide] describes all the steps needed to migrate.]
2017-03-28 17:23:01 -04:00
{xpack} provides a Java client called `WatcherClient` that adds native Java
support for the {watcher}.
To obtain a `WatcherClient` instance, make sure you first set up the
`XPackClient`.
[float]
=== Installing XPackClient
You first need to make sure the +x-pack-transport-{version}+ JAR file is in the classpath.
You can extract this jar from the downloaded {xpack} bundle.
If you use Maven to manage dependencies, add the following to the `pom.xml`:
["source","xml",subs="attributes,callouts"]
--------------------------------------------------
<project ...>
<repositories>
<!-- add the elasticsearch repo -->
<repository>
<id>elasticsearch-releases</id>
<url>https://artifacts.elastic.co/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
...
</repositories>
...
<dependencies>
<!-- add the x-pack jar as a dependency -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>{version}</version>
</dependency>
...
</dependencies>
...
</project>
--------------------------------------------------
If you use Gradle, add the dependencies to `build.gradle`:
["source","groovy",subs="attributes,callouts"]
--------------------------------------------------------------
repositories {
/* ... Any other repositories ... */
// Add the Elasticsearch Maven Repository
maven {
url "https://artifacts.elastic.co/maven"
}
}
dependencies {
// Provide the x-pack jar on the classpath for compilation and at runtime
compile "org.elasticsearch.client:x-pack-transport:{version}"
/* ... */
}
--------------------------------------------------------------
You can also download the https://artifacts.elastic.co/maven/org/elasticsearch/client/x-pack-transport/{version}/x-pack-transport-{version}.jar[X-Pack Transport JAR]
manually, directly from our Maven repository.
[float]
=== Obtaining the `WatcherClient`
To obtain an instance of the `WatcherClient` you first need to create the
`XPackClient`. The `XPackClient` is a wrapper around the standard Java
Elasticsearch `Client`:
[source,java]
--------------------------------------------------
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
2018-01-23 13:43:58 -05:00
import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.core.watcher.client.WatcherClient;
2017-03-28 17:23:01 -04:00
...
TransportClient client = new PreBuiltXPackTransportClient(Settings.builder()
.put("cluster.name", "myClusterName")
...
.build())
2018-05-17 08:23:08 -04:00
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
2017-03-28 17:23:01 -04:00
XPackClient xpackClient = new XPackClient(client);
WatcherClient watcherClient = xpackClient.watcher();
--------------------------------------------------
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/put-watch.asciidoc
2017-03-28 17:23:01 -04:00
include::java/put-watch.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/get-watch.asciidoc
2017-03-28 17:23:01 -04:00
include::java/get-watch.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/delete-watch.asciidoc
2017-03-28 17:23:01 -04:00
include::java/delete-watch.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/execute-watch.asciidoc
2017-03-28 17:23:01 -04:00
include::java/execute-watch.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/ack-watch.asciidoc
2017-03-28 17:23:01 -04:00
include::java/ack-watch.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/activate-watch.asciidoc
2017-03-28 17:23:01 -04:00
include::java/activate-watch.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/deactivate-watch.asciidoc
2017-03-28 17:23:01 -04:00
include::java/deactivate-watch.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/stats.asciidoc
2017-03-28 17:23:01 -04:00
include::java/stats.asciidoc[]
2018-05-23 12:37:55 -04:00
:edit_url: https://github.com/elastic/elasticsearch/edit/{branch}/x-pack/docs/en/watcher/java/service.asciidoc
2017-03-28 17:23:01 -04:00
include::java/service.asciidoc[]