diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java index 407ee7a390a9..b47f6092c020 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java @@ -743,8 +743,8 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { openRequest.keepAlive(TimeValue.timeValueMinutes(30)); // <2> OpenPointInTimeResponse openResponse = client.openPointInTime(openRequest, RequestOptions.DEFAULT); String pitId = openResponse.getPointInTimeId(); // <3> - assertNotNull(pitId); // end::open-point-in-time + assertNotNull(pitId); // tag::search-point-in-time SearchRequest searchRequest = new SearchRequest(); @@ -752,14 +752,15 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { pointInTimeBuilder.setKeepAlive("2m"); // <2> searchRequest.source(new SearchSourceBuilder().pointInTimeBuilder(pointInTimeBuilder)); // <3> SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - assertThat(searchResponse.pointInTimeId(), equalTo(pitId)); // end::search-point-in-time + assertThat(searchResponse.pointInTimeId(), equalTo(pitId)); // tag::close-point-in-time ClosePointInTimeRequest closeRequest = new ClosePointInTimeRequest(pitId); // <1> ClearScrollResponse closeResponse = client.closePointInTime(closeRequest, RequestOptions.DEFAULT); - assertTrue(closeResponse.isSucceeded()); + boolean succeeded = closeResponse.isSucceeded(); // end::close-point-in-time + assertTrue(succeeded); // Open a point in time with optional arguments { @@ -770,7 +771,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { // tag::open-point-in-time-routing openRequest.routing("routing"); // <1> - // end::explain-request-routing + // end::open-point-in-time-routing // tag::open-point-in-time-preference openRequest.preference("_local"); // <1> @@ -782,45 +783,6 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { } } - public void testSearchAfterWithPointInTime() throws Exception { - RestHighLevelClient client = highLevelClient(); - int numDocs = between(50, 100); - BulkRequest request = new BulkRequest(); - for (int i = 0; i < numDocs; i++) { - request.add(new IndexRequest("posts").id(Integer.toString(i)).source(XContentType.JSON, "field", i)); - } - request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - - // tag::search-after-with-point-in-time - OpenPointInTimeRequest openRequest = new OpenPointInTimeRequest("posts"); - openRequest.keepAlive(TimeValue.timeValueMinutes(20)); - String pitId = client.openPointInTime(openRequest, RequestOptions.DEFAULT).getPointInTimeId(); // <1> - assertNotNull(pitId); - - SearchResponse searchResponse = null; - int totalHits = 0; - do { - SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder().sort("field").size(5)); // <2> - if (searchResponse != null) { - final SearchHit[] lastHits = searchResponse.getHits().getHits(); - searchRequest.source().searchAfter(lastHits[lastHits.length - 1].getSortValues()); // <3> - } - searchRequest.source().pointInTimeBuilder(new PointInTimeBuilder(pitId)); // <4> - searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - assertThat(searchResponse.pointInTimeId(), equalTo(pitId)); - totalHits += searchResponse.getHits().getHits().length; - } while (searchResponse.getHits().getHits().length > 0); - - assertThat(totalHits, equalTo(numDocs)); - - ClearScrollResponse closeResponse = client.closePointInTime(new ClosePointInTimeRequest(pitId), RequestOptions.DEFAULT); // <5> - assertTrue(closeResponse.isSucceeded()); - // end::search-after-with-point-in-time - } - public void testSearchTemplateWithInlineScript() throws Exception { indexSearchTestData(); RestHighLevelClient client = highLevelClient(); diff --git a/docs/java-rest/high-level/search/point-in-time.asciidoc b/docs/java-rest/high-level/search/point-in-time.asciidoc index 2663d162e1fe..f0321689dc7b 100644 --- a/docs/java-rest/high-level/search/point-in-time.asciidoc +++ b/docs/java-rest/high-level/search/point-in-time.asciidoc @@ -1,4 +1,4 @@ -[[java-rest-high-search-point-in-time]] +[[java-rest-high-point-in-time]] === Open a point in time @@ -53,19 +53,8 @@ include-tagged::{doc-tests}/SearchDocumentationIT.java[search-point-in-time] A search request with a point in time does not accept these parameters: `indices`, `indicesOptions` `routing`, `preference`, and `ccsMinimizeRoundtrips`. -==== Paginate search results with point in time A point in time can be used in search after requests to paginate search results. -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-after-with-point-in-time] --------------------------------------------------- -<1> Open a point in time that will be used in multiple search_after requests -<2> Create a search request with the sort parameter -<3> Set the search_after parameter using the sort values from the previous page -<4> Pass a point in time to a search request -<5> Close the point in time - === Close point in time Point in time should be closed as soon as they are no longer used in search requests. diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index e38dc3b6a25d..bb12bad0d34b 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -60,6 +60,7 @@ The Java High Level REST Client supports the following Search APIs: * <<{upid}-rank-eval>> * <<{upid}-explain>> * <<{upid}-count>> +* <<{upid}-point-in-time>> include::search/search.asciidoc[] include::search/scroll.asciidoc[] @@ -70,6 +71,7 @@ include::search/field-caps.asciidoc[] include::search/rank-eval.asciidoc[] include::search/explain.asciidoc[] include::search/count.asciidoc[] +include::search/point-in-time.asciidoc[] [role="xpack"] == Async Search APIs