Skip to content
Merged
Show file tree
Hide file tree
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 @@ -176,7 +176,8 @@ public void testIndex() throws Exception {
// <3>
}
if (shardInfo.getFailed() > 0) {
for (ReplicationResponse.ShardInfo.Failure failure : shardInfo.getFailures()) {
for (ReplicationResponse.ShardInfo.Failure failure :
shardInfo.getFailures()) {
String reason = failure.reason(); // <4>
}
}
Expand Down Expand Up @@ -239,8 +240,9 @@ public void testIndex() throws Exception {
}
{
IndexRequest request = new IndexRequest("posts", "doc", "async").source("field", "value");
ActionListener<IndexResponse> listener;
// tag::index-execute-listener
ActionListener<IndexResponse> listener = new ActionListener<IndexResponse>() {
listener = new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse indexResponse) {
// <1>
Expand Down Expand Up @@ -305,8 +307,8 @@ public void testUpdate() throws Exception {

request = new UpdateRequest("posts", "doc", "1").fetchSource(true);
//tag::update-request-with-stored-script
Script stored =
new Script(ScriptType.STORED, null, "increment-field", parameters); // <1>
Script stored = new Script(
ScriptType.STORED, null, "increment-field", parameters); // <1>
request.script(stored); // <2>
//end::update-request-with-stored-script
updateResponse = client.update(request, RequestOptions.DEFAULT);
Expand Down Expand Up @@ -359,7 +361,8 @@ public void testUpdate() throws Exception {
//end::update-request-with-doc-as-string
request.fetchSource(true);
// tag::update-execute
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
UpdateResponse updateResponse = client.update(
request, RequestOptions.DEFAULT);
// end::update-execute
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());

Expand Down Expand Up @@ -397,7 +400,8 @@ public void testUpdate() throws Exception {
// <1>
}
if (shardInfo.getFailed() > 0) {
for (ReplicationResponse.ShardInfo.Failure failure : shardInfo.getFailures()) {
for (ReplicationResponse.ShardInfo.Failure failure :
shardInfo.getFailures()) {
String reason = failure.reason(); // <2>
}
}
Expand All @@ -408,7 +412,8 @@ public void testUpdate() throws Exception {
UpdateRequest request = new UpdateRequest("posts", "type", "does_not_exist")
.doc("field", "value");
try {
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
UpdateResponse updateResponse = client.update(
request, RequestOptions.DEFAULT);
} catch (ElasticsearchException e) {
if (e.status() == RestStatus.NOT_FOUND) {
// <1>
Expand All @@ -422,7 +427,8 @@ public void testUpdate() throws Exception {
.doc("field", "value")
.version(1);
try {
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
UpdateResponse updateResponse = client.update(
request, RequestOptions.DEFAULT);
} catch(ElasticsearchException e) {
if (e.status() == RestStatus.CONFLICT) {
// <1>
Expand All @@ -445,7 +451,8 @@ public void testUpdate() throws Exception {
//tag::update-request-source-include
String[] includes = new String[]{"updated", "r*"};
String[] excludes = Strings.EMPTY_ARRAY;
request.fetchSource(new FetchSourceContext(true, includes, excludes)); // <1>
request.fetchSource(
new FetchSourceContext(true, includes, excludes)); // <1>
//end::update-request-source-include
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
Expand All @@ -459,7 +466,8 @@ public void testUpdate() throws Exception {
//tag::update-request-source-exclude
String[] includes = Strings.EMPTY_ARRAY;
String[] excludes = new String[]{"updated"};
request.fetchSource(new FetchSourceContext(true, includes, excludes)); // <1>
request.fetchSource(
new FetchSourceContext(true, includes, excludes)); // <1>
//end::update-request-source-exclude
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
Expand Down Expand Up @@ -508,8 +516,9 @@ public void testUpdate() throws Exception {
{
UpdateRequest request = new UpdateRequest("posts", "doc", "async").doc("reason", "async update").docAsUpsert(true);

ActionListener<UpdateResponse> listener;
// tag::update-execute-listener
ActionListener<UpdateResponse> listener = new ActionListener<UpdateResponse>() {
listener = new ActionListener<UpdateResponse>() {
@Override
public void onResponse(UpdateResponse updateResponse) {
// <1>
Expand Down Expand Up @@ -548,12 +557,13 @@ public void testDelete() throws Exception {
// tag::delete-request
DeleteRequest request = new DeleteRequest(
"posts", // <1>
"doc", // <2>
"1"); // <3>
"doc", // <2>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These didn't line up and they made me uncomfortable.

"1"); // <3>
// end::delete-request

// tag::delete-execute
DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);
DeleteResponse deleteResponse = client.delete(
request, RequestOptions.DEFAULT);
// end::delete-execute
assertSame(DocWriteResponse.Result.DELETED, deleteResponse.getResult());

Expand All @@ -567,7 +577,8 @@ public void testDelete() throws Exception {
// <1>
}
if (shardInfo.getFailed() > 0) {
for (ReplicationResponse.ShardInfo.Failure failure : shardInfo.getFailures()) {
for (ReplicationResponse.ShardInfo.Failure failure :
shardInfo.getFailures()) {
String reason = failure.reason(); // <2>
}
}
Expand Down Expand Up @@ -598,7 +609,8 @@ public void testDelete() throws Exception {
{
// tag::delete-notfound
DeleteRequest request = new DeleteRequest("posts", "doc", "does_not_exist");
DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);
DeleteResponse deleteResponse = client.delete(
request, RequestOptions.DEFAULT);
if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {
// <1>
}
Expand All @@ -612,8 +624,9 @@ public void testDelete() throws Exception {

// tag::delete-conflict
try {
DeleteRequest request = new DeleteRequest("posts", "doc", "1").version(2);
DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);
DeleteResponse deleteResponse = client.delete(
new DeleteRequest("posts", "doc", "1").version(2),
RequestOptions.DEFAULT);
} catch (ElasticsearchException exception) {
if (exception.status() == RestStatus.CONFLICT) {
// <1>
Expand All @@ -628,8 +641,9 @@ public void testDelete() throws Exception {

DeleteRequest request = new DeleteRequest("posts", "doc", "async");

ActionListener<DeleteResponse> listener;
// tag::delete-execute-listener
ActionListener<DeleteResponse> listener = new ActionListener<DeleteResponse>() {
listener = new ActionListener<DeleteResponse>() {
@Override
public void onResponse(DeleteResponse deleteResponse) {
// <1>
Expand Down
71 changes: 21 additions & 50 deletions docs/java-rest/high-level/document/delete.asciidoc
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
[[java-rest-high-document-delete]]
--
:api: delete
:request: DeleteRequest
:response: DeleteResponse
--

[id="{upid}-{api}"]
=== Delete API

[[java-rest-high-document-delete-request]]
[id="{upid}-{api}-request"]
==== Delete Request

A `DeleteRequest` requires the following arguments:
A +{request}+ requires the following arguments:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request]
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Index
<2> Type
Expand All @@ -19,82 +25,47 @@ The following arguments can optionally be provided:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-routing]
include-tagged::{doc-tests-file}[{api}-request-routing]
--------------------------------------------------
<1> Routing value

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-timeout]
include-tagged::{doc-tests-file}[{api}-request-timeout]
--------------------------------------------------
<1> Timeout to wait for primary shard to become available as a `TimeValue`
<2> Timeout to wait for primary shard to become available as a `String`

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-refresh]
include-tagged::{doc-tests-file}[{api}-request-refresh]
--------------------------------------------------
<1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
<2> Refresh policy as a `String`

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-version]
include-tagged::{doc-tests-file}[{api}-request-version]
--------------------------------------------------
<1> Version

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-version-type]
include-tagged::{doc-tests-file}[{api}-request-version-type]
--------------------------------------------------
<1> Version type

[[java-rest-high-document-delete-sync]]
==== Synchronous Execution

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute]
--------------------------------------------------

[[java-rest-high-document-delete-async]]
==== Asynchronous Execution

The asynchronous execution of a delete request requires both the `DeleteRequest`
instance and an `ActionListener` instance to be passed to the asynchronous
method:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute-async]
--------------------------------------------------
<1> The `DeleteRequest` to execute and the `ActionListener` to use when
the execution completes

The asynchronous method does not block and returns immediately. Once it is
completed the `ActionListener` is called back using the `onResponse` method
if the execution successfully completed or using the `onFailure` method if
it failed.

A typical listener for `DeleteResponse` looks like:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute-listener]
--------------------------------------------------
<1> Called when the execution is successfully completed. The response is
provided as an argument
<2> Called in case of failure. The raised exception is provided as an argument
include::../execution.asciidoc[]

[[java-rest-high-document-delete-response]]
[id="{upid}-{api}-response"]
==== Delete Response

The returned `DeleteResponse` allows to retrieve information about the executed
The returned +{response}+ allows to retrieve information about the executed
operation as follows:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-response]
include-tagged::{doc-tests-file}[{api}-response]
--------------------------------------------------
<1> Handle the situation where number of successful shards is less than
total shards
Expand All @@ -105,7 +76,7 @@ It is also possible to check whether the document was found or not:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-notfound]
include-tagged::{doc-tests-file}[{api}-notfound]
--------------------------------------------------
<1> Do something if the document to be deleted was not found

Expand All @@ -114,7 +85,7 @@ be thrown:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-conflict]
include-tagged::{doc-tests-file}[{api}-conflict]
--------------------------------------------------
<1> The raised exception indicates that a version conflict error was returned

51 changes: 11 additions & 40 deletions docs/java-rest/high-level/document/exists.asciidoc
Original file line number Diff line number Diff line change
@@ -1,60 +1,31 @@
[[java-rest-high-document-exists]]
--
:api: exists
:request: GetRequest
:response: boolean
--

[id="{upid}-{api}"]
=== Exists API

The exists API returns `true` if a document exists, and `false` otherwise.

[[java-rest-high-document-exists-request]]
[id="{upid}-{api}-request"]
==== Exists Request

It uses `GetRequest` just like the <<java-rest-high-document-get>>.
It uses +{request}+ just like the <<java-rest-high-document-get>>.
All of its <<java-rest-high-document-get-request-optional-arguments, optional arguments>>
are supported. Since `exists()` only returns `true` or `false`, we recommend
turning off fetching `_source` and any stored fields so the request is
slightly lighter:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-request]
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Index
<2> Type
<3> Document id
<4> Disable fetching `_source`.
<5> Disable fetching stored fields.

[[java-rest-high-document-exists-sync]]
==== Synchronous Execution

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-execute]
--------------------------------------------------

[[java-rest-high-document-exists-async]]
==== Asynchronous Execution

The asynchronous execution of exists request requires both the `GetRequest`
instance and an `ActionListener` instance to be passed to the asynchronous
method:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-execute-async]
--------------------------------------------------
<1> The `GetRequest` to execute and the `ActionListener` to use when
the execution completes.

The asynchronous method does not block and returns immediately. Once it is
completed the `ActionListener` is called back using the `onResponse` method
if the execution successfully completed or using the `onFailure` method if
it failed.

A typical listener for `GetResponse` looks like:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-execute-listener]
--------------------------------------------------
<1> Called when the execution is successfully completed. The response is
provided as an argument.
<2> Called in case of failure. The raised exception is provided as an argument.
include::../execution.asciidoc[]
Loading