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 @@ -932,6 +932,49 @@ public void onFailure(Exception e) {
}
}

public void testExists() throws Exception {
RestHighLevelClient client = highLevelClient();
// tag::exists-request
GetRequest getRequest = new GetRequest(
"posts", // <1>
"doc", // <2>
Copy link
Contributor

Choose a reason for hiding this comment

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

would "_doc" be better here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it makes a difference to be honest.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it does not ;)
I was thinking of #27816 and #27751 ( Docs should use _doc as a type name whenever possible ). I do not think that it is consistently done in the docs for the high level client though. Just a thought ...

"1"); // <3>
getRequest.fetchSourceContext(new FetchSourceContext(false)); // <4>
getRequest.storedFields("_none_"); // <5>
// end::exists-request
{
// tag::exists-execute
boolean exists = client.exists(getRequest);
// end::exists-execute
assertFalse(exists);
}
{
// tag::exists-execute-listener
ActionListener<Boolean> listener = new ActionListener<Boolean>() {
@Override
public void onResponse(Boolean exists) {
// <1>
}

@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::exists-execute-listener

// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);

// tag::exists-execute-async
client.existsAsync(getRequest, listener); // <1>
// end::exists-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
}

public void testBulkProcessor() throws InterruptedException {
RestHighLevelClient client = highLevelClient();
{
Expand Down
60 changes: 60 additions & 0 deletions docs/java-rest/high-level/document/exists.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[[java-rest-high-document-exists]]
=== Exists API

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

[[java-rest-high-document-exists-request]]
==== Exists Request

It uses `GetRequest` 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]
--------------------------------------------------
<1> Index
<2> Type
<3> Document id
<4> Disable fetching `_source`.
<5> Disable fetching stored fields.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm... I would say with . or without . for all? What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I put the . because these are sentences and the ones above aren't.


[[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.
1 change: 1 addition & 0 deletions docs/java-rest/high-level/document/get.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request]
<2> Type
<3> Document id

[[java-rest-high-document-get-request-optional-arguments]]
==== Optional arguments
The following arguments can optionally be provided:

Expand Down
1 change: 1 addition & 0 deletions docs/java-rest/high-level/supported-apis.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Multi-document APIs::

include::document/index.asciidoc[]
include::document/get.asciidoc[]
include::document/exists.asciidoc[]
include::document/delete.asciidoc[]
include::document/update.asciidoc[]
include::document/bulk.asciidoc[]
Expand Down