2017-02-24 07:52:36 -05:00
|
|
|
[[java-rest-high-usage]]
|
2017-07-04 04:58:57 -04:00
|
|
|
== Getting started
|
|
|
|
|
|
|
|
This section describes how to get started with the high-level REST client from
|
|
|
|
getting the artifact to using it in an application.
|
2017-02-24 07:52:36 -05:00
|
|
|
|
2017-08-01 04:38:56 -04:00
|
|
|
[[java-rest-high-compatibility]]
|
|
|
|
=== Compatibility
|
|
|
|
The Java High Level REST Client requires Java 1.8 and depends on the Elasticsearch
|
|
|
|
core project. The client version is the same as the Elasticsearch version that the
|
|
|
|
client was developed for. It accepts the same request arguments as the `TransportClient`
|
|
|
|
and returns the same response objects.
|
|
|
|
|
|
|
|
The High Level Client is backwards compatible but can only communicate with Elasticsearch
|
|
|
|
version 5.5 and onwards. The High Level Client is forward compatible as well, meaning that
|
|
|
|
it supports communicating with a later version of Elasticsearch than the one it was developed
|
|
|
|
for. It is recommended to upgrade the High Level Client when upgrading the Elasticsearch
|
|
|
|
cluster to a new major version, as REST API breaking changes may cause unexpected results,
|
|
|
|
and newly added APIs will only be supported by the newer version of the client. The client
|
|
|
|
should be updated last, once all of the nodes in the cluster have been upgraded.
|
|
|
|
|
2017-07-31 09:41:21 -04:00
|
|
|
[[java-rest-high-javadoc]]
|
|
|
|
=== Javadoc
|
|
|
|
|
|
|
|
The javadoc for the REST high level client can be found at {rest-high-level-client-javadoc}/index.html.
|
|
|
|
|
2017-02-24 07:52:36 -05:00
|
|
|
[[java-rest-high-usage-maven]]
|
2017-07-04 04:58:57 -04:00
|
|
|
=== Maven Repository
|
2017-02-24 07:52:36 -05:00
|
|
|
|
|
|
|
The high-level Java REST client is hosted on
|
|
|
|
http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.elasticsearch.client%22[Maven
|
|
|
|
Central]. The minimum Java version required is `1.8`.
|
|
|
|
|
2017-07-03 04:48:16 -04:00
|
|
|
The High Level REST Client is subject to the same release cycle as
|
|
|
|
Elasticsearch. Replace the version with the desired client version.
|
2017-02-24 07:52:36 -05:00
|
|
|
|
|
|
|
[[java-rest-high-usage-maven-maven]]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Maven configuration
|
2017-02-24 07:52:36 -05:00
|
|
|
|
|
|
|
Here is how you can configure the dependency using maven as a dependency manager.
|
|
|
|
Add the following to your `pom.xml` file:
|
|
|
|
|
|
|
|
["source","xml",subs="attributes"]
|
|
|
|
--------------------------------------------------
|
|
|
|
<dependency>
|
|
|
|
<groupId>org.elasticsearch.client</groupId>
|
2017-07-13 03:44:25 -04:00
|
|
|
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
2017-02-24 07:52:36 -05:00
|
|
|
<version>{version}</version>
|
|
|
|
</dependency>
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[[java-rest-high-usage-maven-gradle]]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Gradle configuration
|
2017-02-24 07:52:36 -05:00
|
|
|
|
|
|
|
Here is how you can configure the dependency using gradle as a dependency manager.
|
|
|
|
Add the following to your `build.gradle` file:
|
|
|
|
|
|
|
|
["source","groovy",subs="attributes"]
|
|
|
|
--------------------------------------------------
|
|
|
|
dependencies {
|
2017-07-13 03:44:25 -04:00
|
|
|
compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:{version}'
|
2017-02-24 07:52:36 -05:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
Document how to import Lucene Snapshot libs when elasticsearch clients (#26113)
When using the High Level Rest Client 6.0.0-beta1, we are missing some transitive dependencies for Lucene as Lucene 7 has not been released yet. See the following `pom.xml`:
```xml
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>6.0.0-beta1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.0.0-beta1</version>
</dependency>
```
It gives:
```
[ERROR] Failed to execute goal on project fscrawler: Could not resolve dependencies for project fr.pilato.elasticsearch.crawler:fscrawler:jar:2.4-SNAPSHOT: The following artifacts could not be resolved: org.apache.lucene:lucene-analyzers-common:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-backward-codecs:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-grouping:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-highlighter:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-join:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-memory:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-misc:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-queries:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-queryparser:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-sandbox:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-spatial:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-spatial-extras:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-spatial3d:jar:7.0.0-snapshot-00142c9, org.apache.lucene:lucene-suggest:jar:7.0.0-snapshot-00142c9: Failure to find org.apache.lucene:lucene-analyzers-common:jar:7.0.0-snapshot-00142c9 in https://artifacts.elastic.co/maven/ was cached in the local repository, resolution will not be reattempted until the update interval of elastic-download-service has elapsed or updates are forced -
```
We need to add some temporary documentation on how to add the missing repository to a gradle or maven project:
```xml
<repository>
<id>elastic-lucene-snapshots</id>
<name>Elastic Lucene Snapshots</name>
<url>http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
```
This also applies to the transport client.
Closes #26106.
2017-08-10 08:54:07 -04:00
|
|
|
[[java-rest-high-usage-maven-lucene]]
|
|
|
|
==== Lucene Snapshot repository
|
|
|
|
|
|
|
|
The very first releases of any major version (like a beta), might have been built on top of a Lucene Snapshot version.
|
|
|
|
In such a case you will be unable to resolve the Lucene dependencies of the client.
|
|
|
|
|
|
|
|
For example, if you want to use the `6.0.0-beta1` version which depends on Lucene `7.0.0-snapshot-00142c9`, you must
|
|
|
|
define the following repository.
|
|
|
|
|
|
|
|
For Maven:
|
|
|
|
|
|
|
|
["source","xml",subs="attributes"]
|
|
|
|
--------------------------------------------------
|
|
|
|
<repository>
|
|
|
|
<id>elastic-lucene-snapshots</id>
|
|
|
|
<name>Elastic Lucene Snapshots</name>
|
|
|
|
<url>http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9</url>
|
|
|
|
<releases><enabled>true</enabled></releases>
|
|
|
|
<snapshots><enabled>false</enabled></snapshots>
|
|
|
|
</repository>
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
For Gradle:
|
|
|
|
|
|
|
|
["source","groovy",subs="attributes"]
|
|
|
|
--------------------------------------------------
|
|
|
|
maven {
|
|
|
|
url 'http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9'
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2017-02-24 07:52:36 -05:00
|
|
|
[[java-rest-high-usage-dependencies]]
|
2017-07-04 04:58:57 -04:00
|
|
|
=== Dependencies
|
2017-02-24 07:52:36 -05:00
|
|
|
|
2017-07-03 04:48:16 -04:00
|
|
|
The High Level Java REST Client depends on the following artifacts and their
|
2017-02-24 07:52:36 -05:00
|
|
|
transitive dependencies:
|
|
|
|
|
2017-07-27 05:17:48 -04:00
|
|
|
- org.elasticsearch.client:elasticsearch-rest-client
|
2017-02-24 07:52:36 -05:00
|
|
|
- org.elasticsearch:elasticsearch
|
|
|
|
|
|
|
|
|
|
|
|
[[java-rest-high-usage-initialization]]
|
2017-07-04 04:58:57 -04:00
|
|
|
=== Initialization
|
2017-02-24 07:52:36 -05:00
|
|
|
|
|
|
|
A `RestHighLevelClient` instance needs a <<java-rest-low-usage-initialization,REST low-level client>>
|
|
|
|
to be built as follows:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
RestHighLevelClient client =
|
|
|
|
new RestHighLevelClient(lowLevelRestClient); <1>
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> We pass the <<java-rest-low-usage-initialization,REST low-level client>> instance
|
|
|
|
|
2017-07-03 04:48:16 -04:00
|
|
|
In the rest of this documentation about the Java High Level Client, the `RestHighLevelClient` instance
|
2017-02-24 07:52:36 -05:00
|
|
|
will be referenced as `client`.
|