-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add first High level client documentation #23351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60661ec
Add first High level client documentation
dadoonet c373ed1
Extract documentation from test code
dadoonet 6c526ad
Merge branch 'master' into doc/hlclient-delete
dadoonet 798bf96
Don't mention cluster compatibility
dadoonet ee4a17a
Adapt per Nik's comments
dadoonet 2629c98
Missing dot and parenthesis
dadoonet dc80a1f
Bad rendering of docs
dadoonet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
...igh-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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.documentation; | ||
|
|
||
| import org.elasticsearch.ElasticsearchException; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.DocWriteResponse; | ||
| import org.elasticsearch.action.delete.DeleteRequest; | ||
| import org.elasticsearch.action.delete.DeleteResponse; | ||
| import org.elasticsearch.action.support.WriteRequest; | ||
| import org.elasticsearch.client.ESRestHighLevelClientTestCase; | ||
| import org.elasticsearch.client.RestHighLevelClient; | ||
| import org.elasticsearch.common.unit.TimeValue; | ||
| import org.elasticsearch.index.VersionType; | ||
| import org.elasticsearch.rest.RestStatus; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * This class is used to generate the Java Delete API documentation. | ||
| * You need to wrap your code between two tags like: | ||
| * // tag::example[] | ||
| * // end::example[] | ||
| * | ||
| * Where example is your tag name. | ||
| * | ||
| * Then in the documentation, you can extract what is between tag and end tags with | ||
| * ["source","java",subs="attributes,callouts"] | ||
| * -------------------------------------------------- | ||
| * sys2::[perl -ne 'exit if /end::example/; print if $tag; $tag = $tag || /tag::example/' {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java] | ||
| * -------------------------------------------------- | ||
| */ | ||
| public class DeleteDocumentationIT extends ESRestHighLevelClientTestCase { | ||
|
|
||
| /** | ||
| * This test documents docs/java-rest/high-level/document/delete.asciidoc | ||
| */ | ||
| public void testDelete() throws IOException { | ||
| RestHighLevelClient client = highLevelClient(); | ||
|
|
||
| // tag::delete-request[] | ||
| DeleteRequest request = new DeleteRequest( | ||
| "index", // <1> | ||
| "type", // <2> | ||
| "id"); // <3> | ||
| // end::delete-request[] | ||
|
|
||
| // tag::delete-request-props[] | ||
| request.timeout(TimeValue.timeValueSeconds(1)); // <1> | ||
| request.timeout("1s"); // <2> | ||
| request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); // <3> | ||
| request.setRefreshPolicy("wait_for"); // <4> | ||
| request.version(2); // <5> | ||
| request.versionType(VersionType.EXTERNAL); // <6> | ||
| // end::delete-request-props[] | ||
|
|
||
| // tag::delete-execute[] | ||
| DeleteResponse response = client.delete(request); | ||
| // end::delete-execute[] | ||
|
|
||
| try { | ||
| // tag::delete-notfound[] | ||
| if (response.getResult().equals(DocWriteResponse.Result.NOT_FOUND)) { | ||
| throw new Exception("Can't find document to be removed"); // <1> | ||
| } | ||
| // end::delete-notfound[] | ||
| } catch (Exception ignored) { } | ||
|
|
||
| // tag::delete-execute-async[] | ||
| client.deleteAsync(request, new ActionListener<DeleteResponse>() { | ||
| @Override | ||
| public void onResponse(DeleteResponse deleteResponse) { | ||
| // <1> | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Exception e) { | ||
| // <2> | ||
| } | ||
| }); | ||
| // end::delete-execute-async[] | ||
|
|
||
| // tag::delete-conflict[] | ||
| try { | ||
| client.delete(request); | ||
| } catch (ElasticsearchException exception) { | ||
| if (exception.status().equals(RestStatus.CONFLICT)) { | ||
| // <1> | ||
| } | ||
| } | ||
| // end::delete-conflict[] | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| * index API | ||
|
|
||
| * get API | ||
|
|
||
| * <<java-rest-high-document-delete>> | ||
|
|
||
| * bulk API | ||
|
|
||
| * search API | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| [[java-rest-high-document-delete]] | ||
| === Delete API | ||
|
|
||
| [[java-rest-high-document-delete-request]] | ||
| ==== Delete Request | ||
|
|
||
| The most simple Delete Request needs is: | ||
|
|
||
| ["source","java",subs="attributes,callouts"] | ||
| -------------------------------------------------- | ||
| sys2::[perl -ne 'exit if /end::delete-request/; print if $tag; $tag = $tag || /tag::delete-request/' {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java] | ||
| -------------------------------------------------- | ||
| <1> Index name | ||
| <2> Type | ||
| <3> Document id | ||
|
|
||
| You can also provide the following properties: | ||
|
|
||
| ["source","java",subs="attributes,callouts"] | ||
| -------------------------------------------------- | ||
| sys2::[perl -ne 'exit if /end::delete-request-props/; print if $tag; $tag = $tag || /tag::delete-request-props/' {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java] | ||
| -------------------------------------------------- | ||
| <1> Timeout | ||
| <2> Timeout as String | ||
| <3> Refresh policy | ||
| <4> Refresh policy as String | ||
| <5> Version | ||
| <6> Version type | ||
|
|
||
| [[java-rest-high-document-delete-sync]] | ||
| ==== Execution | ||
|
|
||
| ["source","java",subs="attributes,callouts"] | ||
| -------------------------------------------------- | ||
| sys2::[perl -ne 'exit if /end::delete-execute/; print if $tag; $tag = $tag || /tag::delete-execute/' {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java] | ||
| -------------------------------------------------- | ||
|
|
||
| [[java-rest-high-document-delete-async]] | ||
| ==== Asynchronous Execution | ||
|
|
||
| ["source","java",subs="attributes,callouts"] | ||
| -------------------------------------------------- | ||
| sys2::[perl -ne 'exit if /end::delete-execute-async/; print if $tag; $tag = $tag || /tag::delete-execute-async/' {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java] | ||
| -------------------------------------------------- | ||
| <1> Implement if needed when execution did not throw an exception | ||
| <2> Implement if needed in case of failure | ||
|
|
||
| [[java-rest-high-document-delete-response]] | ||
| ==== Delete Response | ||
|
|
||
| In the Delete Response object, you can check for example the result of the operation: | ||
|
|
||
| ["source","java",subs="attributes,callouts"] | ||
| -------------------------------------------------- | ||
| sys2::[perl -ne 'exit if /end::delete-notfound/; print if $tag; $tag = $tag || /tag::delete-notfound/' {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java] | ||
| -------------------------------------------------- | ||
| <1> Do something if we did not find the document which should have been deleted | ||
|
|
||
| Note that if you have a version conflict because you defined the version within the | ||
| <<java-rest-high-document-delete-request>>, it will raise an `ElasticsearchException` like: | ||
|
|
||
| ["source","java",subs="attributes,callouts"] | ||
| -------------------------------------------------- | ||
| sys2::[perl -ne 'exit if /end::delete-conflict/; print if $tag; $tag = $tag || /tag::delete-conflict/' {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DeleteDocumentationIT.java] | ||
| -------------------------------------------------- | ||
| <1> We got a version conflict | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include::delete.asciidoc[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [[java-rest-high]] | ||
| == Java High Level REST Client | ||
|
|
||
| The <<java-rest-high>>'s features include: | ||
|
|
||
| include::apis.asciidoc[] | ||
|
|
||
| It depends on elasticsearch core project as it uses elasticsearch request and response | ||
| objects so it will simplify a migration from the transport client. | ||
|
|
||
|
|
||
| include::usage.asciidoc[] | ||
|
|
||
| include::document/index.asciidoc[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| [[java-rest-high-usage]] | ||
| === Getting started | ||
|
|
||
| [[java-rest-high-usage-maven]] | ||
| ==== Maven Repository | ||
|
|
||
| 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`. | ||
|
|
||
| The high-level REST client is subject to the same release cycle as | ||
| elasticsearch. Replace the version with the desired client version. | ||
|
|
||
| [[java-rest-high-usage-maven-maven]] | ||
| ===== Maven configuration | ||
|
|
||
| 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> | ||
| <artifactId>rest-high-level</artifactId> | ||
| <version>{version}</version> | ||
| </dependency> | ||
| -------------------------------------------------- | ||
|
|
||
| [[java-rest-high-usage-maven-gradle]] | ||
| ===== Gradle configuration | ||
|
|
||
| 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 { | ||
| compile 'org.elasticsearch.client:rest-high-level:{version}' | ||
| } | ||
| -------------------------------------------------- | ||
|
|
||
| [[java-rest-high-usage-dependencies]] | ||
| ==== Dependencies | ||
|
|
||
| The high-level Java REST client depends on the following artifacts and their | ||
| transitive dependencies: | ||
|
|
||
| - org.elasticsearch.client:rest | ||
| - org.elasticsearch:elasticsearch | ||
|
|
||
|
|
||
| [[java-rest-high-usage-initialization]] | ||
| ==== Initialization | ||
|
|
||
| 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 | ||
|
|
||
| In the rest of this documentation about the high-level client, the `RestHighLevelClient` instance | ||
| will be referenced as `client`. | ||
|
|
||
| Then you have access to the high level APIs such as: | ||
|
|
||
| include::apis.asciidoc[] | ||
|
|
||
| Each API can be executed synchronously (i.e. <<java-rest-high-document-delete,`delete`>>) or | ||
| asynchronously (i.e. <<java-rest-high-document-delete,`deleteAsync`>>). | ||
| The asynchronous APIs require a listener that is called on thread pool managed by the low level client | ||
| when the response is received. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [[java-rest-license]] | ||
| == License | ||
|
|
||
| Copyright 2013-2017 Elasticsearch | ||
|
|
||
| Licensed 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. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [[java-rest-low]] | ||
| == Java Low Level REST Client | ||
|
|
||
| The low-level client's features include: | ||
|
|
||
| * minimal dependencies | ||
|
|
||
| * load balancing across all available nodes | ||
|
|
||
| * failover in case of node failures and upon specific response codes | ||
|
|
||
| * failed connection penalization (whether a failed node is retried depends on | ||
| how many consecutive times it failed; the more failed attempts the longer the | ||
| client will wait before trying that same node again) | ||
|
|
||
| * persistent connections | ||
|
|
||
| * trace logging of requests and responses | ||
|
|
||
| * optional automatic <<sniffer,discovery of cluster nodes>> | ||
|
|
||
|
|
||
| include::usage.asciidoc[] | ||
|
|
||
| include::configuration.asciidoc[] | ||
|
|
||
| include::sniffer.asciidoc[] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link instead of include here? I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found out that it gives a better documentation as the guy does not have to clic but has everything at hand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.