diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/AsyncSearchDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/AsyncSearchDocumentationIT.java deleted file mode 100644 index 365760a2b7f1..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/AsyncSearchDocumentationIT.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.asyncsearch.AsyncSearchResponse; -import org.elasticsearch.client.asyncsearch.DeleteAsyncSearchRequest; -import org.elasticsearch.client.asyncsearch.GetAsyncSearchRequest; -import org.elasticsearch.client.asyncsearch.SubmitAsyncSearchRequest; -import org.elasticsearch.client.core.AcknowledgedResponse; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.CreateIndexResponse; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.junit.Before; - -import java.io.IOException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * Documentation for Async Search APIs in the high level java client. - * Code wrapped in {@code tag} and {@code end} tags is included in the docs. - */ -@SuppressWarnings("removal") -public class AsyncSearchDocumentationIT extends ESRestHighLevelClientTestCase { - - @Before - void setUpIndex() throws IOException { - CreateIndexResponse createIndexResponse = highLevelClient().indices() - .create(new CreateIndexRequest("my-index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - public void testSubmitAsyncSearch() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::asyncsearch-submit-request - SearchSourceBuilder searchSource = new SearchSourceBuilder() - .query(QueryBuilders.matchAllQuery()); // <1> - String[] indices = new String[] { "my-index" }; // <2> - SubmitAsyncSearchRequest request - = new SubmitAsyncSearchRequest(searchSource, indices); - // end::asyncsearch-submit-request - - // tag::asyncsearch-submit-request-arguments - request.setWaitForCompletionTimeout(TimeValue.timeValueSeconds(30)); // <1> - request.setKeepAlive(TimeValue.timeValueMinutes(15)); // <2> - request.setKeepOnCompletion(false); // <3> - // end::asyncsearch-submit-request-arguments - - // tag::asyncsearch-submit-execute - AsyncSearchResponse response = client.asyncSearch() - .submit(request, RequestOptions.DEFAULT); // <1> - // end::asyncsearch-submit-execute - - assertNotNull(response); - assertNull(response.getFailure()); - - // tag::asyncsearch-submit-response - response.getSearchResponse(); // <1> - response.getId(); // <2> - response.isPartial(); // <3> - response.isRunning(); // <4> - response.getStartTime(); // <5> - response.getExpirationTime(); // <6> - response.getFailure(); // <7> - // end::asyncsearch-submit-response - - // tag::asyncsearch-submit-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AsyncSearchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::asyncsearch-submit-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::asyncsearch-submit-execute-async - client.asyncSearch() - .submitAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::asyncsearch-submit-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetAsyncSearch() throws Exception { - RestHighLevelClient client = highLevelClient(); - SearchSourceBuilder searchSource = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()); - String[] indices = new String[] { "my-index" }; - SubmitAsyncSearchRequest submitRequest = new SubmitAsyncSearchRequest(searchSource, indices); - submitRequest.setKeepOnCompletion(true); - AsyncSearchResponse submitResponse = client.asyncSearch().submit(submitRequest, RequestOptions.DEFAULT); - String id = submitResponse.getId(); - - // tag::asyncsearch-get-request - GetAsyncSearchRequest request = new GetAsyncSearchRequest(id); - // end::asyncsearch-get-request - - // tag::asyncsearch-get-request-arguments - request.setWaitForCompletion(TimeValue.timeValueSeconds(30)); // <1> - request.setKeepAlive(TimeValue.timeValueMinutes(15)); // <2> - // end::asyncsearch-get-request-arguments - - // tag::asyncsearch-get-execute - AsyncSearchResponse response = client.asyncSearch() - .get(request, RequestOptions.DEFAULT); // <1> - // end::asyncsearch-get-execute - - assertNotNull(response); - assertNull(response.getFailure()); - - // tag::asyncsearch-get-response - response.getSearchResponse(); // <1> - response.getId(); // <2> - response.isPartial(); // <3> - response.isRunning(); // <4> - response.getStartTime(); // <5> - response.getExpirationTime(); // <6> - response.getFailure(); // <7> - // end::asyncsearch-get-response - - // tag::asyncsearch-get-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AsyncSearchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::asyncsearch-get-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::asyncsearch-get-execute-async - client.asyncSearch() - .getAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::asyncsearch-get-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - client.asyncSearch().delete(new DeleteAsyncSearchRequest(id), RequestOptions.DEFAULT); - } - - @SuppressWarnings("unused") - public void testDeleteAsyncSearch() throws Exception { - RestHighLevelClient client = highLevelClient(); - SearchSourceBuilder searchSource = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()); - String[] indices = new String[] { "my-index" }; - SubmitAsyncSearchRequest submitRequest = new SubmitAsyncSearchRequest(searchSource, indices); - submitRequest.setKeepOnCompletion(true); - AsyncSearchResponse submitResponse = client.asyncSearch().submit(submitRequest, RequestOptions.DEFAULT); - String id = submitResponse.getId(); - - // tag::asyncsearch-delete-request - DeleteAsyncSearchRequest request = new DeleteAsyncSearchRequest(id); - // end::asyncsearch-delete-request - - // tag::asyncsearch-delete-execute - AcknowledgedResponse response = client.asyncSearch() // <1> - .delete(new DeleteAsyncSearchRequest(id), - RequestOptions.DEFAULT); - // end::asyncsearch-delete-execute - - assertNotNull(response); - assertTrue(response.isAcknowledged()); - - // tag::asyncsearch-delete-response - response.isAcknowledged(); // <1> - // end::asyncsearch-delete-response - - // tag::asyncsearch-delete-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::asyncsearch-delete-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::asyncsearch-delete-execute-async - client.asyncSearch() - .deleteAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::asyncsearch-delete-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java deleted file mode 100644 index f015863f0053..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java +++ /dev/null @@ -1,970 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.support.ActiveShardCount; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.ccr.AutoFollowStats; -import org.elasticsearch.client.ccr.CcrStatsRequest; -import org.elasticsearch.client.ccr.CcrStatsResponse; -import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest; -import org.elasticsearch.client.ccr.FollowInfoRequest; -import org.elasticsearch.client.ccr.FollowInfoResponse; -import org.elasticsearch.client.ccr.FollowStatsRequest; -import org.elasticsearch.client.ccr.FollowStatsResponse; -import org.elasticsearch.client.ccr.ForgetFollowerRequest; -import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest; -import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse; -import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse.Pattern; -import org.elasticsearch.client.ccr.IndicesFollowStats; -import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest; -import org.elasticsearch.client.ccr.PauseFollowRequest; -import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest; -import org.elasticsearch.client.ccr.PutFollowRequest; -import org.elasticsearch.client.ccr.PutFollowResponse; -import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest; -import org.elasticsearch.client.ccr.ResumeFollowRequest; -import org.elasticsearch.client.ccr.UnfollowRequest; -import org.elasticsearch.client.core.AcknowledgedResponse; -import org.elasticsearch.client.core.BroadcastResponse; -import org.elasticsearch.client.indices.CloseIndexRequest; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.CreateIndexResponse; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.test.rest.yaml.ObjectPath; -import org.junit.Before; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.is; - -@SuppressWarnings("removal") -public class CCRDocumentationIT extends ESRestHighLevelClientTestCase { - - @Before - public void setupRemoteClusterConfig() throws Exception { - setupRemoteClusterConfig("local"); - } - - public void testPutFollow() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // Create leader index: - CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader"); - CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), is(true)); - } - - // tag::ccr-put-follow-request - PutFollowRequest putFollowRequest = new PutFollowRequest( - "local", // <1> - "leader", // <2> - "follower", // <3> - ActiveShardCount.ONE // <4> - ); - Settings settings = - Settings.builder().put("index.number_of_replicas", 0L).build(); - putFollowRequest.setSettings(settings); // <5> - // end::ccr-put-follow-request - - // tag::ccr-put-follow-execute - PutFollowResponse putFollowResponse = - client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - // end::ccr-put-follow-execute - - // tag::ccr-put-follow-response - boolean isFollowIndexCreated = - putFollowResponse.isFollowIndexCreated(); // <1> - boolean isFollowIndexShardsAcked = - putFollowResponse.isFollowIndexShardsAcked(); // <2> - boolean isIndexFollowingStarted = - putFollowResponse.isIndexFollowingStarted(); // <3> - // end::ccr-put-follow-response - - // Pause following and delete follower index, so that we can execute put follow api again: - { - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower"); - AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(pauseFollowResponse.isAcknowledged(), is(true)); - - DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("follower"); - assertThat(client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true)); - } - - // tag::ccr-put-follow-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(PutFollowResponse response) { // <1> - boolean isFollowIndexCreated = - putFollowResponse.isFollowIndexCreated(); - boolean isFollowIndexShardsAcked = - putFollowResponse.isFollowIndexShardsAcked(); - boolean isIndexFollowingStarted = - putFollowResponse.isIndexFollowingStarted(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-put-follow-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-put-follow-execute-async - client.ccr().putFollowAsync(putFollowRequest, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-put-follow-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - { - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower"); - AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(pauseFollowResponse.isAcknowledged(), is(true)); - } - } - - public void testPauseFollow() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // Create leader index: - CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader"); - CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), is(true)); - } - String followIndex = "follower"; - // Follow index, so that it can be paused: - { - PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE); - PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - assertThat(putFollowResponse.isFollowIndexCreated(), is(true)); - assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true)); - assertThat(putFollowResponse.isIndexFollowingStarted(), is(true)); - } - - // tag::ccr-pause-follow-request - PauseFollowRequest request = new PauseFollowRequest(followIndex); // <1> - // end::ccr-pause-follow-request - - // tag::ccr-pause-follow-execute - AcknowledgedResponse response = - client.ccr().pauseFollow(request, RequestOptions.DEFAULT); - // end::ccr-pause-follow-execute - - // tag::ccr-pause-follow-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ccr-pause-follow-response - - // tag::ccr-pause-follow-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-pause-follow-execute-listener - - // Resume follow index, so that it can be paused again: - { - ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest(followIndex); - AcknowledgedResponse resumeResponse = client.ccr().resumeFollow(resumeFollowRequest, RequestOptions.DEFAULT); - assertThat(resumeResponse.isAcknowledged(), is(true)); - } - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-pause-follow-execute-async - client.ccr() - .pauseFollowAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::ccr-pause-follow-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testResumeFollow() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // Create leader index: - CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader"); - CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), is(true)); - } - String followIndex = "follower"; - // Follow index, so that it can be paused: - { - PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE); - PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - assertThat(putFollowResponse.isFollowIndexCreated(), is(true)); - assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true)); - assertThat(putFollowResponse.isIndexFollowingStarted(), is(true)); - } - - // Pause follow index, so that it can be resumed: - { - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex); - AcknowledgedResponse pauseResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(pauseResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-resume-follow-request - ResumeFollowRequest request = new ResumeFollowRequest(followIndex); // <1> - // end::ccr-resume-follow-request - - // tag::ccr-resume-follow-execute - AcknowledgedResponse response = - client.ccr().resumeFollow(request, RequestOptions.DEFAULT); - // end::ccr-resume-follow-execute - - // tag::ccr-resume-follow-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ccr-resume-follow-response - - // Pause follow index, so that it can be resumed again: - { - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex); - AcknowledgedResponse pauseResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(pauseResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-resume-follow-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-resume-follow-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-resume-follow-execute-async - client.ccr() - .resumeFollowAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::ccr-resume-follow-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // Cleanup: - client.ccr().pauseFollow(new PauseFollowRequest(followIndex), RequestOptions.DEFAULT); - } - - public void testUnfollow() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // Create leader index: - CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader"); - CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), is(true)); - } - String followIndex = "follower"; - // Follow index, pause and close, so that it can be unfollowed: - { - PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE); - PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - assertThat(putFollowResponse.isFollowIndexCreated(), is(true)); - assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true)); - assertThat(putFollowResponse.isIndexFollowingStarted(), is(true)); - - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex); - AcknowledgedResponse unfollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(unfollowResponse.isAcknowledged(), is(true)); - - CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followIndex); - assertThat(client.indices().close(closeIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true)); - } - - // tag::ccr-unfollow-request - UnfollowRequest request = new UnfollowRequest(followIndex); // <1> - // end::ccr-unfollow-request - - // tag::ccr-unfollow-execute - AcknowledgedResponse response = - client.ccr().unfollow(request, RequestOptions.DEFAULT); - // end::ccr-unfollow-execute - - // tag::ccr-unfollow-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ccr-unfollow-response - - // Delete, put follow index, pause and close, so that it can be unfollowed again: - { - DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(followIndex); - assertThat(client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true)); - - PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE); - PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - assertThat(putFollowResponse.isFollowIndexCreated(), is(true)); - assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true)); - assertThat(putFollowResponse.isIndexFollowingStarted(), is(true)); - - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex); - AcknowledgedResponse unfollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(unfollowResponse.isAcknowledged(), is(true)); - - CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followIndex); - assertThat(client.indices().close(closeIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true)); - } - - // tag::ccr-unfollow-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-unfollow-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-unfollow-execute-async - client.ccr() - .unfollowAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::ccr-unfollow-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testForgetFollower() throws InterruptedException, IOException { - final RestHighLevelClient client = highLevelClient(); - final String leaderIndex = "leader"; - { - // create leader index - final CreateIndexRequest createIndexRequest = new CreateIndexRequest(leaderIndex); - final Map settings = new HashMap<>(2); - final int numberOfShards = randomIntBetween(1, 2); - settings.put("index.number_of_shards", Integer.toString(numberOfShards)); - createIndexRequest.settings(settings); - final CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), is(true)); - } - final String followerIndex = "follower"; - - final PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followerIndex, ActiveShardCount.ONE); - final PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - assertTrue(putFollowResponse.isFollowIndexCreated()); - assertTrue((putFollowResponse.isFollowIndexShardsAcked())); - assertTrue(putFollowResponse.isIndexFollowingStarted()); - - final PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower"); - AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertTrue(pauseFollowResponse.isAcknowledged()); - - final String followerCluster = highLevelClient().info(RequestOptions.DEFAULT).getClusterName(); - final Request statsRequest = new Request("GET", "/follower/_stats"); - final Response statsResponse = client().performRequest(statsRequest); - final ObjectPath statsObjectPath = ObjectPath.createFromResponse(statsResponse); - final String followerIndexUUID = statsObjectPath.evaluate("indices.follower.uuid"); - - final String leaderCluster = "local"; - - // tag::ccr-forget-follower-request - final ForgetFollowerRequest request = new ForgetFollowerRequest( - followerCluster, // <1> - followerIndex, // <2> - followerIndexUUID, // <3> - leaderCluster, // <4> - leaderIndex); // <5> - // end::ccr-forget-follower-request - - // tag::ccr-forget-follower-execute - final BroadcastResponse response = client - .ccr() - .forgetFollower(request, RequestOptions.DEFAULT); - // end::ccr-forget-follower-execute - - // tag::ccr-forget-follower-response - final BroadcastResponse.Shards shards = response.shards(); // <1> - final int total = shards.total(); // <2> - final int successful = shards.successful(); // <3> - final int skipped = shards.skipped(); // <4> - final int failed = shards.failed(); // <5> - shards.failures().forEach(failure -> {}); // <6> - // end::ccr-forget-follower-response - - // tag::ccr-forget-follower-execute-listener - ActionListener listener = - new ActionListener() { - - @Override - public void onResponse(final BroadcastResponse response) { - final BroadcastResponse.Shards shards = // <1> - response.shards(); - final int total = shards.total(); - final int successful = shards.successful(); - final int skipped = shards.skipped(); - final int failed = shards.failed(); - shards.failures().forEach(failure -> {}); - } - - @Override - public void onFailure(final Exception e) { - // <2> - } - - }; - // end::ccr-forget-follower-execute-listener - - // replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-forget-follower-execute-async - client.ccr().forgetFollowerAsync( - request, - RequestOptions.DEFAULT, - listener); // <1> - // end::ccr-forget-follower-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testPutAutoFollowPattern() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::ccr-put-auto-follow-pattern-request - PutAutoFollowPatternRequest request = - new PutAutoFollowPatternRequest( - "my_pattern", // <1> - "local", // <2> - Arrays.asList("logs-*", "metrics-*"), // <3> - Arrays.asList("logs-excluded", "metrics-excluded") // <4> - ); - request.setFollowIndexNamePattern("copy-{{leader_index}}"); // <5> - Settings settings = - Settings.builder().put("index.number_of_replicas", 0L).build(); - request.setSettings(settings); // <6> - // end::ccr-put-auto-follow-pattern-request - - // tag::ccr-put-auto-follow-pattern-execute - AcknowledgedResponse response = client.ccr() - .putAutoFollowPattern(request, RequestOptions.DEFAULT); - // end::ccr-put-auto-follow-pattern-execute - - // tag::ccr-put-auto-follow-pattern-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ccr-put-auto-follow-pattern-response - - // Delete auto follow pattern, so that we can store it again: - { - final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern"); - AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT); - assertThat(deleteResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-put-auto-follow-pattern-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { // <1> - boolean acknowledged = response.isAcknowledged(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-put-auto-follow-pattern-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-put-auto-follow-pattern-execute-async - client.ccr().putAutoFollowPatternAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-put-auto-follow-pattern-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // Cleanup: - { - final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern"); - AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT); - assertThat(deleteResponse.isAcknowledged(), is(true)); - } - } - - public void testDeleteAutoFollowPattern() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // Put auto follow pattern, so that we can delete it: - { - final PutAutoFollowPatternRequest putRequest = new PutAutoFollowPatternRequest( - "my_pattern", - "local", - Collections.singletonList("logs-*") - ); - AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT); - assertThat(putResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-delete-auto-follow-pattern-request - DeleteAutoFollowPatternRequest request = - new DeleteAutoFollowPatternRequest("my_pattern"); // <1> - // end::ccr-delete-auto-follow-pattern-request - - // tag::ccr-delete-auto-follow-pattern-execute - AcknowledgedResponse response = client.ccr() - .deleteAutoFollowPattern(request, RequestOptions.DEFAULT); - // end::ccr-delete-auto-follow-pattern-execute - - // tag::ccr-delete-auto-follow-pattern-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ccr-delete-auto-follow-pattern-response - - // Put auto follow pattern, so that we can delete it again: - { - final PutAutoFollowPatternRequest putRequest = new PutAutoFollowPatternRequest( - "my_pattern", - "local", - Collections.singletonList("logs-*") - ); - AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT); - assertThat(putResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-delete-auto-follow-pattern-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { // <1> - boolean acknowledged = response.isAcknowledged(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-delete-auto-follow-pattern-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-delete-auto-follow-pattern-execute-async - client.ccr().deleteAutoFollowPatternAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-delete-auto-follow-pattern-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetAutoFollowPattern() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // Put auto follow pattern, so that we can get it: - { - final PutAutoFollowPatternRequest putRequest = new PutAutoFollowPatternRequest( - "my_pattern", - "local", - Collections.singletonList("logs-*") - ); - AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT); - assertThat(putResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-get-auto-follow-pattern-request - GetAutoFollowPatternRequest request = - new GetAutoFollowPatternRequest("my_pattern"); // <1> - // end::ccr-get-auto-follow-pattern-request - - // tag::ccr-get-auto-follow-pattern-execute - GetAutoFollowPatternResponse response = client.ccr() - .getAutoFollowPattern(request, RequestOptions.DEFAULT); - // end::ccr-get-auto-follow-pattern-execute - - // tag::ccr-get-auto-follow-pattern-response - Map patterns = response.getPatterns(); - Pattern pattern = patterns.get("my_pattern"); // <1> - pattern.getLeaderIndexPatterns(); - // end::ccr-get-auto-follow-pattern-response - - // tag::ccr-get-auto-follow-pattern-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetAutoFollowPatternResponse - response) { // <1> - Map patterns = response.getPatterns(); - Pattern pattern = patterns.get("my_pattern"); - pattern.getLeaderIndexPatterns(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-get-auto-follow-pattern-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-get-auto-follow-pattern-execute-async - client.ccr().getAutoFollowPatternAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-get-auto-follow-pattern-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // Cleanup: - { - DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern"); - AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT); - assertThat(deleteResponse.isAcknowledged(), is(true)); - } - } - - public void testPauseAutoFollowPattern() throws Exception { - final RestHighLevelClient client = highLevelClient(); - { - final PutAutoFollowPatternRequest putRequest = new PutAutoFollowPatternRequest("my_pattern", "local", List.of("logs-*")); - AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT); - assertThat(putResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-pause-auto-follow-pattern-request - PauseAutoFollowPatternRequest request = - new PauseAutoFollowPatternRequest("my_pattern"); // <1> - // end::ccr-pause-auto-follow-pattern-request - - // tag::ccr-pause-auto-follow-pattern-execute - AcknowledgedResponse response = client.ccr() - .pauseAutoFollowPattern(request, RequestOptions.DEFAULT); - // end::ccr-pause-auto-follow-pattern-execute - - // tag::ccr-pause-auto-follow-pattern-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ccr-pause-auto-follow-pattern-response - - // tag::ccr-pause-auto-follow-pattern-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { // <1> - boolean paused = response.isAcknowledged(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-pause-auto-follow-pattern-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-pause-auto-follow-pattern-execute-async - client.ccr().pauseAutoFollowPatternAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-pause-auto-follow-pattern-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // Cleanup: - { - DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern"); - AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT); - assertThat(deleteResponse.isAcknowledged(), is(true)); - } - } - - public void testResumeAutoFollowPattern() throws Exception { - final RestHighLevelClient client = highLevelClient(); - { - final PutAutoFollowPatternRequest putRequest = new PutAutoFollowPatternRequest("my_pattern", "local", List.of("logs-*")); - AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT); - assertThat(putResponse.isAcknowledged(), is(true)); - - final PauseAutoFollowPatternRequest pauseRequest = new PauseAutoFollowPatternRequest("my_pattern"); - AcknowledgedResponse pauseResponse = client.ccr().pauseAutoFollowPattern(pauseRequest, RequestOptions.DEFAULT); - assertThat(pauseResponse.isAcknowledged(), is(true)); - } - - // tag::ccr-resume-auto-follow-pattern-request - ResumeAutoFollowPatternRequest request = - new ResumeAutoFollowPatternRequest("my_pattern"); // <1> - // end::ccr-resume-auto-follow-pattern-request - - // tag::ccr-resume-auto-follow-pattern-execute - AcknowledgedResponse response = client.ccr() - .resumeAutoFollowPattern(request, RequestOptions.DEFAULT); - // end::ccr-resume-auto-follow-pattern-execute - - // tag::ccr-resume-auto-follow-pattern-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ccr-resume-auto-follow-pattern-response - - // tag::ccr-resume-auto-follow-pattern-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { // <1> - boolean resumed = response.isAcknowledged(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-resume-auto-follow-pattern-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-resume-auto-follow-pattern-execute-async - client.ccr().resumeAutoFollowPatternAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-resume-auto-follow-pattern-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // Cleanup: - { - DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern"); - AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT); - assertThat(deleteResponse.isAcknowledged(), is(true)); - } - } - - public void testGetCCRStats() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::ccr-get-stats-request - CcrStatsRequest request = - new CcrStatsRequest(); // <1> - // end::ccr-get-stats-request - - // tag::ccr-get-stats-execute - CcrStatsResponse response = client.ccr() - .getCcrStats(request, RequestOptions.DEFAULT); - // end::ccr-get-stats-execute - - // tag::ccr-get-stats-response - IndicesFollowStats indicesFollowStats = - response.getIndicesFollowStats(); // <1> - AutoFollowStats autoFollowStats = - response.getAutoFollowStats(); // <2> - // end::ccr-get-stats-response - - // tag::ccr-get-stats-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(CcrStatsResponse response) { // <1> - IndicesFollowStats indicesFollowStats = - response.getIndicesFollowStats(); - AutoFollowStats autoFollowStats = - response.getAutoFollowStats(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-get-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-get-stats-execute-async - client.ccr().getCcrStatsAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-get-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetFollowStats() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // Create leader index: - CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader"); - CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), is(true)); - } - { - // Follow index, so that we can query for follow stats: - PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", "follower", ActiveShardCount.ONE); - PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - assertThat(putFollowResponse.isFollowIndexCreated(), is(true)); - assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true)); - assertThat(putFollowResponse.isIndexFollowingStarted(), is(true)); - } - - // tag::ccr-get-follow-stats-request - FollowStatsRequest request = - new FollowStatsRequest("follower"); // <1> - // end::ccr-get-follow-stats-request - - // tag::ccr-get-follow-stats-execute - FollowStatsResponse response = client.ccr() - .getFollowStats(request, RequestOptions.DEFAULT); - // end::ccr-get-follow-stats-execute - - // tag::ccr-get-follow-stats-response - IndicesFollowStats indicesFollowStats = - response.getIndicesFollowStats(); // <1> - // end::ccr-get-follow-stats-response - - // tag::ccr-get-follow-stats-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(FollowStatsResponse response) { // <1> - IndicesFollowStats indicesFollowStats = - response.getIndicesFollowStats(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-get-follow-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-get-follow-stats-execute-async - client.ccr().getFollowStatsAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-get-follow-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - { - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower"); - AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(pauseFollowResponse.isAcknowledged(), is(true)); - } - } - - public void testGetFollowInfos() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // Create leader index: - CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader"); - CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), is(true)); - } - { - // Follow index, so that we can query for follow stats: - PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", "follower", ActiveShardCount.ONE); - PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT); - assertThat(putFollowResponse.isFollowIndexCreated(), is(true)); - assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true)); - assertThat(putFollowResponse.isIndexFollowingStarted(), is(true)); - } - - // tag::ccr-get-follow-info-request - FollowInfoRequest request = - new FollowInfoRequest("follower"); // <1> - // end::ccr-get-follow-info-request - - // tag::ccr-get-follow-info-execute - FollowInfoResponse response = client.ccr() - .getFollowInfo(request, RequestOptions.DEFAULT); - // end::ccr-get-follow-info-execute - - // tag::ccr-get-follow-info-response - List infos = - response.getInfos(); // <1> - // end::ccr-get-follow-info-response - - // tag::ccr-get-follow-info-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(FollowInfoResponse response) { // <1> - List infos = - response.getInfos(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ccr-get-follow-info-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ccr-get-follow-info-execute-async - client.ccr().getFollowInfoAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ccr-get-follow-info-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - { - PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower"); - AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT); - assertThat(pauseFollowResponse.isAcknowledged(), is(true)); - } - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java deleted file mode 100644 index 9bcdcc72a02c..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ /dev/null @@ -1,2039 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.apache.http.HttpHost; -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.DocWriteRequest; -import org.elasticsearch.action.DocWriteResponse; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; -import org.elasticsearch.action.bulk.BackoffPolicy; -import org.elasticsearch.action.bulk.BulkItemResponse; -import org.elasticsearch.action.bulk.BulkProcessor; -import org.elasticsearch.action.bulk.BulkRequest; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.delete.DeleteRequest; -import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.get.GetRequest; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequest; -import org.elasticsearch.action.get.MultiGetResponse; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.support.ActiveShardCount; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.WriteRequest; -import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; -import org.elasticsearch.action.support.replication.ReplicationResponse; -import org.elasticsearch.action.update.UpdateRequest; -import org.elasticsearch.action.update.UpdateResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.RethrottleRequest; -import org.elasticsearch.client.core.GetSourceRequest; -import org.elasticsearch.client.core.GetSourceResponse; -import org.elasticsearch.client.core.MultiTermVectorsRequest; -import org.elasticsearch.client.core.MultiTermVectorsResponse; -import org.elasticsearch.client.core.TermVectorsRequest; -import org.elasticsearch.client.core.TermVectorsResponse; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.CreateIndexResponse; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.VersionType; -import org.elasticsearch.index.get.GetResult; -import org.elasticsearch.index.query.MatchAllQueryBuilder; -import org.elasticsearch.index.query.TermQueryBuilder; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.elasticsearch.index.reindex.DeleteByQueryRequest; -import org.elasticsearch.index.reindex.ReindexRequest; -import org.elasticsearch.index.reindex.RemoteInfo; -import org.elasticsearch.index.reindex.ScrollableHitSource; -import org.elasticsearch.index.reindex.UpdateByQueryRequest; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptType; -import org.elasticsearch.search.fetch.subphase.FetchSourceContext; -import org.elasticsearch.tasks.TaskId; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentFactory; -import org.elasticsearch.xcontent.XContentType; -import org.elasticsearch.xcontent.json.JsonXContent; - -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static java.util.Collections.singletonMap; -import static org.hamcrest.Matchers.arrayWithSize; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.Matchers.hasKey; -import static org.hamcrest.Matchers.not; - -/** - * Documentation for CRUD APIs in the high level java client. - * Code wrapped in {@code tag} and {@code end} tags is included in the docs. - */ -@SuppressWarnings("removal") -public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { - - @SuppressWarnings("unused") - public void testIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - //tag::index-request-map - Map jsonMap = new HashMap<>(); - jsonMap.put("user", "kimchy"); - jsonMap.put("postDate", new Date()); - jsonMap.put("message", "trying out Elasticsearch"); - IndexRequest indexRequest = new IndexRequest("posts") - .id("1").source(jsonMap); // <1> - //end::index-request-map - IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult()); - } - { - //tag::index-request-xcontent - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.field("user", "kimchy"); - builder.timeField("postDate", new Date()); - builder.field("message", "trying out Elasticsearch"); - } - builder.endObject(); - IndexRequest indexRequest = new IndexRequest("posts") - .id("1").source(builder); // <1> - //end::index-request-xcontent - IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.UPDATED, indexResponse.getResult()); - } - { - //tag::index-request-shortcut - IndexRequest indexRequest = new IndexRequest("posts") - .id("1") - .source("user", "kimchy", - "postDate", new Date(), - "message", "trying out Elasticsearch"); // <1> - //end::index-request-shortcut - IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.UPDATED, indexResponse.getResult()); - } - { - //tag::index-request-string - IndexRequest request = new IndexRequest("posts"); // <1> - request.id("1"); // <2> - String jsonString = """ - { - "user": "kimchy", - "postDate": "2013-01-30", - "message": "trying out Elasticsearch" - } - """; - request.source(jsonString, XContentType.JSON); // <3> - //end::index-request-string - - // tag::index-execute - IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT); - // end::index-execute - assertEquals(DocWriteResponse.Result.UPDATED, indexResponse.getResult()); - - // tag::index-response - String index = indexResponse.getIndex(); - String id = indexResponse.getId(); - if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) { - // <1> - } else if (indexResponse.getResult() == DocWriteResponse.Result.UPDATED) { - // <2> - } - ReplicationResponse.ShardInfo shardInfo = indexResponse.getShardInfo(); - if (shardInfo.getTotal() != shardInfo.getSuccessful()) { - // <3> - } - if (shardInfo.getFailed() > 0) { - for (ReplicationResponse.ShardInfo.Failure failure : - shardInfo.getFailures()) { - String reason = failure.reason(); // <4> - } - } - // end::index-response - } - { - IndexRequest request = new IndexRequest("posts").id("1"); - // tag::index-request-routing - request.routing("routing"); // <1> - // end::index-request-routing - // tag::index-request-timeout - request.timeout(TimeValue.timeValueSeconds(1)); // <1> - request.timeout("1s"); // <2> - // end::index-request-timeout - // tag::index-request-refresh - request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); // <1> - request.setRefreshPolicy("wait_for"); // <2> - // end::index-request-refresh - // tag::index-request-version - request.version(2); // <1> - // end::index-request-version - // tag::index-request-version-type - request.versionType(VersionType.EXTERNAL); // <1> - // end::index-request-version-type - // tag::index-request-op-type - request.opType(DocWriteRequest.OpType.CREATE); // <1> - request.opType("create"); // <2> - // end::index-request-op-type - // tag::index-request-pipeline - request.setPipeline("pipeline"); // <1> - // end::index-request-pipeline - } - { - // tag::index-conflict - IndexRequest request = new IndexRequest("posts") - .id("1") - .source("field", "value") - .setIfSeqNo(10L) - .setIfPrimaryTerm(20); - try { - IndexResponse response = client.index(request, RequestOptions.DEFAULT); - } catch(ElasticsearchException e) { - if (e.status() == RestStatus.CONFLICT) { - // <1> - } - } - // end::index-conflict - } - { - // tag::index-optype - IndexRequest request = new IndexRequest("posts") - .id("1") - .source("field", "value") - .opType(DocWriteRequest.OpType.CREATE); - try { - IndexResponse response = client.index(request, RequestOptions.DEFAULT); - } catch(ElasticsearchException e) { - if (e.status() == RestStatus.CONFLICT) { - // <1> - } - } - // end::index-optype - } - { - IndexRequest request = new IndexRequest("posts").id("async").source("field", "value"); - ActionListener listener; - // tag::index-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(IndexResponse indexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::index-execute-async - client.indexAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testUpdate() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - IndexRequest indexRequest = new IndexRequest("posts").id("1").source("field", 0); - IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); - assertSame(RestStatus.CREATED, indexResponse.status()); - - Request request = new Request("POST", "/_scripts/increment-field"); - request.setJsonEntity( - Strings.toString( - JsonXContent.contentBuilder() - .startObject() - .startObject("script") - .field("lang", "painless") - .field("source", "ctx._source.field += params.count") - .endObject() - .endObject() - ) - ); - Response response = client().performRequest(request); - assertEquals(RestStatus.OK.getStatus(), response.getStatusLine().getStatusCode()); - } - { - //tag::update-request - UpdateRequest request = new UpdateRequest( - "posts", // <1> - "1"); // <2> - //end::update-request - request.fetchSource(true); - //tag::update-request-with-inline-script - Map parameters = singletonMap("count", 4); // <1> - - Script inline = new Script(ScriptType.INLINE, "painless", - "ctx._source.field += params.count", parameters); // <2> - request.script(inline); // <3> - //end::update-request-with-inline-script - UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); - assertEquals(4, updateResponse.getGetResult().getSource().get("field")); - - request = new UpdateRequest("posts", "1").fetchSource(true); - //tag::update-request-with-stored-script - 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); - assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); - assertEquals(8, updateResponse.getGetResult().getSource().get("field")); - } - { - //tag::update-request-with-doc-as-map - Map jsonMap = new HashMap<>(); - jsonMap.put("updated", new Date()); - jsonMap.put("reason", "daily update"); - UpdateRequest request = new UpdateRequest("posts", "1") - .doc(jsonMap); // <1> - //end::update-request-with-doc-as-map - UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); - } - { - //tag::update-request-with-doc-as-xcontent - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.timeField("updated", new Date()); - builder.field("reason", "daily update"); - } - builder.endObject(); - UpdateRequest request = new UpdateRequest("posts", "1") - .doc(builder); // <1> - //end::update-request-with-doc-as-xcontent - UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); - } - { - //tag::update-request-shortcut - UpdateRequest request = new UpdateRequest("posts", "1") - .doc("updated", new Date(), - "reason", "daily update"); // <1> - //end::update-request-shortcut - UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); - } - { - //tag::update-request-with-doc-as-string - UpdateRequest request = new UpdateRequest("posts", "1"); - String jsonString = "{" + - "\"updated\":\"2017-01-01\"," + - "\"reason\":\"daily update\"" + - "}"; - request.doc(jsonString, XContentType.JSON); // <1> - //end::update-request-with-doc-as-string - request.fetchSource(true); - // tag::update-execute - UpdateResponse updateResponse = client.update( - request, RequestOptions.DEFAULT); - // end::update-execute - assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); - - // tag::update-response - String index = updateResponse.getIndex(); - String id = updateResponse.getId(); - long version = updateResponse.getVersion(); - if (updateResponse.getResult() == DocWriteResponse.Result.CREATED) { - // <1> - } else if (updateResponse.getResult() == DocWriteResponse.Result.UPDATED) { - // <2> - } else if (updateResponse.getResult() == DocWriteResponse.Result.DELETED) { - // <3> - } else if (updateResponse.getResult() == DocWriteResponse.Result.NOOP) { - // <4> - } - // end::update-response - - // tag::update-getresult - GetResult result = updateResponse.getGetResult(); // <1> - if (result.isExists()) { - String sourceAsString = result.sourceAsString(); // <2> - Map sourceAsMap = result.sourceAsMap(); // <3> - byte[] sourceAsBytes = result.source(); // <4> - } else { - // <5> - } - // end::update-getresult - assertNotNull(result); - assertEquals(3, result.sourceAsMap().size()); - // tag::update-failure - ReplicationResponse.ShardInfo shardInfo = updateResponse.getShardInfo(); - if (shardInfo.getTotal() != shardInfo.getSuccessful()) { - // <1> - } - if (shardInfo.getFailed() > 0) { - for (ReplicationResponse.ShardInfo.Failure failure : - shardInfo.getFailures()) { - String reason = failure.reason(); // <2> - } - } - // end::update-failure - } - { - //tag::update-docnotfound - UpdateRequest request = new UpdateRequest("posts", "does_not_exist") - .doc("field", "value"); - try { - UpdateResponse updateResponse = client.update( - request, RequestOptions.DEFAULT); - } catch (ElasticsearchException e) { - if (e.status() == RestStatus.NOT_FOUND) { - // <1> - } - } - //end::update-docnotfound - } - { - // tag::update-conflict - UpdateRequest request = new UpdateRequest("posts", "1") - .doc("field", "value") - .setIfSeqNo(101L) - .setIfPrimaryTerm(200L); - try { - UpdateResponse updateResponse = client.update( - request, RequestOptions.DEFAULT); - } catch(ElasticsearchException e) { - if (e.status() == RestStatus.CONFLICT) { - // <1> - } - } - // end::update-conflict - } - { - UpdateRequest request = new UpdateRequest("posts", "1").doc("reason", "no source"); - //tag::update-request-no-source - request.fetchSource(true); // <1> - //end::update-request-no-source - UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); - assertNotNull(updateResponse.getGetResult()); - assertEquals(3, updateResponse.getGetResult().sourceAsMap().size()); - } - { - UpdateRequest request = new UpdateRequest("posts", "1").doc("reason", "source includes"); - //tag::update-request-source-include - String[] includes = new String[]{"updated", "r*"}; - String[] excludes = Strings.EMPTY_ARRAY; - 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()); - Map sourceAsMap = updateResponse.getGetResult().sourceAsMap(); - assertEquals(2, sourceAsMap.size()); - assertEquals("source includes", sourceAsMap.get("reason")); - assertTrue(sourceAsMap.containsKey("updated")); - } - { - UpdateRequest request = new UpdateRequest("posts", "1").doc("reason", "source excludes"); - //tag::update-request-source-exclude - String[] includes = Strings.EMPTY_ARRAY; - String[] excludes = new String[]{"updated"}; - 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()); - Map sourceAsMap = updateResponse.getGetResult().sourceAsMap(); - assertEquals(2, sourceAsMap.size()); - assertEquals("source excludes", sourceAsMap.get("reason")); - assertTrue(sourceAsMap.containsKey("field")); - } - { - UpdateRequest request = new UpdateRequest("posts", "id"); - // tag::update-request-routing - request.routing("routing"); // <1> - // end::update-request-routing - // tag::update-request-timeout - request.timeout(TimeValue.timeValueSeconds(1)); // <1> - request.timeout("1s"); // <2> - // end::update-request-timeout - // tag::update-request-retry - request.retryOnConflict(3); // <1> - // end::update-request-retry - // tag::update-request-refresh - request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); // <1> - request.setRefreshPolicy("wait_for"); // <2> - // end::update-request-refresh - // tag::update-request-cas - request.setIfSeqNo(2L); // <1> - request.setIfPrimaryTerm(1L); // <2> - // end::update-request-cas - // tag::update-request-detect-noop - request.detectNoop(false); // <1> - // end::update-request-detect-noop - // tag::update-request-upsert - String jsonString = "{\"created\":\"2017-01-01\"}"; - request.upsert(jsonString, XContentType.JSON); // <1> - // end::update-request-upsert - // tag::update-request-scripted-upsert - request.scriptedUpsert(true); // <1> - // end::update-request-scripted-upsert - // tag::update-request-doc-upsert - request.docAsUpsert(true); // <1> - // end::update-request-doc-upsert - // tag::update-request-active-shards - request.waitForActiveShards(2); // <1> - request.waitForActiveShards(ActiveShardCount.ALL); // <2> - // end::update-request-active-shards - } - { - UpdateRequest request = new UpdateRequest("posts", "async").doc("reason", "async update").docAsUpsert(true); - - ActionListener listener; - // tag::update-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(UpdateResponse updateResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-execute-async - client.updateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::update-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testDelete() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - IndexRequest indexRequest = new IndexRequest("posts").id("1").source("field", "value"); - IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); - assertSame(RestStatus.CREATED, indexResponse.status()); - } - - { - // tag::delete-request - DeleteRequest request = new DeleteRequest( - "posts", // <1> - "1"); // <2> - // end::delete-request - - // tag::delete-execute - DeleteResponse deleteResponse = client.delete( - request, RequestOptions.DEFAULT); - // end::delete-execute - assertSame(DocWriteResponse.Result.DELETED, deleteResponse.getResult()); - - // tag::delete-response - String index = deleteResponse.getIndex(); - String id = deleteResponse.getId(); - long version = deleteResponse.getVersion(); - ReplicationResponse.ShardInfo shardInfo = deleteResponse.getShardInfo(); - if (shardInfo.getTotal() != shardInfo.getSuccessful()) { - // <1> - } - if (shardInfo.getFailed() > 0) { - for (ReplicationResponse.ShardInfo.Failure failure : - shardInfo.getFailures()) { - String reason = failure.reason(); // <2> - } - } - // end::delete-response - } - - { - DeleteRequest request = new DeleteRequest("posts", "1"); - // tag::delete-request-routing - request.routing("routing"); // <1> - // end::delete-request-routing - // tag::delete-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::delete-request-timeout - // tag::delete-request-refresh - request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); // <1> - request.setRefreshPolicy("wait_for"); // <2> - // end::delete-request-refresh - // tag::delete-request-version - request.version(2); // <1> - // end::delete-request-version - // tag::delete-request-version-type - request.versionType(VersionType.EXTERNAL); // <1> - // end::delete-request-version-type - } - - { - // tag::delete-notfound - DeleteRequest request = new DeleteRequest("posts", "does_not_exist"); - DeleteResponse deleteResponse = client.delete( - request, RequestOptions.DEFAULT); - if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) { - // <1> - } - // end::delete-notfound - } - - { - IndexResponse indexResponse = client.index(new IndexRequest("posts").id("1").source("field", "value"), RequestOptions.DEFAULT); - assertSame(RestStatus.CREATED, indexResponse.status()); - - // tag::delete-conflict - try { - DeleteResponse deleteResponse = client.delete( - new DeleteRequest("posts", "1").setIfSeqNo(100).setIfPrimaryTerm(2), - RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.CONFLICT) { - // <1> - } - } - // end::delete-conflict - } - { - IndexResponse indexResponse = client.index( - new IndexRequest("posts").id("async").source("field", "value"), - RequestOptions.DEFAULT - ); - assertSame(RestStatus.CREATED, indexResponse.status()); - - DeleteRequest request = new DeleteRequest("posts", "async"); - - ActionListener listener; - // tag::delete-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(DeleteResponse deleteResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-execute-async - client.deleteAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testBulk() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // tag::bulk-request - BulkRequest request = new BulkRequest(); // <1> - request.add(new IndexRequest("posts").id("1") // <2> - .source(XContentType.JSON,"field", "foo")); - request.add(new IndexRequest("posts").id("2") // <3> - .source(XContentType.JSON,"field", "bar")); - request.add(new IndexRequest("posts").id("3") // <4> - .source(XContentType.JSON,"field", "baz")); - // end::bulk-request - // tag::bulk-execute - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - // end::bulk-execute - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - } - { - // tag::bulk-request-with-mixed-operations - BulkRequest request = new BulkRequest(); - request.add(new DeleteRequest("posts", "3")); // <1> - request.add(new UpdateRequest("posts", "2") // <2> - .doc(XContentType.JSON,"other", "test")); - request.add(new IndexRequest("posts").id("4") // <3> - .source(XContentType.JSON,"field", "baz")); - // end::bulk-request-with-mixed-operations - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - - // tag::bulk-response - for (BulkItemResponse bulkItemResponse : bulkResponse) { // <1> - DocWriteResponse itemResponse = bulkItemResponse.getResponse(); // <2> - - switch (bulkItemResponse.getOpType()) { - case INDEX: // <3> - case CREATE: - IndexResponse indexResponse = (IndexResponse) itemResponse; - break; - case UPDATE: // <4> - UpdateResponse updateResponse = (UpdateResponse) itemResponse; - break; - case DELETE: // <5> - DeleteResponse deleteResponse = (DeleteResponse) itemResponse; - } - } - // end::bulk-response - // tag::bulk-has-failures - if (bulkResponse.hasFailures()) { // <1> - - } - // end::bulk-has-failures - // tag::bulk-errors - for (BulkItemResponse bulkItemResponse : bulkResponse) { - if (bulkItemResponse.isFailed()) { // <1> - BulkItemResponse.Failure failure = - bulkItemResponse.getFailure(); // <2> - } - } - // end::bulk-errors - } - { - BulkRequest request = new BulkRequest(); - // tag::bulk-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::bulk-request-timeout - // tag::bulk-request-refresh - request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); // <1> - request.setRefreshPolicy("wait_for"); // <2> - // end::bulk-request-refresh - // tag::bulk-request-active-shards - request.waitForActiveShards(2); // <1> - request.waitForActiveShards(ActiveShardCount.ALL); // <2> - // end::bulk-request-active-shards - // tag::bulk-request-pipeline - request.pipeline("pipelineId"); // <1> - // end::bulk-request-pipeline - // tag::bulk-request-routing - request.routing("routingId"); // <1> - // end::bulk-request-routing - - // tag::bulk-request-index-type - BulkRequest defaulted = new BulkRequest("posts"); // <1> - // end::bulk-request-index-type - - // tag::bulk-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(BulkResponse bulkResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::bulk-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::bulk-execute-async - client.bulkAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::bulk-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testReindex() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - String mapping = """ - "properties": { - "user": { - "type": "text" - }, - "field1": { - "type": "integer" - }, - "field2": { - "type": "integer" - } - } - """; - createIndex("source1", Settings.EMPTY, mapping); - createIndex("source2", Settings.EMPTY, mapping); - createPipeline("my_pipeline"); - } - { - // tag::reindex-request - ReindexRequest request = new ReindexRequest(); // <1> - request.setSourceIndices("source1", "source2"); // <2> - request.setDestIndex("dest"); // <3> - // end::reindex-request - // tag::reindex-request-versionType - request.setDestVersionType(VersionType.EXTERNAL); // <1> - // end::reindex-request-versionType - // tag::reindex-request-opType - request.setDestOpType("create"); // <1> - // end::reindex-request-opType - // tag::reindex-request-conflicts - request.setConflicts("proceed"); // <1> - // end::reindex-request-conflicts - // tag::reindex-request-maxDocs - request.setMaxDocs(10); // <1> - // end::reindex-request-maxDocs - // tag::reindex-request-sourceSize - request.setSourceBatchSize(100); // <1> - // end::reindex-request-sourceSize - // tag::reindex-request-pipeline - request.setDestPipeline("my_pipeline"); // <1> - // end::reindex-request-pipeline - // tag::reindex-request-script - request.setScript( - new Script( - ScriptType.INLINE, "painless", - "if (ctx._source.user == 'kimchy') {ctx._source.likes++;}", - Collections.emptyMap())); // <1> - // end::reindex-request-script - HttpHost host = getClusterHosts().get(0); - Integer remotePort = host.getPort(); - String remoteHost = host.getHostName(); - String user = "test_user"; - String password = "test-user-password"; - - // tag::reindex-request-remote - request.setRemoteInfo( - new RemoteInfo( - "http", remoteHost, remotePort, null, - new BytesArray(new MatchAllQueryBuilder().toString()), - user, password, Collections.emptyMap(), - new TimeValue(100, TimeUnit.MILLISECONDS), - new TimeValue(100, TimeUnit.SECONDS) - ) - ); // <1> - // end::reindex-request-remote - // tag::reindex-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::reindex-request-timeout - // tag::reindex-request-refresh - request.setRefresh(true); // <1> - // end::reindex-request-refresh - // tag::reindex-request-scroll - request.setScroll(TimeValue.timeValueMinutes(10)); // <1> - // end::reindex-request-scroll - - // tag::reindex-execute - BulkByScrollResponse bulkResponse = - client.reindex(request, RequestOptions.DEFAULT); - // end::reindex-execute - assertSame(0, bulkResponse.getSearchFailures().size()); - assertSame(0, bulkResponse.getBulkFailures().size()); - // tag::reindex-response - TimeValue timeTaken = bulkResponse.getTook(); // <1> - boolean timedOut = bulkResponse.isTimedOut(); // <2> - long totalDocs = bulkResponse.getTotal(); // <3> - long updatedDocs = bulkResponse.getUpdated(); // <4> - long createdDocs = bulkResponse.getCreated(); // <5> - long deletedDocs = bulkResponse.getDeleted(); // <6> - long batches = bulkResponse.getBatches(); // <7> - long noops = bulkResponse.getNoops(); // <8> - long versionConflicts = bulkResponse.getVersionConflicts(); // <9> - long bulkRetries = bulkResponse.getBulkRetries(); // <10> - long searchRetries = bulkResponse.getSearchRetries(); // <11> - TimeValue throttledMillis = bulkResponse.getStatus().getThrottled(); // <12> - TimeValue throttledUntilMillis = - bulkResponse.getStatus().getThrottledUntil(); // <13> - List searchFailures = - bulkResponse.getSearchFailures(); // <14> - List bulkFailures = - bulkResponse.getBulkFailures(); // <15> - // end::reindex-response - } - { - ReindexRequest request = new ReindexRequest(); - request.setSourceIndices("source1"); - request.setDestIndex("dest"); - - // These cannot be set with a remote set, so its set here instead for the docs - // tag::reindex-request-query - request.setSourceQuery(new TermQueryBuilder("user", "kimchy")); // <1> - // end::reindex-request-query - // tag::reindex-request-slices - request.setSlices(2); // <1> - // end::reindex-request-slices - - ActionListener listener; - // tag::reindex-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(BulkByScrollResponse bulkResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::reindex-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::reindex-execute-async - client.reindexAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::reindex-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testReindexRethrottle() throws Exception { - RestHighLevelClient client = highLevelClient(); - TaskId taskId = new TaskId("oTUltX4IQMOUUVeiohTt8A:124"); - { - // tag::rethrottle-disable-request - RethrottleRequest request = new RethrottleRequest(taskId); // <1> - // end::rethrottle-disable-request - } - - { - // tag::rethrottle-request - RethrottleRequest request = new RethrottleRequest(taskId, 100.0f); // <1> - // end::rethrottle-request - } - - { - RethrottleRequest request = new RethrottleRequest(taskId); - // tag::rethrottle-request-execution - client.reindexRethrottle(request, RequestOptions.DEFAULT); // <1> - client.updateByQueryRethrottle(request, RequestOptions.DEFAULT); // <2> - client.deleteByQueryRethrottle(request, RequestOptions.DEFAULT); // <3> - // end::rethrottle-request-execution - } - - ActionListener listener; - // tag::rethrottle-request-async-listener - listener = new ActionListener() { - @Override - public void onResponse(ListTasksResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::rethrottle-request-async-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(3); - listener = new LatchedActionListener<>(listener, latch); - - RethrottleRequest request = new RethrottleRequest(taskId); - // tag::rethrottle-execute-async - client.reindexRethrottleAsync(request, - RequestOptions.DEFAULT, listener); // <1> - client.updateByQueryRethrottleAsync(request, - RequestOptions.DEFAULT, listener); // <2> - client.deleteByQueryRethrottleAsync(request, - RequestOptions.DEFAULT, listener); // <3> - // end::rethrottle-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testUpdateByQuery() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - String mapping = """ - "properties": { - "user": { - "type": "text" - }, - "field1": { - "type": "integer" - }, - "field2": { - "type": "integer" - } - } - """; - createIndex("source1", Settings.EMPTY, mapping); - createIndex("source2", Settings.EMPTY, mapping); - createPipeline("my_pipeline"); - } - { - // tag::update-by-query-request - UpdateByQueryRequest request = - new UpdateByQueryRequest("source1", "source2"); // <1> - // end::update-by-query-request - // tag::update-by-query-request-conflicts - request.setConflicts("proceed"); // <1> - // end::update-by-query-request-conflicts - // tag::update-by-query-request-query - request.setQuery(new TermQueryBuilder("user", "kimchy")); // <1> - // end::update-by-query-request-query - // tag::update-by-query-request-maxDocs - request.setMaxDocs(10); // <1> - // end::update-by-query-request-maxDocs - // tag::update-by-query-request-scrollSize - request.setBatchSize(100); // <1> - // end::update-by-query-request-scrollSize - // tag::update-by-query-request-pipeline - request.setPipeline("my_pipeline"); // <1> - // end::update-by-query-request-pipeline - // tag::update-by-query-request-script - request.setScript( - new Script( - ScriptType.INLINE, "painless", - "if (ctx._source.user == 'kimchy') {ctx._source.likes++;}", - Collections.emptyMap())); // <1> - // end::update-by-query-request-script - // tag::update-by-query-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::update-by-query-request-timeout - // tag::update-by-query-request-refresh - request.setRefresh(true); // <1> - // end::update-by-query-request-refresh - // tag::update-by-query-request-slices - request.setSlices(2); // <1> - // end::update-by-query-request-slices - // tag::update-by-query-request-scroll - request.setScroll(TimeValue.timeValueMinutes(10)); // <1> - // end::update-by-query-request-scroll - // tag::update-by-query-request-routing - request.setRouting("=cat"); // <1> - // end::update-by-query-request-routing - // tag::update-by-query-request-indicesOptions - request.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN); // <1> - // end::update-by-query-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::update-by-query-execute - BulkByScrollResponse bulkResponse = - client.updateByQuery(request, requestOptions); - // end::update-by-query-execute - assertSame(0, bulkResponse.getSearchFailures().size()); - assertSame(0, bulkResponse.getBulkFailures().size()); - // tag::update-by-query-response - TimeValue timeTaken = bulkResponse.getTook(); // <1> - boolean timedOut = bulkResponse.isTimedOut(); // <2> - long totalDocs = bulkResponse.getTotal(); // <3> - long updatedDocs = bulkResponse.getUpdated(); // <4> - long deletedDocs = bulkResponse.getDeleted(); // <5> - long batches = bulkResponse.getBatches(); // <6> - long noops = bulkResponse.getNoops(); // <7> - long versionConflicts = bulkResponse.getVersionConflicts(); // <8> - long bulkRetries = bulkResponse.getBulkRetries(); // <9> - long searchRetries = bulkResponse.getSearchRetries(); // <10> - TimeValue throttledMillis = bulkResponse.getStatus().getThrottled(); // <11> - TimeValue throttledUntilMillis = - bulkResponse.getStatus().getThrottledUntil(); // <12> - List searchFailures = - bulkResponse.getSearchFailures(); // <13> - List bulkFailures = - bulkResponse.getBulkFailures(); // <14> - // end::update-by-query-response - } - { - UpdateByQueryRequest request = new UpdateByQueryRequest(); - request.indices("source1"); - - ActionListener listener; - // tag::update-by-query-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(BulkByScrollResponse bulkResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-by-query-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-by-query-execute-async - client.updateByQueryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::update-by-query-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testDeleteByQuery() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - String mapping = """ - "properties": { - "user": { - "type": "text" - }, - "field1": { - "type": "integer" - }, - "field2": { - "type": "integer" - } - }"""; - createIndex("source1", Settings.EMPTY, mapping); - createIndex("source2", Settings.EMPTY, mapping); - } - { - // tag::delete-by-query-request - DeleteByQueryRequest request = - new DeleteByQueryRequest("source1", "source2"); // <1> - // end::delete-by-query-request - // tag::delete-by-query-request-conflicts - request.setConflicts("proceed"); // <1> - // end::delete-by-query-request-conflicts - // tag::delete-by-query-request-query - request.setQuery(new TermQueryBuilder("user", "kimchy")); // <1> - // end::delete-by-query-request-query - // tag::delete-by-query-request-maxDocs - request.setMaxDocs(10); // <1> - // end::delete-by-query-request-maxDocs - // tag::delete-by-query-request-scrollSize - request.setBatchSize(100); // <1> - // end::delete-by-query-request-scrollSize - // tag::delete-by-query-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::delete-by-query-request-timeout - // tag::delete-by-query-request-refresh - request.setRefresh(true); // <1> - // end::delete-by-query-request-refresh - // tag::delete-by-query-request-slices - request.setSlices(2); // <1> - // end::delete-by-query-request-slices - // tag::delete-by-query-request-scroll - request.setScroll(TimeValue.timeValueMinutes(10)); // <1> - // end::delete-by-query-request-scroll - // tag::delete-by-query-request-routing - request.setRouting("=cat"); // <1> - // end::delete-by-query-request-routing - // tag::delete-by-query-request-indicesOptions - request.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN); // <1> - // end::delete-by-query-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::delete-by-query-execute - BulkByScrollResponse bulkResponse = - client.deleteByQuery(request, requestOptions); - // end::delete-by-query-execute - assertSame(0, bulkResponse.getSearchFailures().size()); - assertSame(0, bulkResponse.getBulkFailures().size()); - // tag::delete-by-query-response - TimeValue timeTaken = bulkResponse.getTook(); // <1> - boolean timedOut = bulkResponse.isTimedOut(); // <2> - long totalDocs = bulkResponse.getTotal(); // <3> - long deletedDocs = bulkResponse.getDeleted(); // <4> - long batches = bulkResponse.getBatches(); // <5> - long noops = bulkResponse.getNoops(); // <6> - long versionConflicts = bulkResponse.getVersionConflicts(); // <7> - long bulkRetries = bulkResponse.getBulkRetries(); // <8> - long searchRetries = bulkResponse.getSearchRetries(); // <9> - TimeValue throttledMillis = bulkResponse.getStatus().getThrottled(); // <10> - TimeValue throttledUntilMillis = - bulkResponse.getStatus().getThrottledUntil(); // <11> - List searchFailures = - bulkResponse.getSearchFailures(); // <12> - List bulkFailures = - bulkResponse.getBulkFailures(); // <13> - // end::delete-by-query-response - } - { - DeleteByQueryRequest request = new DeleteByQueryRequest(); - request.indices("source1"); - - ActionListener listener; - // tag::delete-by-query-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(BulkByScrollResponse bulkResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-by-query-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-by-query-execute-async - client.deleteByQueryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-by-query-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testGet() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - Request createIndex = new Request("PUT", "/posts"); - createIndex.setJsonEntity(""" - { - "mappings": { - "properties": { - "message": { - "type": "text", - "store": true - } - } - } - }"""); - Response response = client().performRequest(createIndex); - assertEquals(200, response.getStatusLine().getStatusCode()); - - IndexRequest indexRequest = new IndexRequest("posts").id("1") - .source("user", "kimchy", "postDate", new Date(), "message", "trying out Elasticsearch"); - IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult()); - } - { - //tag::get-request - GetRequest getRequest = new GetRequest( - "posts", // <1> - "1"); // <2> - //end::get-request - - //tag::get-execute - GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); - //end::get-execute - assertTrue(getResponse.isExists()); - assertEquals(3, getResponse.getSourceAsMap().size()); - //tag::get-response - String index = getResponse.getIndex(); - String id = getResponse.getId(); - if (getResponse.isExists()) { - long version = getResponse.getVersion(); - String sourceAsString = getResponse.getSourceAsString(); // <1> - Map sourceAsMap = getResponse.getSourceAsMap(); // <2> - byte[] sourceAsBytes = getResponse.getSourceAsBytes(); // <3> - } else { - // <4> - } - //end::get-response - } - { - GetRequest request = new GetRequest("posts", "1"); - //tag::get-request-no-source - request.fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE); // <1> - //end::get-request-no-source - GetResponse getResponse = client.get(request, RequestOptions.DEFAULT); - assertNull(getResponse.getSourceInternal()); - } - { - GetRequest request = new GetRequest("posts", "1"); - //tag::get-request-source-include - String[] includes = new String[]{"message", "*Date"}; - String[] excludes = Strings.EMPTY_ARRAY; - FetchSourceContext fetchSourceContext = - new FetchSourceContext(true, includes, excludes); - request.fetchSourceContext(fetchSourceContext); // <1> - //end::get-request-source-include - GetResponse getResponse = client.get(request, RequestOptions.DEFAULT); - Map sourceAsMap = getResponse.getSourceAsMap(); - assertEquals(2, sourceAsMap.size()); - assertEquals("trying out Elasticsearch", sourceAsMap.get("message")); - assertTrue(sourceAsMap.containsKey("postDate")); - } - { - GetRequest request = new GetRequest("posts", "1"); - //tag::get-request-source-exclude - String[] includes = Strings.EMPTY_ARRAY; - String[] excludes = new String[]{"message"}; - FetchSourceContext fetchSourceContext = - new FetchSourceContext(true, includes, excludes); - request.fetchSourceContext(fetchSourceContext); // <1> - //end::get-request-source-exclude - GetResponse getResponse = client.get(request, RequestOptions.DEFAULT); - Map sourceAsMap = getResponse.getSourceAsMap(); - assertEquals(2, sourceAsMap.size()); - assertEquals("kimchy", sourceAsMap.get("user")); - assertTrue(sourceAsMap.containsKey("postDate")); - } - { - GetRequest request = new GetRequest("posts", "1"); - //tag::get-request-stored - request.storedFields("message"); // <1> - GetResponse getResponse = client.get(request, RequestOptions.DEFAULT); - String message = getResponse.getField("message").getValue(); // <2> - //end::get-request-stored - assertEquals("trying out Elasticsearch", message); - assertEquals(1, getResponse.getFields().size()); - assertNull(getResponse.getSourceInternal()); - } - { - GetRequest request = new GetRequest("posts", "1"); - //tag::get-request-routing - request.routing("routing"); // <1> - //end::get-request-routing - //tag::get-request-preference - request.preference("preference"); // <1> - //end::get-request-preference - //tag::get-request-realtime - request.realtime(false); // <1> - //end::get-request-realtime - //tag::get-request-refresh - request.refresh(true); // <1> - //end::get-request-refresh - //tag::get-request-version - request.version(2); // <1> - //end::get-request-version - //tag::get-request-version-type - request.versionType(VersionType.EXTERNAL); // <1> - //end::get-request-version-type - } - { - GetRequest request = new GetRequest("posts", "1"); - - // tag::get-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetResponse getResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - //tag::get-execute-async - client.getAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::get-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - { - //tag::get-indexnotfound - GetRequest request = new GetRequest("does_not_exist", "1"); - try { - GetResponse getResponse = client.get(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException e) { - if (e.status() == RestStatus.NOT_FOUND) { - // <1> - } - } - //end::get-indexnotfound - } - { - // tag::get-conflict - try { - GetRequest request = new GetRequest("posts", "1").version(2); - GetResponse getResponse = client.get(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.CONFLICT) { - // <1> - } - } - // end::get-conflict - } - } - - public void testGetSource() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - Request createIndex = new Request("PUT", "/posts"); - createIndex.setJsonEntity(""" - { - "mappings": { - "properties": { - "message": { - "type": "text", - "store": true - } - } - } - }"""); - Response response = client().performRequest(createIndex); - assertEquals(200, response.getStatusLine().getStatusCode()); - - IndexRequest indexRequest = new IndexRequest("posts").id("1") - .source("user", "kimchy", "postDate", new Date(), "message", "trying out Elasticsearch"); - IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); - assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult()); - } - - // tag::get-source-request - GetSourceRequest getSourceRequest = new GetSourceRequest( - "posts", // <1> - "1"); // <2> - // end::get-source-request - - //tag::get-source-request-optional - String[] includes = Strings.EMPTY_ARRAY; // <2> - String[] excludes = new String[]{"postDate"}; - getSourceRequest.fetchSourceContext( - new FetchSourceContext(true, includes, excludes)); // <1> - // end::get-source-request-optional - - //tag::get-source-request-routing - getSourceRequest.routing("routing"); // <1> - //end::get-source-request-routing - //tag::get-source-request-preference - getSourceRequest.preference("preference"); // <1> - //end::get-source-request-preference - //tag::get-source-request-realtime - getSourceRequest.realtime(false); // <1> - //end::get-source-request-realtime - //tag::get-source-request-refresh - getSourceRequest.refresh(true); // <1> - //end::get-source-request-refresh - - { - // tag::get-source-execute - GetSourceResponse response = - client.getSource(getSourceRequest, RequestOptions.DEFAULT); - // end::get-source-execute - // tag::get-source-response - Map source = response.getSource(); - // end::get-source-response - - Map expectSource = new HashMap<>(); - expectSource.put("user", "kimchy"); - expectSource.put("message", "trying out Elasticsearch"); - assertEquals(expectSource, source); - } - { - GetSourceRequest request = new GetSourceRequest("posts", "1"); - - // tag::get-source-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetSourceResponse getResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-source-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - //tag::get-source-execute-async - client.getSourceAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::get-source-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - } - - public void testExists() throws Exception { - RestHighLevelClient client = highLevelClient(); - // tag::exists-request - GetRequest getRequest = new GetRequest( - "posts", // <1> - "1"); // <2> - getRequest.fetchSourceContext(new FetchSourceContext(false)); // <3> - getRequest.storedFields("_none_"); // <4> - // end::exists-request - { - // tag::exists-execute - boolean exists = client.exists(getRequest, RequestOptions.DEFAULT); - // end::exists-execute - assertFalse(exists); - } - { - // tag::exists-execute-listener - ActionListener listener = new ActionListener() { - @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, RequestOptions.DEFAULT, listener); // <1> - // end::exists-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testBulkProcessor() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - // tag::bulk-processor-init - BulkProcessor.Listener listener = new BulkProcessor.Listener() { // <1> - @Override - public void beforeBulk(long executionId, BulkRequest request) { - // <2> - } - - @Override - public void afterBulk(long executionId, BulkRequest request, - BulkResponse response) { - // <3> - } - - @Override - public void afterBulk(long executionId, BulkRequest request, - Throwable failure) { - // <4> - } - }; - - BulkProcessor bulkProcessor = BulkProcessor.builder( - (request, bulkListener) -> - client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener), - listener, "bulk-processor-name").build(); // <5> - // end::bulk-processor-init - assertNotNull(bulkProcessor); - - // tag::bulk-processor-add - IndexRequest one = new IndexRequest("posts").id("1") - .source(XContentType.JSON, "title", - "In which order are my Elasticsearch queries executed?"); - IndexRequest two = new IndexRequest("posts").id("2") - .source(XContentType.JSON, "title", - "Current status and upcoming changes in Elasticsearch"); - IndexRequest three = new IndexRequest("posts").id("3") - .source(XContentType.JSON, "title", - "The Future of Federated Search in Elasticsearch"); - - bulkProcessor.add(one); - bulkProcessor.add(two); - bulkProcessor.add(three); - // end::bulk-processor-add - - // tag::bulk-processor-await - boolean terminated = bulkProcessor.awaitClose(30L, TimeUnit.SECONDS); // <1> - // end::bulk-processor-await - assertTrue(terminated); - - // tag::bulk-processor-close - bulkProcessor.close(); - // end::bulk-processor-close - } - { - // tag::bulk-processor-listener - BulkProcessor.Listener listener = new BulkProcessor.Listener() { - @Override - public void beforeBulk(long executionId, BulkRequest request) { - int numberOfActions = request.numberOfActions(); // <1> - logger.debug("Executing bulk [{}] with {} requests", - executionId, numberOfActions); - } - - @Override - public void afterBulk(long executionId, BulkRequest request, - BulkResponse response) { - if (response.hasFailures()) { // <2> - logger.warn("Bulk [{}] executed with failures", executionId); - } else { - logger.debug("Bulk [{}] completed in {} milliseconds", - executionId, response.getTook().getMillis()); - } - } - - @Override - public void afterBulk(long executionId, BulkRequest request, - Throwable failure) { - logger.error("Failed to execute bulk", failure); // <3> - } - }; - // end::bulk-processor-listener - - // tag::bulk-processor-options - BulkProcessor.Builder builder = BulkProcessor.builder( - (request, bulkListener) -> - client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener), - listener, "bulk-processor-name"); - builder.setBulkActions(500); // <1> - builder.setBulkSize(new ByteSizeValue(1L, ByteSizeUnit.MB)); // <2> - builder.setConcurrentRequests(0); // <3> - builder.setFlushInterval(TimeValue.timeValueSeconds(10L)); // <4> - builder.setBackoffPolicy(BackoffPolicy - .constantBackoff(TimeValue.timeValueSeconds(1L), 3)); // <5> - // end::bulk-processor-options - } - } - - // Not entirely sure if _termvectors belongs to CRUD, and in the absence of a better place, will have it here - public void testTermVectors() throws Exception { - RestHighLevelClient client = highLevelClient(); - CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("user") - .field("type", "keyword") - .endObject() - .endObject() - .endObject() - ); - CreateIndexResponse authorsResponse = client.indices().create(authorsRequest, RequestOptions.DEFAULT); - assertTrue(authorsResponse.isAcknowledged()); - client.index(new IndexRequest("index").id("1").source("user", "kimchy"), RequestOptions.DEFAULT); - Response refreshResponse = client().performRequest(new Request("POST", "/authors/_refresh")); - assertEquals(200, refreshResponse.getStatusLine().getStatusCode()); - - { - // tag::term-vectors-request - TermVectorsRequest request = new TermVectorsRequest("authors", "1"); - request.setFields("user"); - // end::term-vectors-request - } - - { - // tag::term-vectors-request-artificial - XContentBuilder docBuilder = XContentFactory.jsonBuilder(); - docBuilder.startObject().field("user", "guest-user").endObject(); - TermVectorsRequest request = new TermVectorsRequest("authors", - docBuilder); // <1> - // end::term-vectors-request-artificial - - // tag::term-vectors-request-optional-arguments - request.setFieldStatistics(false); // <1> - request.setTermStatistics(true); // <2> - request.setPositions(false); // <3> - request.setOffsets(false); // <4> - request.setPayloads(false); // <5> - - Map filterSettings = new HashMap<>(); - filterSettings.put("max_num_terms", 3); - filterSettings.put("min_term_freq", 1); - filterSettings.put("max_term_freq", 10); - filterSettings.put("min_doc_freq", 1); - filterSettings.put("max_doc_freq", 100); - filterSettings.put("min_word_length", 1); - filterSettings.put("max_word_length", 10); - - request.setFilterSettings(filterSettings); // <6> - - Map perFieldAnalyzer = new HashMap<>(); - perFieldAnalyzer.put("user", "keyword"); - request.setPerFieldAnalyzer(perFieldAnalyzer); // <7> - - request.setRealtime(false); // <8> - request.setRouting("routing"); // <9> - // end::term-vectors-request-optional-arguments - } - - TermVectorsRequest request = new TermVectorsRequest("authors", "1"); - request.setFields("user"); - - // tag::term-vectors-execute - TermVectorsResponse response = - client.termvectors(request, RequestOptions.DEFAULT); - // end::term-vectors-execute - - // tag::term-vectors-response - String index = response.getIndex(); // <1> - String id = response.getId(); // <2> - boolean found = response.getFound(); // <3> - // end::term-vectors-response - - if (response.getTermVectorsList() != null) { - // tag::term-vectors-term-vectors - for (TermVectorsResponse.TermVector tv : response.getTermVectorsList()) { - String fieldname = tv.getFieldName(); // <1> - int docCount = tv.getFieldStatistics().getDocCount(); // <2> - long sumTotalTermFreq = - tv.getFieldStatistics().getSumTotalTermFreq(); // <3> - long sumDocFreq = tv.getFieldStatistics().getSumDocFreq(); // <4> - if (tv.getTerms() != null) { - List terms = - tv.getTerms(); // <5> - for (TermVectorsResponse.TermVector.Term term : terms) { - String termStr = term.getTerm(); // <6> - int termFreq = term.getTermFreq(); // <7> - int docFreq = term.getDocFreq(); // <8> - long totalTermFreq = term.getTotalTermFreq(); // <9> - float score = term.getScore(); // <10> - if (term.getTokens() != null) { - List tokens = - term.getTokens(); // <11> - for (TermVectorsResponse.TermVector.Token token : tokens) { - int position = token.getPosition(); // <12> - int startOffset = token.getStartOffset(); // <13> - int endOffset = token.getEndOffset(); // <14> - String payload = token.getPayload(); // <15> - } - } - } - } - } - // end::term-vectors-term-vectors - } - - ActionListener listener; - // tag::term-vectors-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(TermVectorsResponse termVectorsResponse) { - // <1> - } - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::term-vectors-execute-listener - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - // tag::term-vectors-execute-async - client.termvectorsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::term-vectors-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - } - - // Not entirely sure if _mtermvectors belongs to CRUD, and in the absence of a better place, will have it here - public void testMultiTermVectors() throws Exception { - RestHighLevelClient client = highLevelClient(); - CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("user") - .field("type", "keyword") - .endObject() - .endObject() - .endObject() - ); - CreateIndexResponse authorsResponse = client.indices().create(authorsRequest, RequestOptions.DEFAULT); - assertTrue(authorsResponse.isAcknowledged()); - client.index(new IndexRequest("index").id("1").source("user", "kimchy"), RequestOptions.DEFAULT); - client.index(new IndexRequest("index").id("2").source("user", "s1monw"), RequestOptions.DEFAULT); - Response refreshResponse = client().performRequest(new Request("POST", "/authors/_refresh")); - assertEquals(200, refreshResponse.getStatusLine().getStatusCode()); - - { - // tag::multi-term-vectors-request - MultiTermVectorsRequest request = new MultiTermVectorsRequest(); // <1> - TermVectorsRequest tvrequest1 = - new TermVectorsRequest("authors", "1"); - tvrequest1.setFields("user"); - request.add(tvrequest1); // <2> - - XContentBuilder docBuilder = XContentFactory.jsonBuilder(); - docBuilder.startObject().field("user", "guest-user").endObject(); - TermVectorsRequest tvrequest2 = - new TermVectorsRequest("authors", docBuilder); - request.add(tvrequest2); // <3> - // end::multi-term-vectors-request - } - - // tag::multi-term-vectors-request-template - TermVectorsRequest tvrequestTemplate = - new TermVectorsRequest("authors", "fake_id"); // <1> - tvrequestTemplate.setFields("user"); - String[] ids = {"1", "2"}; - MultiTermVectorsRequest request = - new MultiTermVectorsRequest(ids, tvrequestTemplate); // <2> - // end::multi-term-vectors-request-template - - // tag::multi-term-vectors-execute - MultiTermVectorsResponse response = - client.mtermvectors(request, RequestOptions.DEFAULT); - // end::multi-term-vectors-execute - - // tag::multi-term-vectors-response - List tvresponseList = - response.getTermVectorsResponses(); // <1> - if (tvresponseList != null) { - for (TermVectorsResponse tvresponse : tvresponseList) { - } - } - // end::multi-term-vectors-response - - ActionListener listener; - // tag::multi-term-vectors-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(MultiTermVectorsResponse mtvResponse) { - // <1> - } - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::multi-term-vectors-execute-listener - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - // tag::multi-term-vectors-execute-async - client.mtermvectorsAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::multi-term-vectors-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - } - - @SuppressWarnings("unused") - public void testMultiGet() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - Request createIndex = new Request("PUT", "/index"); - createIndex.setJsonEntity(""" - { - "mappings": { - "properties": { - "foo": { - "type": "text", - "store": true - } - } - } - }"""); - Response response = client().performRequest(createIndex); - assertEquals(200, response.getStatusLine().getStatusCode()); - } - - Map source = new HashMap<>(); - source.put("foo", "val1"); - source.put("bar", "val2"); - source.put("baz", "val3"); - client.index( - new IndexRequest("index").id("example_id").source(source).setRefreshPolicy(RefreshPolicy.IMMEDIATE), - RequestOptions.DEFAULT - ); - - { - // tag::multi-get-request - MultiGetRequest request = new MultiGetRequest(); - request.add(new MultiGetRequest.Item( - "index", // <1> - "example_id")); // <2> - request.add(new MultiGetRequest.Item("index", "another_id")); // <3> - // end::multi-get-request - - // Add a missing index so we can test it. - request.add(new MultiGetRequest.Item("missing_index", "id")); - - // tag::multi-get-request-item-extras - request.add(new MultiGetRequest.Item("index", "with_routing") - .routing("some_routing")); // <1> - request.add(new MultiGetRequest.Item("index", "with_version") - .versionType(VersionType.EXTERNAL) // <2> - .version(10123L)); // <3> - // end::multi-get-request-item-extras - // tag::multi-get-request-top-level-extras - request.preference("some_preference"); // <1> - request.realtime(false); // <2> - request.refresh(true); // <3> - // end::multi-get-request-top-level-extras - - // tag::multi-get-execute - MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT); - // end::multi-get-execute - - // tag::multi-get-response - MultiGetItemResponse firstItem = response.getResponses()[0]; - assertNull(firstItem.getFailure()); // <1> - GetResponse firstGet = firstItem.getResponse(); // <2> - String index = firstItem.getIndex(); - String id = firstItem.getId(); - if (firstGet.isExists()) { - long version = firstGet.getVersion(); - String sourceAsString = firstGet.getSourceAsString(); // <3> - Map sourceAsMap = firstGet.getSourceAsMap(); // <4> - byte[] sourceAsBytes = firstGet.getSourceAsBytes(); // <5> - } else { - // <6> - } - // end::multi-get-response - - assertTrue(firstGet.isExists()); - assertEquals(source, firstGet.getSource()); - - MultiGetItemResponse missingIndexItem = response.getResponses()[2]; - // tag::multi-get-indexnotfound - assertNull(missingIndexItem.getResponse()); // <1> - Exception e = missingIndexItem.getFailure().getFailure(); // <2> - ElasticsearchException ee = (ElasticsearchException) e; // <3> - // TODO status is broken! fix in a followup - // assertEquals(RestStatus.NOT_FOUND, ee.status()); // <4> - assertThat(e.getMessage(), - containsString("reason=no such index [missing_index]")); // <5> - // end::multi-get-indexnotfound - - ActionListener listener; - // tag::multi-get-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(MultiGetResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::multi-get-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::multi-get-execute-async - client.mgetAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::multi-get-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - { - MultiGetRequest request = new MultiGetRequest(); - // tag::multi-get-request-no-source - request.add(new MultiGetRequest.Item("index", "example_id") - .fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE)); // <1> - // end::multi-get-request-no-source - MultiGetItemResponse item = unwrapAndAssertExample(client.mget(request, RequestOptions.DEFAULT)); - assertNull(item.getResponse().getSource()); - } - { - MultiGetRequest request = new MultiGetRequest(); - // tag::multi-get-request-source-include - String[] includes = new String[] {"foo", "*r"}; - String[] excludes = Strings.EMPTY_ARRAY; - FetchSourceContext fetchSourceContext = - new FetchSourceContext(true, includes, excludes); - request.add(new MultiGetRequest.Item("index", "example_id") - .fetchSourceContext(fetchSourceContext)); // <1> - // end::multi-get-request-source-include - MultiGetItemResponse item = unwrapAndAssertExample(client.mget(request, RequestOptions.DEFAULT)); - assertThat(item.getResponse().getSource(), hasEntry("foo", "val1")); - assertThat(item.getResponse().getSource(), hasEntry("bar", "val2")); - assertThat(item.getResponse().getSource(), not(hasKey("baz"))); - } - { - MultiGetRequest request = new MultiGetRequest(); - // tag::multi-get-request-source-exclude - String[] includes = Strings.EMPTY_ARRAY; - String[] excludes = new String[] {"foo", "*r"}; - FetchSourceContext fetchSourceContext = - new FetchSourceContext(true, includes, excludes); - request.add(new MultiGetRequest.Item("index", "example_id") - .fetchSourceContext(fetchSourceContext)); // <1> - // end::multi-get-request-source-exclude - MultiGetItemResponse item = unwrapAndAssertExample(client.mget(request, RequestOptions.DEFAULT)); - assertThat(item.getResponse().getSource(), not(hasKey("foo"))); - assertThat(item.getResponse().getSource(), not(hasKey("bar"))); - assertThat(item.getResponse().getSource(), hasEntry("baz", "val3")); - } - { - MultiGetRequest request = new MultiGetRequest(); - // tag::multi-get-request-stored - request.add(new MultiGetRequest.Item("index", "example_id") - .storedFields("foo")); // <1> - MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT); - MultiGetItemResponse item = response.getResponses()[0]; - String value = item.getResponse().getField("foo").getValue(); // <2> - // end::multi-get-request-stored - assertNull(item.getResponse().getSource()); - assertEquals("val1", value); - } - { - // tag::multi-get-conflict - MultiGetRequest request = new MultiGetRequest(); - request.add(new MultiGetRequest.Item("index", "example_id") - .version(1000L)); - MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT); - MultiGetItemResponse item = response.getResponses()[0]; - assertNull(item.getResponse()); // <1> - Exception e = item.getFailure().getFailure(); // <2> - ElasticsearchException ee = (ElasticsearchException) e; // <3> - // TODO status is broken! fix in a followup - // assertEquals(RestStatus.CONFLICT, ee.status()); // <4> - assertThat(e.getMessage(), - containsString("version conflict, current version [1] is " - + "different than the one provided [1000]")); // <5> - // end::multi-get-conflict - } - - } - - private MultiGetItemResponse unwrapAndAssertExample(MultiGetResponse response) { - assertThat(response.getResponses(), arrayWithSize(1)); - MultiGetItemResponse item = response.getResponses()[0]; - assertEquals("index", item.getIndex()); - assertEquals("example_id", item.getId()); - return item; - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java deleted file mode 100644 index 6d284fecec74..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java +++ /dev/null @@ -1,696 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; -import org.elasticsearch.action.support.ActiveShardCount; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.WarningsHandler; -import org.elasticsearch.client.cluster.RemoteConnectionInfo; -import org.elasticsearch.client.cluster.RemoteInfoRequest; -import org.elasticsearch.client.cluster.RemoteInfoResponse; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.DeleteComponentTemplateRequest; -import org.elasticsearch.client.indices.GetComponentTemplatesRequest; -import org.elasticsearch.client.indices.GetComponentTemplatesResponse; -import org.elasticsearch.client.indices.PutComponentTemplateRequest; -import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.elasticsearch.cluster.health.ClusterIndexHealth; -import org.elasticsearch.cluster.health.ClusterShardHealth; -import org.elasticsearch.cluster.metadata.AliasMetadata; -import org.elasticsearch.cluster.metadata.ComponentTemplate; -import org.elasticsearch.cluster.metadata.Template; -import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; -import org.elasticsearch.common.Priority; -import org.elasticsearch.common.compress.CompressedXContent; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.indices.recovery.RecoverySettings; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; - -/** - * Documentation for Cluster APIs in the high level java client. - * Code wrapped in {@code tag} and {@code end} tags is included in the docs. - */ -@SuppressWarnings("removal") -public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testClusterPutSettings() throws IOException { - RestHighLevelClient client = highLevelClient(); - - // tag::put-settings-request - ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest(); - // end::put-settings-request - - // tag::put-settings-create-settings - String transientSettingKey = - RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(); - int transientSettingValue = 10; - Settings transientSettings = - Settings.builder() - .put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES) - .build(); // <1> - - String persistentSettingKey = - EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(); - String persistentSettingValue = - EnableAllocationDecider.Allocation.NONE.name(); - Settings persistentSettings = - Settings.builder() - .put(persistentSettingKey, persistentSettingValue) - .build(); // <2> - // end::put-settings-create-settings - - // tag::put-settings-request-cluster-settings - request.transientSettings(transientSettings); // <1> - request.persistentSettings(persistentSettings); // <2> - // end::put-settings-request-cluster-settings - - { - // tag::put-settings-settings-builder - Settings.Builder transientSettingsBuilder = - Settings.builder() - .put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES); - request.transientSettings(transientSettingsBuilder); // <1> - // end::put-settings-settings-builder - } - { - // tag::put-settings-settings-map - Map map = new HashMap<>(); - map.put(transientSettingKey - , transientSettingValue + ByteSizeUnit.BYTES.getSuffix()); - request.transientSettings(map); // <1> - // end::put-settings-settings-map - } - { - // tag::put-settings-settings-source - request.transientSettings( - "{\"indices.recovery.max_bytes_per_sec\": \"10b\"}" - , XContentType.JSON); // <1> - // end::put-settings-settings-source - } - - // tag::put-settings-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::put-settings-request-timeout - // tag::put-settings-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::put-settings-request-masterTimeout - - RequestOptions options = RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE).build(); - // tag::put-settings-execute - ClusterUpdateSettingsResponse response = client.cluster().putSettings(request, options); - // end::put-settings-execute - - // tag::put-settings-response - boolean acknowledged = response.isAcknowledged(); // <1> - Settings transientSettingsResponse = response.getTransientSettings(); // <2> - Settings persistentSettingsResponse = response.getPersistentSettings(); // <3> - // end::put-settings-response - assertTrue(acknowledged); - assertThat(transientSettingsResponse.get(transientSettingKey), equalTo(transientSettingValue + ByteSizeUnit.BYTES.getSuffix())); - assertThat(persistentSettingsResponse.get(persistentSettingKey), equalTo(persistentSettingValue)); - - // tag::put-settings-request-reset-transient - request.transientSettings(Settings.builder().putNull(transientSettingKey).build()); // <1> - // tag::put-settings-request-reset-transient - request.persistentSettings(Settings.builder().putNull(persistentSettingKey)); - ClusterUpdateSettingsResponse resetResponse = client.cluster().putSettings(request, options); - - assertTrue(resetResponse.isAcknowledged()); - } - - public void testClusterUpdateSettingsAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest(); - - // tag::put-settings-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ClusterUpdateSettingsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-settings-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-settings-execute-async - client.cluster().putSettingsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-settings-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testClusterGetSettings() throws IOException { - RestHighLevelClient client = highLevelClient(); - - // tag::get-settings-request - ClusterGetSettingsRequest request = new ClusterGetSettingsRequest(); - // end::get-settings-request - - // tag::get-settings-request-includeDefaults - request.includeDefaults(true); // <1> - // end::get-settings-request-includeDefaults - - // tag::get-settings-request-local - request.local(true); // <1> - // end::get-settings-request-local - - // tag::get-settings-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::get-settings-request-masterTimeout - - // tag::get-settings-execute - ClusterGetSettingsResponse response = client.cluster().getSettings(request, RequestOptions.DEFAULT); // <1> - // end::get-settings-execute - - // tag::get-settings-response - Settings persistentSettings = response.getPersistentSettings(); // <1> - Settings transientSettings = response.getTransientSettings(); // <2> - Settings defaultSettings = response.getDefaultSettings(); // <3> - String settingValue = response.getSetting("cluster.routing.allocation.enable"); // <4> - // end::get-settings-response - - assertThat(defaultSettings.size(), greaterThan(0)); - } - - public void testClusterGetSettingsAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - - ClusterGetSettingsRequest request = new ClusterGetSettingsRequest(); - - // tag::get-settings-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ClusterGetSettingsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-settings-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-settings-execute-async - client.cluster().getSettingsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-settings-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testClusterHealth() throws IOException { - RestHighLevelClient client = highLevelClient(); - client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - { - // tag::health-request - ClusterHealthRequest request = new ClusterHealthRequest(); - // end::health-request - } - { - // tag::health-request-indices-ctr - ClusterHealthRequest request = new ClusterHealthRequest("index1", "index2"); - // end::health-request-indices-ctr - } - { - // tag::health-request-indices-setter - ClusterHealthRequest request = new ClusterHealthRequest(); - request.indices("index1", "index2"); - // end::health-request-indices-setter - } - ClusterHealthRequest request = new ClusterHealthRequest(); - - // tag::health-request-timeout - request.timeout(TimeValue.timeValueSeconds(50)); // <1> - request.timeout("50s"); // <2> - // end::health-request-timeout - - // tag::health-request-master-timeout - request.masterNodeTimeout(TimeValue.timeValueSeconds(20)); // <1> - request.masterNodeTimeout("20s"); // <2> - // end::health-request-master-timeout - - // tag::health-request-wait-status - request.waitForStatus(ClusterHealthStatus.YELLOW); // <1> - request.waitForYellowStatus(); // <2> - // end::health-request-wait-status - - // tag::health-request-wait-events - request.waitForEvents(Priority.NORMAL); // <1> - // end::health-request-wait-events - - // tag::health-request-level - request.level(ClusterHealthRequest.Level.SHARDS); // <1> - // end::health-request-level - - // tag::health-request-wait-relocation - request.waitForNoRelocatingShards(true); // <1> - // end::health-request-wait-relocation - - // tag::health-request-wait-initializing - request.waitForNoInitializingShards(true); // <1> - // end::health-request-wait-initializing - - // tag::health-request-wait-nodes - request.waitForNodes("2"); // <1> - request.waitForNodes(">=2"); // <2> - request.waitForNodes("le(2)"); // <3> - // end::health-request-wait-nodes - - // tag::health-request-wait-active - request.waitForActiveShards(ActiveShardCount.ALL); // <1> - request.waitForActiveShards(1); // <2> - // end::health-request-wait-active - - // tag::health-request-local - request.local(true); // <1> - // end::health-request-local - - // tag::health-execute - ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT); - // end::health-execute - - assertThat(response.isTimedOut(), equalTo(false)); - assertThat(response.status(), equalTo(RestStatus.OK)); - assertThat(response.getStatus(), equalTo(ClusterHealthStatus.YELLOW)); - assertThat(response, notNullValue()); - // tag::health-response-general - String clusterName = response.getClusterName(); // <1> - ClusterHealthStatus status = response.getStatus(); // <2> - // end::health-response-general - - // tag::health-response-request-status - boolean timedOut = response.isTimedOut(); // <1> - RestStatus restStatus = response.status(); // <2> - // end::health-response-request-status - - // tag::health-response-nodes - int numberOfNodes = response.getNumberOfNodes(); // <1> - int numberOfDataNodes = response.getNumberOfDataNodes(); // <2> - // end::health-response-nodes - - { - // tag::health-response-shards - int activeShards = response.getActiveShards(); // <1> - int activePrimaryShards = response.getActivePrimaryShards(); // <2> - int relocatingShards = response.getRelocatingShards(); // <3> - int initializingShards = response.getInitializingShards(); // <4> - int unassignedShards = response.getUnassignedShards(); // <5> - int delayedUnassignedShards = response.getDelayedUnassignedShards(); // <6> - double activeShardsPercent = response.getActiveShardsPercent(); // <7> - // end::health-response-shards - } - - // tag::health-response-task - TimeValue taskMaxWaitingTime = response.getTaskMaxWaitingTime(); // <1> - int numberOfPendingTasks = response.getNumberOfPendingTasks(); // <2> - int numberOfInFlightFetch = response.getNumberOfInFlightFetch(); // <3> - // end::health-response-task - - // tag::health-response-indices - Map indices = response.getIndices(); // <1> - // end::health-response-indices - - { - // tag::health-response-index - ClusterIndexHealth index = indices.get("index"); // <1> - ClusterHealthStatus indexStatus = index.getStatus(); - int numberOfShards = index.getNumberOfShards(); - int numberOfReplicas = index.getNumberOfReplicas(); - int activeShards = index.getActiveShards(); - int activePrimaryShards = index.getActivePrimaryShards(); - int initializingShards = index.getInitializingShards(); - int relocatingShards = index.getRelocatingShards(); - int unassignedShards = index.getUnassignedShards(); - // end::health-response-index - - // tag::health-response-shard-details - Map shards = index.getShards(); // <1> - ClusterShardHealth shardHealth = shards.get(0); - int shardId = shardHealth.getShardId(); - ClusterHealthStatus shardStatus = shardHealth.getStatus(); - int active = shardHealth.getActiveShards(); - int initializing = shardHealth.getInitializingShards(); - int unassigned = shardHealth.getUnassignedShards(); - int relocating = shardHealth.getRelocatingShards(); - boolean primaryActive = shardHealth.isPrimaryActive(); - // end::health-response-shard-details - } - } - - public void testClusterHealthAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - ClusterHealthRequest request = new ClusterHealthRequest(); - - // tag::health-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ClusterHealthResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::health-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::health-execute-async - client.cluster().healthAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::health-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testRemoteInfo() throws Exception { - setupRemoteClusterConfig("local_cluster"); - - RestHighLevelClient client = highLevelClient(); - - // tag::remote-info-request - RemoteInfoRequest request = new RemoteInfoRequest(); - // end::remote-info-request - - // tag::remote-info-execute - RemoteInfoResponse response = client.cluster().remoteInfo(request, RequestOptions.DEFAULT); // <1> - // end::remote-info-execute - - // tag::remote-info-response - List infos = response.getInfos(); - // end::remote-info-response - - assertThat(infos.size(), greaterThan(0)); - } - - public void testRemoteInfoAsync() throws Exception { - setupRemoteClusterConfig("local_cluster"); - - RestHighLevelClient client = highLevelClient(); - - // tag::remote-info-request - RemoteInfoRequest request = new RemoteInfoRequest(); - // end::remote-info-request - - // tag::remote-info-execute-listener - ActionListener listener = - new ActionListener<>() { - @Override - public void onResponse(RemoteInfoResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::remote-info-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::health-execute-async - client.cluster().remoteInfoAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::health-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetComponentTemplates() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - Template template = new Template(Settings.builder().put("index.number_of_replicas", 3).build(), null, null); - ComponentTemplate componentTemplate = new ComponentTemplate(template, null, null); - PutComponentTemplateRequest putComponentTemplateRequest = new PutComponentTemplateRequest().name("ct1") - .componentTemplate(componentTemplate); - client.cluster().putComponentTemplate(putComponentTemplateRequest, RequestOptions.DEFAULT); - - assertTrue(client.cluster().putComponentTemplate(putComponentTemplateRequest, RequestOptions.DEFAULT).isAcknowledged()); - } - - // tag::get-component-templates-request - GetComponentTemplatesRequest request = new GetComponentTemplatesRequest("ct1"); // <1> - // end::get-component-templates-request - - // tag::get-component-templates-request-masterTimeout - request.setMasterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.setMasterNodeTimeout("1m"); // <2> - // end::get-component-templates-request-masterTimeout - - // tag::get-component-templates-execute - GetComponentTemplatesResponse getTemplatesResponse = client.cluster().getComponentTemplate(request, RequestOptions.DEFAULT); - // end::get-component-templates-execute - - // tag::get-component-templates-response - Map templates = getTemplatesResponse.getComponentTemplates(); // <1> - // end::get-component-templates-response - - assertThat(templates.size(), is(1)); - assertThat(templates.get("ct1"), is(notNullValue())); - - // tag::get-component-templates-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetComponentTemplatesResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-component-templates-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-component-templates-execute-async - client.cluster().getComponentTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-component-templates-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testPutComponentTemplate() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::put-component-template-request - PutComponentTemplateRequest request = new PutComponentTemplateRequest() - .name("ct1"); // <1> - - Settings settings = Settings.builder() - .put("index.number_of_shards", 3) - .put("index.number_of_replicas", 1) - .build(); - String mappingJson = """ - { - "properties": { - "message": { - "type": "text" - } - } - }"""; - AliasMetadata twitterAlias = AliasMetadata.builder("twitter_alias").build(); - Template template = new Template(settings, new CompressedXContent(mappingJson), Map.of("twitter_alias", twitterAlias)); // <2> - - request.componentTemplate(new ComponentTemplate(template, null, null)); - assertTrue(client.cluster().putComponentTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-component-template-request - } - - { - // tag::put-component-template-request-version - PutComponentTemplateRequest request = new PutComponentTemplateRequest() - .name("ct1"); - Settings settings = Settings.builder() - .put("index.number_of_replicas", 3) - .build(); - Template template = new Template(settings, null, null); - - request.componentTemplate(new ComponentTemplate(template, 3L, null)); // <1> - assertTrue(client.cluster().putComponentTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-component-template-request-version - - // tag::put-component-template-request-create - request.create(true); // <1> - // end::put-component-template-request-create - - // tag::put-component-template-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::put-component-template-request-masterTimeout - - request.create(false); // make test happy - - // tag::put-component-template-request-execute - AcknowledgedResponse putComponentTemplateResponse = client.cluster().putComponentTemplate(request, RequestOptions.DEFAULT); - // end::put-component-template-request-execute - - // tag::put-component-template-response - boolean acknowledged = putComponentTemplateResponse.isAcknowledged(); // <1> - // end::put-component-template-response - assertTrue(acknowledged); - - // tag::put-component-template-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse putComponentTemplateResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-component-template-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-component-template-execute-async - client.cluster().putComponentTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-component-template-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteComponentTemplate() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - PutComponentTemplateRequest request = new PutComponentTemplateRequest().name("ct1"); - - Settings settings = Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 1).build(); - String mappingJson = """ - { - "properties": { - "message": { - "type": "text" - } - } - }"""; - AliasMetadata twitterAlias = AliasMetadata.builder("twitter_alias").build(); - Template template = new Template(settings, new CompressedXContent(mappingJson), Map.of("twitter_alias", twitterAlias)); - - request.componentTemplate(new ComponentTemplate(template, null, null)); - assertTrue(client.cluster().putComponentTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - } - - // tag::delete-component-template-request - DeleteComponentTemplateRequest deleteRequest = new DeleteComponentTemplateRequest("ct1"); // <1> - // end::delete-component-template-request - - // tag::delete-component-template-request-masterTimeout - deleteRequest.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::delete-component-template-request-masterTimeout - - // tag::delete-component-template-execute - AcknowledgedResponse deleteTemplateAcknowledge = client.cluster().deleteComponentTemplate(deleteRequest, RequestOptions.DEFAULT); - // end::delete-component-template-execute - - // tag::delete-component-template-response - boolean acknowledged = deleteTemplateAcknowledge.isAcknowledged(); // <1> - // end::delete-component-template-response - assertThat(acknowledged, equalTo(true)); - - { - PutComponentTemplateRequest request = new PutComponentTemplateRequest().name("ct1"); - - Settings settings = Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 1).build(); - Template template = new Template(settings, null, null); - request.componentTemplate(new ComponentTemplate(template, null, null)); - assertTrue(client.cluster().putComponentTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - } - - // tag::delete-component-template-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-component-template-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-component-template-execute-async - client.cluster().deleteComponentTemplateAsync(deleteRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-component-template-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/EnrichDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/EnrichDocumentationIT.java deleted file mode 100644 index 6a4834eb84ca..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/EnrichDocumentationIT.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.AcknowledgedResponse; -import org.elasticsearch.client.enrich.DeletePolicyRequest; -import org.elasticsearch.client.enrich.ExecutePolicyRequest; -import org.elasticsearch.client.enrich.ExecutePolicyResponse; -import org.elasticsearch.client.enrich.GetPolicyRequest; -import org.elasticsearch.client.enrich.GetPolicyResponse; -import org.elasticsearch.client.enrich.NamedPolicy; -import org.elasticsearch.client.enrich.PutPolicyRequest; -import org.elasticsearch.client.enrich.StatsRequest; -import org.elasticsearch.client.enrich.StatsResponse; -import org.elasticsearch.client.enrich.StatsResponse.CoordinatorStats; -import org.elasticsearch.client.enrich.StatsResponse.ExecutingPolicy; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.junit.After; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -@SuppressWarnings("removal") -public class EnrichDocumentationIT extends ESRestHighLevelClientTestCase { - - @After - public void cleanup() { - RestHighLevelClient client = highLevelClient(); - DeletePolicyRequest deletePolicyRequest = new DeletePolicyRequest("users-policy"); - try { - client.enrich().deletePolicy(deletePolicyRequest, RequestOptions.DEFAULT); - } catch (Exception e) { - // ignore... it is ok if policy has already been removed - } - } - - public void testPutPolicy() throws Exception { - RestHighLevelClient client = highLevelClient(); - CreateIndexRequest createIndexRequest = new CreateIndexRequest("users").mapping( - Map.of("properties", Map.of("email", Map.of("type", "keyword"))) - ); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - - // tag::enrich-put-policy-request - PutPolicyRequest putPolicyRequest = new PutPolicyRequest( - "users-policy", "match", List.of("users"), - "email", List.of("address", "zip", "city", "state")); - // end::enrich-put-policy-request - - // tag::enrich-put-policy-execute - AcknowledgedResponse putPolicyResponse = - client.enrich().putPolicy(putPolicyRequest, RequestOptions.DEFAULT); - // end::enrich-put-policy-execute - - // tag::enrich-put-policy-response - boolean isAcknowledged = - putPolicyResponse.isAcknowledged(); // <1> - // end::enrich-put-policy-response - - // tag::enrich-put-policy-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse response) { // <1> - boolean isAcknowledged = response.isAcknowledged(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::enrich-put-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::enrich-put-policy-execute-async - client.enrich().putPolicyAsync(putPolicyRequest, - RequestOptions.DEFAULT, listener); // <1> - // end::enrich-put-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testDeletePolicy() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexRequest createIndexRequest = new CreateIndexRequest("users").mapping( - Map.of("properties", Map.of("email", Map.of("type", "keyword"))) - ); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - - // Add a policy, so that it can be deleted: - PutPolicyRequest putPolicyRequest = new PutPolicyRequest( - "users-policy", - "match", - List.of("users"), - "email", - List.of("address", "zip", "city", "state") - ); - client.enrich().putPolicy(putPolicyRequest, RequestOptions.DEFAULT); - } - - // tag::enrich-delete-policy-request - DeletePolicyRequest deletePolicyRequest = - new DeletePolicyRequest("users-policy"); - // end::enrich-delete-policy-request - - // tag::enrich-delete-policy-execute - AcknowledgedResponse deletePolicyResponse = client.enrich() - .deletePolicy(deletePolicyRequest, RequestOptions.DEFAULT); - // end::enrich-delete-policy-execute - - // tag::enrich-delete-policy-response - boolean isAcknowledged = - deletePolicyResponse.isAcknowledged(); // <1> - // end::enrich-delete-policy-response - - // tag::enrich-delete-policy-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse response) { // <1> - boolean isAcknowledged = response.isAcknowledged(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::enrich-delete-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::enrich-delete-policy-execute-async - client.enrich().deletePolicyAsync(deletePolicyRequest, - RequestOptions.DEFAULT, listener); // <1> - // end::enrich-delete-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetPolicy() throws Exception { - RestHighLevelClient client = highLevelClient(); - - CreateIndexRequest createIndexRequest = new CreateIndexRequest("users").mapping( - Map.of("properties", Map.of("email", Map.of("type", "keyword"))) - ); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - - PutPolicyRequest putPolicyRequest = new PutPolicyRequest( - "users-policy", - "match", - List.of("users"), - "email", - List.of("address", "zip", "city", "state") - ); - client.enrich().putPolicy(putPolicyRequest, RequestOptions.DEFAULT); - - // tag::enrich-get-policy-request - GetPolicyRequest getPolicyRequest = new GetPolicyRequest("users-policy"); - // end::enrich-get-policy-request - - // tag::enrich-get-policy-execute - GetPolicyResponse getPolicyResponse = - client.enrich().getPolicy(getPolicyRequest, RequestOptions.DEFAULT); - // end::enrich-get-policy-execute - - // tag::enrich-get-policy-response - List policies = getPolicyResponse.getPolicies(); // <1> - NamedPolicy policy = policies.get(0); - // end::enrich-get-policy-response - - // tag::enrich-get-policy-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(GetPolicyResponse response) { // <1> - List policies = response.getPolicies(); - NamedPolicy policy = policies.get(0); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::enrich-get-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::enrich-get-policy-execute-async - client.enrich().getPolicyAsync(getPolicyRequest, - RequestOptions.DEFAULT, listener); // <1> - // end::enrich-get-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testStats() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::enrich-stats-request - StatsRequest statsRequest = new StatsRequest(); - // end::enrich-stats-request - - // tag::enrich-stats-execute - StatsResponse statsResponse = - client.enrich().stats(statsRequest, RequestOptions.DEFAULT); - // end::enrich-stats-execute - - // tag::enrich-stats-response - List executingPolicies = - statsResponse.getExecutingPolicies(); // <1> - List coordinatorStats = - statsResponse.getCoordinatorStats(); // <2> - // end::enrich-stats-response - - // tag::enrich-stats-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(StatsResponse response) { // <1> - List executingPolicies = - statsResponse.getExecutingPolicies(); - List coordinatorStats = - statsResponse.getCoordinatorStats(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::enrich-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::enrich-stats-execute-async - client.enrich().statsAsync(statsRequest, RequestOptions.DEFAULT, - listener); // <1> - // end::enrich-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testExecutePolicy() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexRequest createIndexRequest = new CreateIndexRequest("users").mapping( - Map.of("properties", Map.of("email", Map.of("type", "keyword"))) - ); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - PutPolicyRequest putPolicyRequest = new PutPolicyRequest( - "users-policy", - "match", - List.of("users"), - "email", - List.of("address", "zip", "city", "state") - ); - client.enrich().putPolicy(putPolicyRequest, RequestOptions.DEFAULT); - } - - // tag::enrich-execute-policy-request - ExecutePolicyRequest request = - new ExecutePolicyRequest("users-policy"); - // end::enrich-execute-policy-request - - // tag::enrich-execute-policy-execute - ExecutePolicyResponse response = - client.enrich().executePolicy(request, RequestOptions.DEFAULT); - // end::enrich-execute-policy-execute - - // tag::enrich-execute-policy-response - ExecutePolicyResponse.ExecutionStatus status = - response.getExecutionStatus(); - // end::enrich-execute-policy-response - - // tag::enrich-execute-policy-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(ExecutePolicyResponse response) { // <1> - ExecutePolicyResponse.ExecutionStatus status = - response.getExecutionStatus(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::enrich-execute-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::enrich-execute-policy-execute-async - client.enrich().executePolicyAsync(request, RequestOptions.DEFAULT, - listener); // <1> - // end::enrich-execute-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/GraphDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/GraphDocumentationIT.java deleted file mode 100644 index 64506d6d2642..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/GraphDocumentationIT.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.documentation; - -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.graph.Connection; -import org.elasticsearch.client.graph.GraphExploreRequest; -import org.elasticsearch.client.graph.GraphExploreResponse; -import org.elasticsearch.client.graph.Hop; -import org.elasticsearch.client.graph.Vertex; -import org.elasticsearch.client.graph.VertexRequest; -import org.elasticsearch.core.SuppressForbidden; -import org.elasticsearch.index.query.TermQueryBuilder; -import org.junit.Before; - -import java.io.IOException; -import java.util.Collection; - -@SuppressWarnings("removal") -public class GraphDocumentationIT extends ESRestHighLevelClientTestCase { - - @Before - public void indexDocuments() throws IOException { - // Create chain of doc IDs across indices 1->2->3 - Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/_doc/1"); - doc1.setJsonEntity(""" - {"participants":[1,2], "text":"let's start projectx", "attachment_md5":"324FHDGHFDG4564"}"""); - client().performRequest(doc1); - - Request doc2 = new Request(HttpPut.METHOD_NAME, "/index2/_doc/2"); - doc2.setJsonEntity(""" - {"participants":[2,3,4], "text":"got something you both may be interested in"}"""); - client().performRequest(doc2); - - client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh")); - } - - @SuppressForbidden(reason = "system out is ok for a documentation example") - public void testExplore() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::x-pack-graph-explore-request - GraphExploreRequest request = new GraphExploreRequest(); - request.indices("index1", "index2"); - request.useSignificance(false); - TermQueryBuilder startingQuery = new TermQueryBuilder("text", "projectx"); - - Hop hop1 = request.createNextHop(startingQuery); // <1> - VertexRequest people = hop1.addVertexRequest("participants"); // <2> - people.minDocCount(1); - VertexRequest files = hop1.addVertexRequest("attachment_md5"); - files.minDocCount(1); - - Hop hop2 = request.createNextHop(null); // <3> - VertexRequest vr2 = hop2.addVertexRequest("participants"); - vr2.minDocCount(5); - - GraphExploreResponse exploreResponse = client.graph().explore(request, RequestOptions.DEFAULT); // <4> - // end::x-pack-graph-explore-request - - // tag::x-pack-graph-explore-response - Collection v = exploreResponse.getVertices(); - Collection c = exploreResponse.getConnections(); - for (Vertex vertex : v) { - System.out.println(vertex.getField() + ":" + vertex.getTerm() + // <1> - " discovered at hop depth " + vertex.getHopDepth()); - } - for (Connection link : c) { - System.out.println(link.getFrom() + " -> " + link.getTo() // <2> - + " evidenced by " + link.getDocCount() + " docs"); - } - // end::x-pack-graph-explore-response - - Collection initialVertices = exploreResponse.getVertices(); - - // tag::x-pack-graph-explore-expand - GraphExploreRequest expandRequest = new GraphExploreRequest(); - expandRequest.indices("index1", "index2"); - - - Hop expandHop1 = expandRequest.createNextHop(null); // <1> - VertexRequest fromPeople = expandHop1.addVertexRequest("participants"); // <2> - for (Vertex vertex : initialVertices) { - if (vertex.getField().equals("participants")) { - fromPeople.addInclude(vertex.getTerm(), 1f); - } - } - - Hop expandHop2 = expandRequest.createNextHop(null); - VertexRequest newPeople = expandHop2.addVertexRequest("participants"); // <3> - for (Vertex vertex : initialVertices) { - if (vertex.getField().equals("participants")) { - newPeople.addExclude(vertex.getTerm()); - } - } - - GraphExploreResponse expandResponse = client.graph().explore(expandRequest, RequestOptions.DEFAULT); - // end::x-pack-graph-explore-expand - - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java deleted file mode 100644 index 1be3802c3681..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java +++ /dev/null @@ -1,1204 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; -import org.elasticsearch.action.admin.indices.alias.Alias; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.AcknowledgedResponse; -import org.elasticsearch.client.ilm.DeleteAction; -import org.elasticsearch.client.ilm.DeleteLifecyclePolicyRequest; -import org.elasticsearch.client.ilm.ExplainLifecycleRequest; -import org.elasticsearch.client.ilm.ExplainLifecycleResponse; -import org.elasticsearch.client.ilm.GetLifecyclePolicyRequest; -import org.elasticsearch.client.ilm.GetLifecyclePolicyResponse; -import org.elasticsearch.client.ilm.IndexLifecycleExplainResponse; -import org.elasticsearch.client.ilm.LifecycleAction; -import org.elasticsearch.client.ilm.LifecycleManagementStatusRequest; -import org.elasticsearch.client.ilm.LifecycleManagementStatusResponse; -import org.elasticsearch.client.ilm.LifecyclePolicy; -import org.elasticsearch.client.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.client.ilm.OperationMode; -import org.elasticsearch.client.ilm.Phase; -import org.elasticsearch.client.ilm.PutLifecyclePolicyRequest; -import org.elasticsearch.client.ilm.RemoveIndexLifecyclePolicyRequest; -import org.elasticsearch.client.ilm.RemoveIndexLifecyclePolicyResponse; -import org.elasticsearch.client.ilm.RetryLifecyclePolicyRequest; -import org.elasticsearch.client.ilm.RolloverAction; -import org.elasticsearch.client.ilm.ShrinkAction; -import org.elasticsearch.client.ilm.StartILMRequest; -import org.elasticsearch.client.ilm.StopILMRequest; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.slm.DeleteSnapshotLifecyclePolicyRequest; -import org.elasticsearch.client.slm.ExecuteSnapshotLifecyclePolicyRequest; -import org.elasticsearch.client.slm.ExecuteSnapshotLifecyclePolicyResponse; -import org.elasticsearch.client.slm.ExecuteSnapshotLifecycleRetentionRequest; -import org.elasticsearch.client.slm.GetSnapshotLifecyclePolicyRequest; -import org.elasticsearch.client.slm.GetSnapshotLifecyclePolicyResponse; -import org.elasticsearch.client.slm.GetSnapshotLifecycleStatsRequest; -import org.elasticsearch.client.slm.GetSnapshotLifecycleStatsResponse; -import org.elasticsearch.client.slm.PutSnapshotLifecyclePolicyRequest; -import org.elasticsearch.client.slm.SnapshotInvocationRecord; -import org.elasticsearch.client.slm.SnapshotLifecycleManagementStatusRequest; -import org.elasticsearch.client.slm.SnapshotLifecyclePolicy; -import org.elasticsearch.client.slm.SnapshotLifecyclePolicyMetadata; -import org.elasticsearch.client.slm.SnapshotLifecycleStats; -import org.elasticsearch.client.slm.SnapshotRetentionConfiguration; -import org.elasticsearch.client.slm.StartSLMRequest; -import org.elasticsearch.client.slm.StopSLMRequest; -import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.repositories.fs.FsRepository; -import org.elasticsearch.snapshots.SnapshotInfo; -import org.elasticsearch.snapshots.SnapshotState; -import org.hamcrest.Matchers; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; - -@SuppressWarnings("removal") -public class ILMDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testPutLifecyclePolicy() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::ilm-put-lifecycle-policy-request - Map phases = new HashMap<>(); - Map hotActions = new HashMap<>(); - hotActions.put(RolloverAction.NAME, new RolloverAction( - new ByteSizeValue(50, ByteSizeUnit.GB), null, null, null)); - phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions)); // <1> - - Map deleteActions = - Collections.singletonMap(DeleteAction.NAME, new DeleteAction()); - phases.put("delete", new Phase("delete", - new TimeValue(90, TimeUnit.DAYS), deleteActions)); // <2> - - LifecyclePolicy policy = new LifecyclePolicy("my_policy", - phases); // <3> - PutLifecyclePolicyRequest request = - new PutLifecyclePolicyRequest(policy); - // end::ilm-put-lifecycle-policy-request - - // tag::ilm-put-lifecycle-policy-execute - AcknowledgedResponse response = client.indexLifecycle(). - putLifecyclePolicy(request, RequestOptions.DEFAULT); - // end::ilm-put-lifecycle-policy-execute - - // tag::ilm-put-lifecycle-policy-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ilm-put-lifecycle-policy-response - - assertTrue(acknowledged); - - // Delete the policy so it can be added again - { - DeleteLifecyclePolicyRequest deleteRequest = new DeleteLifecyclePolicyRequest("my_policy"); - AcknowledgedResponse deleteResponse = client.indexLifecycle().deleteLifecyclePolicy(deleteRequest, RequestOptions.DEFAULT); - assertTrue(deleteResponse.isAcknowledged()); - } - - // tag::ilm-put-lifecycle-policy-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-put-lifecycle-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-put-lifecycle-policy-execute-async - client.indexLifecycle().putLifecyclePolicyAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-put-lifecycle-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - } - - public void testDeletePolicy() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - // Set up a policy so we have something to delete - PutLifecyclePolicyRequest putRequest; - { - Map phases = new HashMap<>(); - Map hotActions = new HashMap<>(); - hotActions.put(RolloverAction.NAME, new RolloverAction(new ByteSizeValue(50, ByteSizeUnit.GB), null, null, null)); - phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions)); - Map deleteActions = Collections.singletonMap(DeleteAction.NAME, new DeleteAction()); - phases.put("delete", new Phase("delete", new TimeValue(90, TimeUnit.DAYS), deleteActions)); - LifecyclePolicy myPolicy = new LifecyclePolicy("my_policy", phases); - putRequest = new PutLifecyclePolicyRequest(myPolicy); - AcknowledgedResponse putResponse = client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); - assertTrue(putResponse.isAcknowledged()); - } - - // tag::ilm-delete-lifecycle-policy-request - DeleteLifecyclePolicyRequest request = - new DeleteLifecyclePolicyRequest("my_policy"); // <1> - // end::ilm-delete-lifecycle-policy-request - - // tag::ilm-delete-lifecycle-policy-execute - AcknowledgedResponse response = client.indexLifecycle() - .deleteLifecyclePolicy(request, RequestOptions.DEFAULT); - // end::ilm-delete-lifecycle-policy-execute - - // tag::ilm-delete-lifecycle-policy-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ilm-delete-lifecycle-policy-response - - assertTrue(acknowledged); - - // Put the policy again so we can delete it again - { - AcknowledgedResponse putResponse = client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); - assertTrue(putResponse.isAcknowledged()); - } - - // tag::ilm-delete-lifecycle-policy-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-delete-lifecycle-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-delete-lifecycle-policy-execute-async - client.indexLifecycle().deleteLifecyclePolicyAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-delete-lifecycle-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetLifecyclePolicy() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - LifecyclePolicy myPolicyAsPut; - LifecyclePolicy otherPolicyAsPut; - // Set up some policies so we have something to get - { - Map phases = new HashMap<>(); - Map hotActions = new HashMap<>(); - hotActions.put(RolloverAction.NAME, new RolloverAction(new ByteSizeValue(50, ByteSizeUnit.GB), null, null, null)); - phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions)); - - Map deleteActions = Collections.singletonMap(DeleteAction.NAME, new DeleteAction()); - phases.put("delete", new Phase("delete", new TimeValue(90, TimeUnit.DAYS), deleteActions)); - - myPolicyAsPut = new LifecyclePolicy("my_policy", phases); - PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(myPolicyAsPut); - - Map otherPolicyPhases = new HashMap<>(phases); - Map warmActions = Collections.singletonMap(ShrinkAction.NAME, new ShrinkAction(1, null)); - otherPolicyPhases.put("warm", new Phase("warm", new TimeValue(30, TimeUnit.DAYS), warmActions)); - otherPolicyAsPut = new LifecyclePolicy("other_policy", otherPolicyPhases); - - PutLifecyclePolicyRequest putRequest2 = new PutLifecyclePolicyRequest(otherPolicyAsPut); - - AcknowledgedResponse putResponse = client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); - assertTrue(putResponse.isAcknowledged()); - AcknowledgedResponse putResponse2 = client.indexLifecycle().putLifecyclePolicy(putRequest2, RequestOptions.DEFAULT); - assertTrue(putResponse2.isAcknowledged()); - } - - // tag::ilm-get-lifecycle-policy-request - GetLifecyclePolicyRequest allRequest = - new GetLifecyclePolicyRequest(); // <1> - GetLifecyclePolicyRequest request = - new GetLifecyclePolicyRequest("my_policy", "other_policy"); // <2> - // end::ilm-get-lifecycle-policy-request - - // tag::ilm-get-lifecycle-policy-execute - GetLifecyclePolicyResponse response = client.indexLifecycle() - .getLifecyclePolicy(request, RequestOptions.DEFAULT); - // end::ilm-get-lifecycle-policy-execute - - // tag::ilm-get-lifecycle-policy-response - ImmutableOpenMap policies = - response.getPolicies(); - LifecyclePolicyMetadata myPolicyMetadata = - policies.get("my_policy"); // <1> - String myPolicyName = myPolicyMetadata.getName(); - long version = myPolicyMetadata.getVersion(); - String lastModified = myPolicyMetadata.getModifiedDateString(); - long lastModifiedDate = myPolicyMetadata.getModifiedDate(); - LifecyclePolicy myPolicy = myPolicyMetadata.getPolicy(); // <2> - // end::ilm-get-lifecycle-policy-response - - assertEquals(myPolicyAsPut, myPolicy); - assertEquals("my_policy", myPolicyName); - assertNotNull(lastModified); - assertNotEquals(0, lastModifiedDate); - - LifecyclePolicyMetadata otherPolicyMetadata = policies.get("other_policy"); - assertEquals(otherPolicyAsPut, otherPolicyMetadata.getPolicy()); - assertEquals("other_policy", otherPolicyMetadata.getName()); - assertNotNull(otherPolicyMetadata.getModifiedDateString()); - assertNotEquals(0, otherPolicyMetadata.getModifiedDate()); - - // tag::ilm-get-lifecycle-policy-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetLifecyclePolicyResponse response) - { - ImmutableOpenMap - policies = response.getPolicies(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-get-lifecycle-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-get-lifecycle-policy-execute-async - client.indexLifecycle().getLifecyclePolicyAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-get-lifecycle-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testExplainLifecycle() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // create a policy & index - { - Map phases = new HashMap<>(); - Map hotActions = new HashMap<>(); - hotActions.put(RolloverAction.NAME, new RolloverAction(new ByteSizeValue(50, ByteSizeUnit.GB), null, null, null)); - phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions)); - - LifecyclePolicy policy = new LifecyclePolicy("my_policy", phases); - PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy); - client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); - - CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index-1").settings( - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put("index.lifecycle.name", "my_policy") - .put("index.lifecycle.rollover_alias", "my_alias") - .build() - ); - createIndexRequest.alias(new Alias("my_alias").writeIndex(true)); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - CreateIndexRequest createOtherIndexRequest = new CreateIndexRequest("other_index").settings( - Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build() - ); - client.indices().create(createOtherIndexRequest, RequestOptions.DEFAULT); - - // wait for the policy to become active - assertBusy( - () -> assertNotNull( - client.indexLifecycle() - .explainLifecycle(new ExplainLifecycleRequest("my_index-1"), RequestOptions.DEFAULT) - .getIndexResponses() - .get("my_index-1") - .getAction() - ) - ); - } - - // tag::ilm-explain-lifecycle-request - ExplainLifecycleRequest request = - new ExplainLifecycleRequest("my_index-1", "other_index"); // <1> - // end::ilm-explain-lifecycle-request - - assertBusy(() -> { - // tag::ilm-explain-lifecycle-execute - ExplainLifecycleResponse response = client.indexLifecycle() - .explainLifecycle(request, RequestOptions.DEFAULT); - // end::ilm-explain-lifecycle-execute - assertNotNull(response); - - // tag::ilm-explain-lifecycle-response - Map indices = - response.getIndexResponses(); - IndexLifecycleExplainResponse myIndex = indices.get("my_index-1"); - String policyName = myIndex.getPolicyName(); // <1> - boolean isManaged = myIndex.managedByILM(); // <2> - - String phase = myIndex.getPhase(); // <3> - long phaseTime = myIndex.getPhaseTime(); // <4> - String action = myIndex.getAction(); // <5> - long actionTime = myIndex.getActionTime(); - String step = myIndex.getStep(); // <6> - long stepTime = myIndex.getStepTime(); - - String failedStep = myIndex.getFailedStep(); // <7> - // end::ilm-explain-lifecycle-response - - assertEquals("my_policy", policyName); - assertTrue(isManaged); - - assertEquals("hot", phase); - assertNotEquals(0, phaseTime); - assertEquals("rollover", action); - assertNotEquals(0, actionTime); - assertEquals("check-rollover-ready", step); - assertNotEquals(0, stepTime); - - assertNull(failedStep); - - IndexLifecycleExplainResponse otherIndex = indices.get("other_index"); - assertFalse(otherIndex.managedByILM()); - assertNull(otherIndex.getPolicyName()); - assertNull(otherIndex.getPhase()); - assertNull(otherIndex.getAction()); - assertNull(otherIndex.getStep()); - assertNull(otherIndex.getFailedStep()); - assertNull(otherIndex.getPhaseExecutionInfo()); - assertNull(otherIndex.getStepInfo()); - }); - - // tag::ilm-explain-lifecycle-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ExplainLifecycleResponse response) - { - Map indices = - response.getIndexResponses(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-explain-lifecycle-execute-listener - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-explain-lifecycle-execute-async - client.indexLifecycle().explainLifecycleAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-explain-lifecycle-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testILMStartStopStatus() throws Exception { - RestHighLevelClient client = highLevelClient(); - - stopILM(client); - - // tag::ilm-status-request - LifecycleManagementStatusRequest request = - new LifecycleManagementStatusRequest(); - // end::ilm-status-request - - // Check that ILM has stopped - { - // tag::ilm-status-execute - LifecycleManagementStatusResponse response = - client.indexLifecycle() - .lifecycleManagementStatus(request, RequestOptions.DEFAULT); - // end::ilm-status-execute - - // tag::ilm-status-response - OperationMode operationMode = response.getOperationMode(); // <1> - // end::ilm-status-response - - assertThat(operationMode, Matchers.either(equalTo(OperationMode.STOPPING)).or(equalTo(OperationMode.STOPPED))); - } - - startILM(client); - - // tag::ilm-status-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse( - LifecycleManagementStatusResponse response) { - OperationMode operationMode = response - .getOperationMode(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-status-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-status-execute-async - client.indexLifecycle().lifecycleManagementStatusAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-status-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // Check that ILM is running again - LifecycleManagementStatusResponse response = client.indexLifecycle().lifecycleManagementStatus(request, RequestOptions.DEFAULT); - - OperationMode operationMode = response.getOperationMode(); - assertEquals(OperationMode.RUNNING, operationMode); - } - - private void stopILM(RestHighLevelClient client) throws IOException, InterruptedException { - // tag::ilm-stop-ilm-request - StopILMRequest request = new StopILMRequest(); - // end::ilm-stop-ilm-request - - // tag::ilm-stop-ilm-execute - AcknowledgedResponse response = client.indexLifecycle() - .stopILM(request, RequestOptions.DEFAULT); - // end::ilm-stop-ilm-execute - - // tag::ilm-stop-ilm-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ilm-stop-ilm-response - assertTrue(acknowledged); - - // tag::ilm-stop-ilm-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-stop-ilm-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-stop-ilm-execute-async - client.indexLifecycle().stopILMAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-stop-ilm-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - private void startILM(RestHighLevelClient client) throws IOException, InterruptedException { - // tag::ilm-start-ilm-request - StartILMRequest request1 = new StartILMRequest(); - // end::ilm-start-ilm-request - - // tag::ilm-start-ilm-execute - AcknowledgedResponse response = client.indexLifecycle() - .startILM(request1, RequestOptions.DEFAULT); - // end::ilm-start-ilm-execute - - // tag::ilm-start-ilm-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ilm-start-ilm-response - - assertTrue(acknowledged); - - // tag::ilm-start-ilm-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-start-ilm-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-start-ilm-execute-async - client.indexLifecycle().startILMAsync(request1, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-start-ilm-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testRetryPolicy() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // setup policy to immediately fail on index - { - Map phases = new HashMap<>(); - Map warmActions = new HashMap<>(); - warmActions.put(ShrinkAction.NAME, new ShrinkAction(3, null)); - phases.put("warm", new Phase("warm", TimeValue.ZERO, warmActions)); - - LifecyclePolicy policy = new LifecyclePolicy("my_policy", phases); - PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy); - client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); - - CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index").settings( - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put("index.lifecycle.name", "my_policy") - .build() - ); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - } - - // tag::ilm-retry-lifecycle-policy-request - RetryLifecyclePolicyRequest request = - new RetryLifecyclePolicyRequest("my_index"); // <1> - // end::ilm-retry-lifecycle-policy-request - - try { - // tag::ilm-retry-lifecycle-policy-execute - AcknowledgedResponse response = client.indexLifecycle() - .retryLifecyclePolicy(request, RequestOptions.DEFAULT); - // end::ilm-retry-lifecycle-policy-execute - - // tag::ilm-retry-lifecycle-policy-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::ilm-retry-lifecycle-policy-response - - assertTrue(acknowledged); - } catch (ElasticsearchException e) { - // the retry API might fail as the shrink action steps are retryable (ILM will stuck in the `check-target-shards-count` step - // with no failure, the retry API will fail) - // assert that's the exception we encountered (we want to test to fail if there is an actual error with the retry api) - assertThat( - e.getMessage(), - containsStringIgnoringCase( - "reason=cannot retry an action for an index [my_index] that has not " - + "encountered an error when running a Lifecycle Policy" - ) - ); - } - - // tag::ilm-retry-lifecycle-policy-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-retry-lifecycle-policy-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-retry-lifecycle-policy-execute-async - client.indexLifecycle().retryLifecyclePolicyAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-retry-lifecycle-policy-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testRemovePolicyFromIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // setup policy for index - Map phases = new HashMap<>(); - phases.put( - "delete", - new Phase("delete", TimeValue.timeValueHours(10L), Collections.singletonMap(DeleteAction.NAME, new DeleteAction())) - ); - LifecyclePolicy policy = new LifecyclePolicy("my_policy", phases); - PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy); - client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); - CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index").settings( - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put("index.lifecycle.name", "my_policy") - .build() - ); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertBusy( - () -> assertTrue( - client.indexLifecycle() - .explainLifecycle(new ExplainLifecycleRequest("my_index"), RequestOptions.DEFAULT) - .getIndexResponses() - .get("my_index") - .managedByILM() - ) - ); - - // tag::ilm-remove-lifecycle-policy-from-index-request - List indices = new ArrayList<>(); - indices.add("my_index"); - RemoveIndexLifecyclePolicyRequest request = - new RemoveIndexLifecyclePolicyRequest(indices); // <1> - // end::ilm-remove-lifecycle-policy-from-index-request - - // tag::ilm-remove-lifecycle-policy-from-index-execute - RemoveIndexLifecyclePolicyResponse response = client - .indexLifecycle() - .removeIndexLifecyclePolicy(request, RequestOptions.DEFAULT); - // end::ilm-remove-lifecycle-policy-from-index-execute - - // tag::ilm-remove-lifecycle-policy-from-index-response - boolean hasFailures = response.hasFailures(); // <1> - List failedIndexes = response.getFailedIndexes(); // <2> - // end::ilm-remove-lifecycle-policy-from-index-response - - { - assertFalse(hasFailures); - Map indexSettings = getIndexSettings("my_index"); - assertTrue(Strings.isNullOrEmpty((String) indexSettings.get("index.lifecycle.name"))); - } - - // re-apply policy on index - updateIndexSettings("my_index", Settings.builder().put("index.lifecycle.name", "my_policy")); - assertBusy( - () -> assertTrue( - client.indexLifecycle() - .explainLifecycle(new ExplainLifecycleRequest("my_index"), RequestOptions.DEFAULT) - .getIndexResponses() - .get("my_index") - .managedByILM() - ) - ); - - // tag::ilm-remove-lifecycle-policy-from-index-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse( - RemoveIndexLifecyclePolicyResponse response) { - boolean hasFailures = response.hasFailures(); // <1> - List failedIndexes = response.getFailedIndexes(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ilm-remove-lifecycle-policy-from-index-execute-listener - - { - Map indexSettings = getIndexSettings("my_index"); - assertTrue(Strings.isNullOrEmpty((String) indexSettings.get("index.lifecycle.name"))); - } - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ilm-remove-lifecycle-policy-from-index-execute-async - client.indexLifecycle().removeIndexLifecyclePolicyAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::ilm-remove-lifecycle-policy-from-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/73317") - public void testAddSnapshotLifecyclePolicy() throws Exception { - RestHighLevelClient client = highLevelClient(); - - PutRepositoryRequest repoRequest = new PutRepositoryRequest(); - - Settings.Builder settingsBuilder = Settings.builder().put("location", "."); - repoRequest.settings(settingsBuilder); - repoRequest.name("my_repository"); - repoRequest.type(FsRepository.TYPE); - org.elasticsearch.action.support.master.AcknowledgedResponse response = client.snapshot() - .createRepository(repoRequest, RequestOptions.DEFAULT); - assertTrue(response.isAcknowledged()); - - //////// PUT - // tag::slm-put-snapshot-lifecycle-policy-request - Map config = new HashMap<>(); - config.put("indices", Collections.singletonList("idx")); - SnapshotRetentionConfiguration retention = - new SnapshotRetentionConfiguration(TimeValue.timeValueDays(30), 2, 10); - SnapshotLifecyclePolicy policy = new SnapshotLifecyclePolicy( - "policy_id", "name", "1 2 3 * * ?", - "my_repository", config, retention); - PutSnapshotLifecyclePolicyRequest request = - new PutSnapshotLifecyclePolicyRequest(policy); - // end::slm-put-snapshot-lifecycle-policy-request - - // tag::slm-put-snapshot-lifecycle-policy-execute - AcknowledgedResponse resp = client.indexLifecycle() - .putSnapshotLifecyclePolicy(request, RequestOptions.DEFAULT); - // end::slm-put-snapshot-lifecycle-policy-execute - - // tag::slm-put-snapshot-lifecycle-policy-response - boolean putAcknowledged = resp.isAcknowledged(); // <1> - // end::slm-put-snapshot-lifecycle-policy-response - assertTrue(putAcknowledged); - - // tag::slm-put-snapshot-lifecycle-policy-execute-listener - ActionListener putListener = - new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse resp) { - boolean acknowledged = resp.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-put-snapshot-lifecycle-policy-execute-listener - - // tag::slm-put-snapshot-lifecycle-policy-execute-async - client.indexLifecycle().putSnapshotLifecyclePolicyAsync(request, - RequestOptions.DEFAULT, putListener); // <1> - // end::slm-put-snapshot-lifecycle-policy-execute-async - - //////// GET - // tag::slm-get-snapshot-lifecycle-policy-request - GetSnapshotLifecyclePolicyRequest getAllRequest = - new GetSnapshotLifecyclePolicyRequest(); // <1> - GetSnapshotLifecyclePolicyRequest getRequest = - new GetSnapshotLifecyclePolicyRequest("policy_id"); // <2> - // end::slm-get-snapshot-lifecycle-policy-request - - // tag::slm-get-snapshot-lifecycle-policy-execute - GetSnapshotLifecyclePolicyResponse getResponse = - client.indexLifecycle() - .getSnapshotLifecyclePolicy(getRequest, - RequestOptions.DEFAULT); - // end::slm-get-snapshot-lifecycle-policy-execute - - // tag::slm-get-snapshot-lifecycle-policy-execute-listener - ActionListener getListener = - new ActionListener<>() { - @Override - public void onResponse(GetSnapshotLifecyclePolicyResponse resp) { - Map policies = - resp.getPolicies(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-get-snapshot-lifecycle-policy-execute-listener - - // tag::slm-get-snapshot-lifecycle-policy-execute-async - client.indexLifecycle().getSnapshotLifecyclePolicyAsync(getRequest, - RequestOptions.DEFAULT, getListener); // <1> - // end::slm-get-snapshot-lifecycle-policy-execute-async - - assertThat(getResponse.getPolicies().size(), equalTo(1)); - // tag::slm-get-snapshot-lifecycle-policy-response - SnapshotLifecyclePolicyMetadata policyMeta = - getResponse.getPolicies().get("policy_id"); // <1> - long policyVersion = policyMeta.getVersion(); - long policyModificationDate = policyMeta.getModifiedDate(); - long nextPolicyExecutionDate = policyMeta.getNextExecution(); - SnapshotInvocationRecord lastSuccess = policyMeta.getLastSuccess(); - SnapshotInvocationRecord lastFailure = policyMeta.getLastFailure(); - SnapshotLifecyclePolicyMetadata.SnapshotInProgress inProgress = - policyMeta.getSnapshotInProgress(); - SnapshotLifecyclePolicy retrievedPolicy = policyMeta.getPolicy(); // <2> - String id = retrievedPolicy.getId(); - String snapshotNameFormat = retrievedPolicy.getName(); - String repositoryName = retrievedPolicy.getRepository(); - String schedule = retrievedPolicy.getSchedule(); - Map snapshotConfiguration = retrievedPolicy.getConfig(); - // end::slm-get-snapshot-lifecycle-policy-response - - assertNotNull(policyMeta); - assertThat(retrievedPolicy, equalTo(policy)); - - createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); - - //////// EXECUTE - // tag::slm-execute-snapshot-lifecycle-policy-request - ExecuteSnapshotLifecyclePolicyRequest executeRequest = - new ExecuteSnapshotLifecyclePolicyRequest("policy_id"); // <1> - // end::slm-execute-snapshot-lifecycle-policy-request - - // tag::slm-execute-snapshot-lifecycle-policy-execute - ExecuteSnapshotLifecyclePolicyResponse executeResponse = - client.indexLifecycle() - .executeSnapshotLifecyclePolicy(executeRequest, - RequestOptions.DEFAULT); - // end::slm-execute-snapshot-lifecycle-policy-execute - - // tag::slm-execute-snapshot-lifecycle-policy-response - final String snapshotName = executeResponse.getSnapshotName(); // <1> - // end::slm-execute-snapshot-lifecycle-policy-response - - assertSnapshotExists(client, "my_repository", snapshotName); - - // tag::slm-execute-snapshot-lifecycle-policy-execute-listener - ActionListener executeListener = - new ActionListener<>() { - @Override - public void onResponse(ExecuteSnapshotLifecyclePolicyResponse r) { - String snapshotName = r.getSnapshotName(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-execute-snapshot-lifecycle-policy-execute-listener - - // We need a listener that will actually wait for the snapshot to be created - CountDownLatch latch = new CountDownLatch(1); - executeListener = new ActionListener<>() { - @Override - public void onResponse(ExecuteSnapshotLifecyclePolicyResponse r) { - try { - assertSnapshotExists(client, "my_repository", r.getSnapshotName()); - } catch (Exception e) { - // Ignore - } finally { - latch.countDown(); - } - } - - @Override - public void onFailure(Exception e) { - latch.countDown(); - fail("failed to execute slm execute: " + e); - } - }; - - // tag::slm-execute-snapshot-lifecycle-policy-execute-async - client.indexLifecycle() - .executeSnapshotLifecyclePolicyAsync(executeRequest, - RequestOptions.DEFAULT, executeListener); // <1> - // end::slm-execute-snapshot-lifecycle-policy-execute-async - latch.await(5, TimeUnit.SECONDS); - - // tag::slm-get-snapshot-lifecycle-stats - GetSnapshotLifecycleStatsRequest getStatsRequest = - new GetSnapshotLifecycleStatsRequest(); - // end::slm-get-snapshot-lifecycle-stats - - // tag::slm-get-snapshot-lifecycle-stats-execute - GetSnapshotLifecycleStatsResponse statsResp = client.indexLifecycle() - .getSnapshotLifecycleStats(getStatsRequest, RequestOptions.DEFAULT); - SnapshotLifecycleStats stats = statsResp.getStats(); - SnapshotLifecycleStats.SnapshotPolicyStats policyStats = - stats.getMetrics().get("policy_id"); - // end::slm-get-snapshot-lifecycle-stats-execute - assertThat(statsResp.getStats().getMetrics().get("policy_id").getSnapshotsTaken(), greaterThanOrEqualTo(1L)); - - //////// DELETE - // tag::slm-delete-snapshot-lifecycle-policy-request - DeleteSnapshotLifecyclePolicyRequest deleteRequest = - new DeleteSnapshotLifecyclePolicyRequest("policy_id"); // <1> - // end::slm-delete-snapshot-lifecycle-policy-request - - // tag::slm-delete-snapshot-lifecycle-policy-execute - AcknowledgedResponse deleteResp = client.indexLifecycle() - .deleteSnapshotLifecyclePolicy(deleteRequest, RequestOptions.DEFAULT); - // end::slm-delete-snapshot-lifecycle-policy-execute - - // tag::slm-delete-snapshot-lifecycle-policy-response - boolean deleteAcknowledged = deleteResp.isAcknowledged(); // <1> - // end::slm-delete-snapshot-lifecycle-policy-response - - assertTrue(deleteResp.isAcknowledged()); - - // tag::slm-delete-snapshot-lifecycle-policy-execute-listener - ActionListener deleteListener = - new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse resp) { - boolean deleteAcknowledged = resp.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-delete-snapshot-lifecycle-policy-execute-listener - - // tag::slm-delete-snapshot-lifecycle-policy-execute-async - client.indexLifecycle() - .deleteSnapshotLifecyclePolicyAsync(deleteRequest, - RequestOptions.DEFAULT, deleteListener); // <1> - // end::slm-delete-snapshot-lifecycle-policy-execute-async - - assertTrue(deleteResp.isAcknowledged()); - - //////// EXECUTE RETENTION - // tag::slm-execute-snapshot-lifecycle-retention-request - ExecuteSnapshotLifecycleRetentionRequest req = - new ExecuteSnapshotLifecycleRetentionRequest(); - // end::slm-execute-snapshot-lifecycle-retention-request - - // tag::slm-execute-snapshot-lifecycle-retention-execute - AcknowledgedResponse retentionResp = - client.indexLifecycle() - .executeSnapshotLifecycleRetention(req, - RequestOptions.DEFAULT); - // end::slm-execute-snapshot-lifecycle-retention-execute - - // tag::slm-execute-snapshot-lifecycle-retention-response - final boolean acked = retentionResp.isAcknowledged(); - // end::slm-execute-snapshot-lifecycle-retention-response - - // tag::slm-execute-snapshot-lifecycle-retention-execute-listener - ActionListener retentionListener = - new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse r) { - assert r.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-execute-snapshot-lifecycle-retention-execute-listener - - // tag::slm-execute-snapshot-lifecycle-retention-execute-async - client.indexLifecycle() - .executeSnapshotLifecycleRetentionAsync(req, - RequestOptions.DEFAULT, retentionListener); // <1> - // end::slm-execute-snapshot-lifecycle-retention-execute-async - } - - private void assertSnapshotExists(final RestHighLevelClient client, final String repo, final String snapshotName) throws Exception { - assertBusy(() -> { - GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(new String[] { repo }, new String[] { snapshotName }); - try { - final GetSnapshotsResponse snaps = client.snapshot().get(getSnapshotsRequest, RequestOptions.DEFAULT); - Optional info = snaps.getSnapshots().stream().findFirst(); - if (info.isPresent()) { - info.ifPresent(si -> { - assertThat(si.snapshotId().getName(), equalTo(snapshotName)); - assertThat(si.state(), equalTo(SnapshotState.SUCCESS)); - }); - } else { - fail("unable to find snapshot; " + snapshotName); - } - } catch (Exception e) { - if (e.getMessage().contains("snapshot_missing_exception")) { - fail("snapshot does not exist: " + snapshotName); - } else if (e.getMessage().contains("repository_exception")) { - fail("got a respository_exception, retrying. original message: " + e.getMessage()); - } - throw e; - } - }); - } - - public void testSLMStartStopStatus() throws Exception { - RestHighLevelClient client = highLevelClient(); - - stopSLM(client); - - // tag::slm-status-request - SnapshotLifecycleManagementStatusRequest request = - new SnapshotLifecycleManagementStatusRequest(); - // end::slm-status-request - - // Check that SLM has stopped - { - // tag::slm-status-execute - LifecycleManagementStatusResponse response = - client.indexLifecycle() - .getSLMStatus(request, RequestOptions.DEFAULT); - // end::slm-status-execute - - // tag::slm-status-response - OperationMode operationMode = response.getOperationMode(); // <1> - // end::slm-status-response - - assertThat(operationMode, Matchers.either(equalTo(OperationMode.STOPPING)).or(equalTo(OperationMode.STOPPED))); - } - - startSLM(client); - - // tag::slm-status-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse( - LifecycleManagementStatusResponse response) { - OperationMode operationMode = response - .getOperationMode(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-status-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::slm-status-execute-async - client.indexLifecycle().getSLMStatusAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::slm-status-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // Check that SLM is running again - LifecycleManagementStatusResponse response = client.indexLifecycle().getSLMStatus(request, RequestOptions.DEFAULT); - - OperationMode operationMode = response.getOperationMode(); - assertEquals(OperationMode.RUNNING, operationMode); - } - - private void stopSLM(RestHighLevelClient client) throws IOException, InterruptedException { - // tag::slm-stop-slm-request - StopSLMRequest request = new StopSLMRequest(); - // end::slm-stop-slm-request - - // tag::slm-stop-slm-execute - AcknowledgedResponse response = client.indexLifecycle() - .stopSLM(request, RequestOptions.DEFAULT); - // end::slm-stop-slm-execute - - // tag::slm-stop-slm-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::slm-stop-slm-response - assertTrue(acknowledged); - - // tag::slm-stop-slm-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-stop-slm-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::slm-stop-slm-execute-async - client.indexLifecycle().stopSLMAsync(request, - RequestOptions.DEFAULT, listener); // <1> - // end::slm-stop-slm-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - private void startSLM(RestHighLevelClient client) throws IOException, InterruptedException { - // tag::slm-start-slm-request - StartSLMRequest request1 = new StartSLMRequest(); - // end::slm-start-slm-request - - // tag::slm-start-slm-execute - AcknowledgedResponse response = client.indexLifecycle() - .startSLM(request1, RequestOptions.DEFAULT); - // end::slm-start-slm-execute - - // tag::slm-start-slm-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::slm-start-slm-response - - assertTrue(acknowledged); - - // tag::slm-start-slm-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::slm-start-slm-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::slm-start-slm-execute-async - client.indexLifecycle().startSLMAsync(request1, - RequestOptions.DEFAULT, listener); // <1> - // end::slm-start-slm-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java deleted file mode 100644 index 83d7240ee577..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ /dev/null @@ -1,3179 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.indices.alias.Alias; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.flush.FlushResponse; -import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; -import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse; -import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; -import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; -import org.elasticsearch.action.admin.indices.shrink.ResizeRequest; -import org.elasticsearch.action.admin.indices.shrink.ResizeResponse; -import org.elasticsearch.action.admin.indices.shrink.ResizeType; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest; -import org.elasticsearch.action.admin.indices.validate.query.QueryExplanation; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; -import org.elasticsearch.action.support.ActiveShardCount; -import org.elasticsearch.action.support.DefaultShardOperationFailedException; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.GetAliasesResponse; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.BroadcastResponse.Shards; -import org.elasticsearch.client.core.ShardsAcknowledgedResponse; -import org.elasticsearch.client.indices.AnalyzeRequest; -import org.elasticsearch.client.indices.AnalyzeResponse; -import org.elasticsearch.client.indices.CloseIndexRequest; -import org.elasticsearch.client.indices.CloseIndexResponse; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.CreateIndexResponse; -import org.elasticsearch.client.indices.DeleteAliasRequest; -import org.elasticsearch.client.indices.DeleteComposableIndexTemplateRequest; -import org.elasticsearch.client.indices.DetailAnalyzeResponse; -import org.elasticsearch.client.indices.GetComposableIndexTemplateRequest; -import org.elasticsearch.client.indices.GetComposableIndexTemplatesResponse; -import org.elasticsearch.client.indices.GetFieldMappingsRequest; -import org.elasticsearch.client.indices.GetFieldMappingsResponse; -import org.elasticsearch.client.indices.GetIndexRequest; -import org.elasticsearch.client.indices.GetIndexResponse; -import org.elasticsearch.client.indices.GetIndexTemplatesRequest; -import org.elasticsearch.client.indices.GetIndexTemplatesResponse; -import org.elasticsearch.client.indices.GetMappingsRequest; -import org.elasticsearch.client.indices.GetMappingsResponse; -import org.elasticsearch.client.indices.IndexTemplateMetadata; -import org.elasticsearch.client.indices.IndexTemplatesExistRequest; -import org.elasticsearch.client.indices.PutComponentTemplateRequest; -import org.elasticsearch.client.indices.PutComposableIndexTemplateRequest; -import org.elasticsearch.client.indices.PutIndexTemplateRequest; -import org.elasticsearch.client.indices.PutMappingRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersResponse; -import org.elasticsearch.client.indices.ReloadAnalyzersResponse.ReloadDetails; -import org.elasticsearch.client.indices.SimulateIndexTemplateRequest; -import org.elasticsearch.client.indices.SimulateIndexTemplateResponse; -import org.elasticsearch.client.indices.UnfreezeIndexRequest; -import org.elasticsearch.client.indices.rollover.RolloverRequest; -import org.elasticsearch.client.indices.rollover.RolloverResponse; -import org.elasticsearch.cluster.metadata.AliasMetadata; -import org.elasticsearch.cluster.metadata.ComponentTemplate; -import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; -import org.elasticsearch.cluster.metadata.MappingMetadata; -import org.elasticsearch.cluster.metadata.Template; -import org.elasticsearch.common.compress.CompressedXContent; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentFactory; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.client.IndicesClientIT.FROZEN_INDICES_DEPRECATION_WARNING; -import static org.elasticsearch.client.IndicesClientIT.LEGACY_TEMPLATE_OPTIONS; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - -/** - * This class is used to generate the Java Indices 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,macros"] - * -------------------------------------------------- - * include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[example] - * -------------------------------------------------- - * - * The column width of the code block is 84. If the code contains a line longer - * than 84, the line will be cut and a horizontal scroll bar will be displayed. - * (the code indentation of the tag is not included in the width) - */ -@SuppressWarnings("removal") -public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testIndicesExist() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::indices-exists-request - GetIndexRequest request = new GetIndexRequest("twitter"); // <1> - // end::indices-exists-request - - IndicesOptions indicesOptions = IndicesOptions.strictExpand(); - // tag::indices-exists-request-optionals - request.local(false); // <1> - request.humanReadable(true); // <2> - request.includeDefaults(false); // <3> - request.indicesOptions(indicesOptions); // <4> - // end::indices-exists-request-optionals - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::indices-exists-execute - boolean exists = client.indices().exists(request, requestOptions); - // end::indices-exists-execute - assertTrue(exists); - } - } - - public void testIndicesExistAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - GetIndexRequest request = new GetIndexRequest("twitter"); - - // tag::indices-exists-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(Boolean exists) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::indices-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::indices-exists-execute-async - client.indices().existsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::indices-exists-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteIndex() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::delete-index-request - DeleteIndexRequest request = new DeleteIndexRequest("posts"); // <1> - // end::delete-index-request - - // tag::delete-index-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::delete-index-request-timeout - // tag::delete-index-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::delete-index-request-masterTimeout - // tag::delete-index-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::delete-index-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::delete-index-execute - AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, requestOptions); - // end::delete-index-execute - - // tag::delete-index-response - boolean acknowledged = deleteIndexResponse.isAcknowledged(); // <1> - // end::delete-index-response - assertTrue(acknowledged); - } - - { - // tag::delete-index-notfound - try { - DeleteIndexRequest request = new DeleteIndexRequest("does_not_exist"); - client.indices().delete(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.NOT_FOUND) { - // <1> - } - } - // end::delete-index-notfound - } - } - - public void testDeleteIndexAsync() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - DeleteIndexRequest request = new DeleteIndexRequest("posts"); - - // tag::delete-index-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse deleteIndexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-index-execute-async - client.indices().deleteAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testCreateIndex() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - // tag::create-index-request - CreateIndexRequest request = new CreateIndexRequest("twitter"); // <1> - // end::create-index-request - - // tag::create-index-request-settings - request.settings(Settings.builder() // <1> - .put("index.number_of_shards", 3) - .put("index.number_of_replicas", 2) - ); - // end::create-index-request-settings - - { - // tag::create-index-request-mappings - request.mapping(// <1> - """ - { - "properties": { - "message": { - "type": "text" - } - } - }""", // <2> - XContentType.JSON); - // end::create-index-request-mappings - CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - request = new CreateIndexRequest("twitter2"); - //tag::create-index-mappings-map - Map message = new HashMap<>(); - message.put("type", "text"); - Map properties = new HashMap<>(); - properties.put("message", message); - Map mapping = new HashMap<>(); - mapping.put("properties", properties); - request.mapping(mapping); // <1> - //end::create-index-mappings-map - CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - { - request = new CreateIndexRequest("twitter3"); - //tag::create-index-mappings-xcontent - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.startObject("properties"); - { - builder.startObject("message"); - { - builder.field("type", "text"); - } - builder.endObject(); - } - builder.endObject(); - } - builder.endObject(); - request.mapping(builder); // <1> - //end::create-index-mappings-xcontent - CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - request = new CreateIndexRequest("twitter5"); - // tag::create-index-request-aliases - request.alias(new Alias("twitter_alias").filter(QueryBuilders.termQuery("user", "kimchy"))); // <1> - // end::create-index-request-aliases - - // tag::create-index-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::create-index-request-timeout - // tag::create-index-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::create-index-request-masterTimeout - // tag::create-index-request-waitForActiveShards - request.waitForActiveShards(ActiveShardCount.from(2)); // <1> - request.waitForActiveShards(ActiveShardCount.DEFAULT); // <2> - // end::create-index-request-waitForActiveShards - { - CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - request = new CreateIndexRequest("twitter6"); - // tag::create-index-whole-source - request.source(""" - { - "settings" : { - "number_of_shards" : 1, - "number_of_replicas" : 0 - }, - "mappings" : { - "properties" : { - "message" : { "type" : "text" } - } - }, - "aliases" : { - "twitter_alias" : {} - } - }""", XContentType.JSON); // <1> - // end::create-index-whole-source - - // tag::create-index-execute - CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); - // end::create-index-execute - - // tag::create-index-response - boolean acknowledged = createIndexResponse.isAcknowledged(); // <1> - boolean shardsAcknowledged = createIndexResponse.isShardsAcknowledged(); // <2> - // end::create-index-response - assertTrue(acknowledged); - assertTrue(shardsAcknowledged); - } - } - - public void testCreateIndexAsync() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - { - CreateIndexRequest request = new CreateIndexRequest("twitter"); - - // tag::create-index-execute-listener - ActionListener listener = - new ActionListener() { - - @Override - public void onResponse(CreateIndexResponse createIndexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::create-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::create-index-execute-async - client.indices().createAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::create-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPutMapping() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::put-mapping-request - PutMappingRequest request = new PutMappingRequest("twitter"); // <1> - // end::put-mapping-request - - { - // tag::put-mapping-request-source - request.source( - """ - { - "properties": { - "message": { - "type": "text" - } - } - }""", // <1> - XContentType.JSON); - // end::put-mapping-request-source - AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT); - assertTrue(putMappingResponse.isAcknowledged()); - } - - { - //tag::put-mapping-map - Map jsonMap = new HashMap<>(); - Map message = new HashMap<>(); - message.put("type", "text"); - Map properties = new HashMap<>(); - properties.put("message", message); - jsonMap.put("properties", properties); - request.source(jsonMap); // <1> - //end::put-mapping-map - AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT); - assertTrue(putMappingResponse.isAcknowledged()); - } - { - //tag::put-mapping-xcontent - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.startObject("properties"); - { - builder.startObject("message"); - { - builder.field("type", "text"); - } - builder.endObject(); - } - builder.endObject(); - } - builder.endObject(); - request.source(builder); // <1> - //end::put-mapping-xcontent - AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT); - assertTrue(putMappingResponse.isAcknowledged()); - } - - // tag::put-mapping-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::put-mapping-request-timeout - - // tag::put-mapping-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::put-mapping-request-masterTimeout - - // tag::put-mapping-execute - AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT); - // end::put-mapping-execute - - // tag::put-mapping-response - boolean acknowledged = putMappingResponse.isAcknowledged(); // <1> - // end::put-mapping-response - assertTrue(acknowledged); - } - } - - public void testPutMappingAsync() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - PutMappingRequest request = new PutMappingRequest("twitter"); - - // tag::put-mapping-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse putMappingResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-mapping-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-mapping-execute-async - client.indices().putMappingAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-mapping-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetMapping() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - PutMappingRequest request = new PutMappingRequest("twitter"); - request.source("{ \"properties\": { \"message\": { \"type\": \"text\" } } }", XContentType.JSON); - AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT); - assertTrue(putMappingResponse.isAcknowledged()); - } - - { - // tag::get-mappings-request - GetMappingsRequest request = new GetMappingsRequest(); // <1> - request.indices("twitter"); // <2> - // end::get-mappings-request - - // tag::get-mappings-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::get-mappings-request-masterTimeout - - // tag::get-mappings-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::get-mappings-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::get-mappings-execute - GetMappingsResponse getMappingResponse = client.indices().getMapping(request, requestOptions); - // end::get-mappings-execute - - // tag::get-mappings-response - Map allMappings = getMappingResponse.mappings(); // <1> - MappingMetadata indexMapping = allMappings.get("twitter"); // <2> - Map mapping = indexMapping.sourceAsMap(); // <3> - // end::get-mappings-response - - Map type = new HashMap<>(); - type.put("type", "text"); - Map field = new HashMap<>(); - field.put("message", type); - Map expected = new HashMap<>(); - expected.put("properties", field); - assertThat(mapping, equalTo(expected)); - } - } - - public void testGetMappingAsync() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - PutMappingRequest request = new PutMappingRequest("twitter"); - request.source("{ \"properties\": { \"message\": { \"type\": \"text\" } } }", XContentType.JSON); - AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT); - assertTrue(putMappingResponse.isAcknowledged()); - } - - { - GetMappingsRequest request = new GetMappingsRequest(); - request.indices("twitter"); - - // tag::get-mappings-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetMappingsResponse putMappingResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-mappings-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - final ActionListener latchListener = new LatchedActionListener<>(listener, latch); - listener = ActionListener.wrap(r -> { - Map allMappings = r.mappings(); - MappingMetadata indexMapping = allMappings.get("twitter"); - Map mapping = indexMapping.sourceAsMap(); - - Map type = new HashMap<>(); - type.put("type", "text"); - Map field = new HashMap<>(); - field.put("message", type); - Map expected = new HashMap<>(); - expected.put("properties", field); - assertThat(mapping, equalTo(expected)); - latchListener.onResponse(r); - }, e -> { - latchListener.onFailure(e); - fail("should not fail"); - }); - - // tag::get-mappings-execute-async - client.indices().getMappingAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-mappings-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testGetFieldMapping() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - PutMappingRequest request = new PutMappingRequest("twitter"); - request.source( - """ - { - "properties": { - "message": { - "type": "text" - }, - "timestamp": { - "type": "date" - } - } - }""", // <1> - XContentType.JSON - ); - AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT); - assertTrue(putMappingResponse.isAcknowledged()); - } - - // tag::get-field-mappings-request - GetFieldMappingsRequest request = new GetFieldMappingsRequest(); // <1> - request.indices("twitter"); // <2> - request.fields("message", "timestamp"); // <3> - // end::get-field-mappings-request - - // tag::get-field-mappings-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::get-field-mappings-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - { - // tag::get-field-mappings-execute - GetFieldMappingsResponse response = - client.indices().getFieldMapping(request, requestOptions); - // end::get-field-mappings-execute - - // tag::get-field-mappings-response - final Map> mappings = - response.mappings();// <1> - final Map fieldMappings = - mappings.get("twitter"); // <2> - final GetFieldMappingsResponse.FieldMappingMetadata metadata = - fieldMappings.get("message");// <3> - - final String fullName = metadata.fullName();// <4> - final Map source = metadata.sourceAsMap(); // <5> - // end::get-field-mappings-response - } - - { - // tag::get-field-mappings-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetFieldMappingsResponse putMappingResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-field-mappings-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - final ActionListener latchListener = new LatchedActionListener<>(listener, latch); - listener = ActionListener.wrap(r -> { - final Map> mappings = r.mappings(); - final Map fieldMappings = mappings.get("twitter"); - final GetFieldMappingsResponse.FieldMappingMetadata metadata1 = fieldMappings.get("message"); - - final String fullName = metadata1.fullName(); - final Map source = metadata1.sourceAsMap(); - latchListener.onResponse(r); - }, e -> { - latchListener.onFailure(e); - fail("should not fail"); - }); - - // tag::get-field-mappings-execute-async - client.indices().getFieldMappingAsync(request, requestOptions, listener); // <1> - // end::get-field-mappings-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - } - - public void testOpenIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::open-index-request - OpenIndexRequest request = new OpenIndexRequest("index"); // <1> - // end::open-index-request - - // tag::open-index-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::open-index-request-timeout - // tag::open-index-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::open-index-request-masterTimeout - // tag::open-index-request-waitForActiveShards - request.waitForActiveShards(2); // <1> - request.waitForActiveShards(ActiveShardCount.DEFAULT); // <2> - // end::open-index-request-waitForActiveShards - - // tag::open-index-request-indicesOptions - request.indicesOptions(IndicesOptions.strictExpandOpen()); // <1> - // end::open-index-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::open-index-execute - OpenIndexResponse openIndexResponse = client.indices().open(request, requestOptions); - // end::open-index-execute - - // tag::open-index-response - boolean acknowledged = openIndexResponse.isAcknowledged(); // <1> - boolean shardsAcked = openIndexResponse.isShardsAcknowledged(); // <2> - // end::open-index-response - assertTrue(acknowledged); - assertTrue(shardsAcked); - - // tag::open-index-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(OpenIndexResponse openIndexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::open-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::open-index-execute-async - client.indices().openAsync(request, requestOptions, listener); // <1> - // end::open-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::open-index-notfound - try { - OpenIndexRequest request = new OpenIndexRequest("does_not_exist"); - client.indices().open(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.BAD_REQUEST) { - // <1> - } - } - // end::open-index-notfound - } - } - - @SuppressWarnings("unused") - public void testRefreshIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createIndex("index1", Settings.EMPTY); - } - - { - // tag::refresh-request - RefreshRequest request = new RefreshRequest("index1"); // <1> - RefreshRequest requestMultiple = new RefreshRequest("index1", "index2"); // <2> - RefreshRequest requestAll = new RefreshRequest(); // <3> - // end::refresh-request - - // tag::refresh-request-indicesOptions - request.indicesOptions(IndicesOptions.strictExpandOpenAndForbidClosed()); // <1> - // end::refresh-request-indicesOptions - - // tag::refresh-execute - RefreshResponse refreshResponse = client.indices().refresh(request, RequestOptions.DEFAULT); - // end::refresh-execute - - // tag::refresh-response - int totalShards = refreshResponse.getTotalShards(); // <1> - int successfulShards = refreshResponse.getSuccessfulShards(); // <2> - int failedShards = refreshResponse.getFailedShards(); // <3> - DefaultShardOperationFailedException[] failures = refreshResponse.getShardFailures(); // <4> - // end::refresh-response - - // tag::refresh-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(RefreshResponse refreshResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::refresh-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::refresh-execute-async - client.indices().refreshAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::refresh-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::refresh-notfound - try { - RefreshRequest request = new RefreshRequest("does_not_exist"); - client.indices().refresh(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.NOT_FOUND) { - // <1> - } - } - // end::refresh-notfound - } - } - - @SuppressWarnings("unused") - public void testFlushIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createIndex("index1", Settings.EMPTY); - } - - { - // tag::flush-request - FlushRequest request = new FlushRequest("index1"); // <1> - FlushRequest requestMultiple = new FlushRequest("index1", "index2"); // <2> - FlushRequest requestAll = new FlushRequest(); // <3> - // end::flush-request - - // tag::flush-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::flush-request-indicesOptions - - // tag::flush-request-wait - request.waitIfOngoing(true); // <1> - // end::flush-request-wait - - // tag::flush-request-force - request.force(true); // <1> - // end::flush-request-force - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::flush-execute - FlushResponse flushResponse = client.indices().flush(request, requestOptions); - // end::flush-execute - - // tag::flush-response - int totalShards = flushResponse.getTotalShards(); // <1> - int successfulShards = flushResponse.getSuccessfulShards(); // <2> - int failedShards = flushResponse.getFailedShards(); // <3> - DefaultShardOperationFailedException[] failures = flushResponse.getShardFailures(); // <4> - // end::flush-response - - // tag::flush-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(FlushResponse flushResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::flush-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::flush-execute-async - client.indices().flushAsync(request, requestOptions, listener); // <1> - // end::flush-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::flush-notfound - try { - FlushRequest request = new FlushRequest("does_not_exist"); - client.indices().flush(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.NOT_FOUND) { - // <1> - } - } - // end::flush-notfound - } - } - - public void testGetSettings() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - Settings settings = Settings.builder().put("number_of_shards", 3).build(); - CreateIndexResponse createIndexResponse = client.indices() - .create(new CreateIndexRequest("index").settings(settings), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - // tag::get-settings-request - GetSettingsRequest request = new GetSettingsRequest().indices("index"); // <1> - // end::get-settings-request - - // tag::get-settings-request-names - request.names("index.number_of_shards"); // <1> - // end::get-settings-request-names - - // tag::get-settings-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::get-settings-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::get-settings-execute - GetSettingsResponse getSettingsResponse = client.indices().getSettings(request, requestOptions); - // end::get-settings-execute - - // tag::get-settings-response - String numberOfShardsString = getSettingsResponse.getSetting("index", "index.number_of_shards"); // <1> - Settings indexSettings = getSettingsResponse.getIndexToSettings().get("index"); // <2> - Integer numberOfShards = indexSettings.getAsInt("index.number_of_shards", null); // <3> - // end::get-settings-response - - assertEquals("3", numberOfShardsString); - assertEquals(Integer.valueOf(3), numberOfShards); - - assertNull("refresh_interval returned but was never set!", getSettingsResponse.getSetting("index", "index.refresh_interval")); - - // tag::get-settings-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetSettingsResponse GetSettingsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-settings-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-settings-execute-async - client.indices().getSettingsAsync(request, requestOptions, listener); // <1> - // end::get-settings-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetSettingsWithDefaults() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - Settings settings = Settings.builder().put("number_of_shards", 3).build(); - CreateIndexResponse createIndexResponse = client.indices() - .create(new CreateIndexRequest("index").settings(settings), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - GetSettingsRequest request = new GetSettingsRequest().indices("index"); - - // tag::get-settings-request-include-defaults - request.includeDefaults(true); // <1> - // end::get-settings-request-include-defaults - - GetSettingsResponse getSettingsResponse = client.indices().getSettings(request, RequestOptions.DEFAULT); - String numberOfShardsString = getSettingsResponse.getSetting("index", "index.number_of_shards"); - Settings indexSettings = getSettingsResponse.getIndexToSettings().get("index"); - Integer numberOfShards = indexSettings.getAsInt("index.number_of_shards", null); - - // tag::get-settings-defaults-response - String refreshInterval = getSettingsResponse.getSetting("index", "index.refresh_interval"); // <1> - Settings indexDefaultSettings = getSettingsResponse.getIndexToDefaultSettings().get("index"); // <2> - // end::get-settings-defaults-response - - assertEquals("3", numberOfShardsString); - assertEquals(Integer.valueOf(3), numberOfShards); - assertNotNull("with defaults enabled we should get a value for refresh_interval!", refreshInterval); - - assertEquals(refreshInterval, indexDefaultSettings.get("index.refresh_interval")); - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetSettingsResponse GetSettingsResponse) {} - - @Override - public void onFailure(Exception e) {} - }; - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - client.indices().getSettingsAsync(request, RequestOptions.DEFAULT, listener); - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - Settings settings = Settings.builder().put("number_of_shards", 3).build(); - String mappings = """ - {"properties":{"field-1":{"type":"integer"}}}"""; - CreateIndexRequest createIndexRequest = new CreateIndexRequest("index").settings(settings).mapping(mappings, XContentType.JSON); - CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - // tag::get-index-request - GetIndexRequest request = new GetIndexRequest("index"); // <1> - // end::get-index-request - - // tag::get-index-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::get-index-request-indicesOptions - - // tag::get-index-request-includeDefaults - request.includeDefaults(true); // <1> - // end::get-index-request-includeDefaults - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::get-index-execute - GetIndexResponse getIndexResponse = client.indices().get(request, requestOptions); - // end::get-index-execute - - // tag::get-index-response - MappingMetadata indexMappings = getIndexResponse.getMappings().get("index"); // <1> - Map indexTypeMappings = indexMappings.getSourceAsMap(); // <2> - List indexAliases = getIndexResponse.getAliases().get("index"); // <3> - String numberOfShardsString = getIndexResponse.getSetting("index", "index.number_of_shards"); // <4> - Settings indexSettings = getIndexResponse.getSettings().get("index"); // <5> - Integer numberOfShards = indexSettings.getAsInt("index.number_of_shards", null); // <6> - TimeValue time = getIndexResponse.getDefaultSettings().get("index") - .getAsTime("index.refresh_interval", null); // <7> - // end::get-index-response - - assertEquals( - Collections.singletonMap("properties", Collections.singletonMap("field-1", Collections.singletonMap("type", "integer"))), - indexTypeMappings - ); - assertTrue(indexAliases.isEmpty()); - assertEquals(IndexSettings.DEFAULT_REFRESH_INTERVAL, time); - assertEquals("3", numberOfShardsString); - assertEquals(Integer.valueOf(3), numberOfShards); - - // tag::get-index-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetIndexResponse getIndexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-index-execute-async - client.indices().getAsync(request, requestOptions, listener); // <1> - // end::get-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testForceMergeIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createIndex("index", Settings.EMPTY); - } - - { - // tag::force-merge-request - ForceMergeRequest request = new ForceMergeRequest("index1"); // <1> - ForceMergeRequest requestMultiple = new ForceMergeRequest("index1", "index2"); // <2> - ForceMergeRequest requestAll = new ForceMergeRequest(); // <3> - // end::force-merge-request - - // tag::force-merge-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::force-merge-request-indicesOptions - - // tag::force-merge-request-segments-num - request.maxNumSegments(1); // <1> - // end::force-merge-request-segments-num - - // tag::force-merge-request-only-expunge-deletes - request.onlyExpungeDeletes(true); // <1> - // end::force-merge-request-only-expunge-deletes - - // set only expunge deletes back to its default value - // as it is mutually exclusive with max. num. segments - request.onlyExpungeDeletes(ForceMergeRequest.Defaults.ONLY_EXPUNGE_DELETES); - - // tag::force-merge-request-flush - request.flush(true); // <1> - // end::force-merge-request-flush - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::force-merge-execute - ForceMergeResponse forceMergeResponse = client.indices().forcemerge(request, requestOptions); - // end::force-merge-execute - - // tag::force-merge-response - int totalShards = forceMergeResponse.getTotalShards(); // <1> - int successfulShards = forceMergeResponse.getSuccessfulShards(); // <2> - int failedShards = forceMergeResponse.getFailedShards(); // <3> - DefaultShardOperationFailedException[] failures = forceMergeResponse.getShardFailures(); // <4> - // end::force-merge-response - - // tag::force-merge-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ForceMergeResponse forceMergeResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::force-merge-execute-listener - - // tag::force-merge-execute-async - client.indices().forcemergeAsync(request, requestOptions, listener); // <1> - // end::force-merge-execute-async - } - { - // tag::force-merge-notfound - try { - ForceMergeRequest request = new ForceMergeRequest("does_not_exist"); - client.indices().forcemerge(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.NOT_FOUND) { - // <1> - } - } - // end::force-merge-notfound - } - } - - @SuppressWarnings("unused") - public void testClearCache() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createIndex("index1", Settings.EMPTY); - } - - { - // tag::clear-cache-request - ClearIndicesCacheRequest request = new ClearIndicesCacheRequest("index1"); // <1> - ClearIndicesCacheRequest requestMultiple = new ClearIndicesCacheRequest("index1", "index2"); // <2> - ClearIndicesCacheRequest requestAll = new ClearIndicesCacheRequest(); // <3> - // end::clear-cache-request - - // tag::clear-cache-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::clear-cache-request-indicesOptions - - // tag::clear-cache-request-query - request.queryCache(true); // <1> - // end::clear-cache-request-query - - // tag::clear-cache-request-request - request.requestCache(true); // <1> - // end::clear-cache-request-request - - // tag::clear-cache-request-fielddata - request.fieldDataCache(true); // <1> - // end::clear-cache-request-fielddata - - // tag::clear-cache-request-fields - request.fields("field1", "field2", "field3"); // <1> - // end::clear-cache-request-fields - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::clear-cache-execute - ClearIndicesCacheResponse clearCacheResponse = client.indices().clearCache(request, requestOptions); - // end::clear-cache-execute - - // tag::clear-cache-response - int totalShards = clearCacheResponse.getTotalShards(); // <1> - int successfulShards = clearCacheResponse.getSuccessfulShards(); // <2> - int failedShards = clearCacheResponse.getFailedShards(); // <3> - DefaultShardOperationFailedException[] failures = clearCacheResponse.getShardFailures(); // <4> - // end::clear-cache-response - - // tag::clear-cache-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ClearIndicesCacheResponse clearCacheResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::clear-cache-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clear-cache-execute-async - client.indices().clearCacheAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clear-cache-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::clear-cache-notfound - try { - ClearIndicesCacheRequest request = new ClearIndicesCacheRequest("does_not_exist"); - client.indices().clearCache(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.NOT_FOUND) { - // <1> - } - } - // end::clear-cache-notfound - } - } - - public void testCloseIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::close-index-request - CloseIndexRequest request = new CloseIndexRequest("index"); // <1> - // end::close-index-request - - // tag::close-index-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::close-index-request-timeout - // tag::close-index-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::close-index-request-masterTimeout - - // tag::close-index-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::close-index-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::close-index-execute - AcknowledgedResponse closeIndexResponse = client.indices().close(request, requestOptions); - // end::close-index-execute - - // tag::close-index-response - boolean acknowledged = closeIndexResponse.isAcknowledged(); // <1> - // end::close-index-response - assertTrue(acknowledged); - - // tag::close-index-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(CloseIndexResponse closeIndexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::close-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::close-index-execute-async - client.indices().closeAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::close-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testExistsAlias() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices() - .create(new CreateIndexRequest("index").alias(new Alias("alias")), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::exists-alias-request - GetAliasesRequest request = new GetAliasesRequest(); - GetAliasesRequest requestWithAlias = new GetAliasesRequest("alias1"); - GetAliasesRequest requestWithAliases = - new GetAliasesRequest(new String[]{"alias1", "alias2"}); - // end::exists-alias-request - - // tag::exists-alias-request-alias - request.aliases("alias"); // <1> - // end::exists-alias-request-alias - // tag::exists-alias-request-indices - request.indices("index"); // <1> - // end::exists-alias-request-indices - - // tag::exists-alias-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::exists-alias-request-indicesOptions - - // tag::exists-alias-request-local - request.local(true); // <1> - // end::exists-alias-request-local - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::exists-alias-execute - boolean exists = client.indices().existsAlias(request, requestOptions); - // end::exists-alias-execute - assertTrue(exists); - - // tag::exists-alias-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(Boolean exists) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::exists-alias-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-alias-execute-async - client.indices().existsAliasAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::exists-alias-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testUpdateAliases() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index1"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - createIndexResponse = client.indices().create(new CreateIndexRequest("index2"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - createIndexResponse = client.indices().create(new CreateIndexRequest("index3"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - createIndexResponse = client.indices().create(new CreateIndexRequest("index4"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::update-aliases-request - IndicesAliasesRequest request = new IndicesAliasesRequest(); // <1> - AliasActions aliasAction = - new AliasActions(AliasActions.Type.ADD) - .index("index1") - .alias("alias1"); // <2> - request.addAliasAction(aliasAction); // <3> - // end::update-aliases-request - - // tag::update-aliases-request2 - AliasActions addIndexAction = - new AliasActions(AliasActions.Type.ADD) - .index("index1") - .alias("alias1") - .filter("{\"term\":{\"year\":2016}}"); // <1> - AliasActions addIndicesAction = - new AliasActions(AliasActions.Type.ADD) - .indices("index1", "index2") - .alias("alias2") - .routing("1"); // <2> - AliasActions removeAction = - new AliasActions(AliasActions.Type.REMOVE) - .index("index3") - .alias("alias3"); // <3> - AliasActions removeIndexAction = - new AliasActions(AliasActions.Type.REMOVE_INDEX) - .index("index4"); // <4> - // end::update-aliases-request2 - - // tag::update-aliases-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::update-aliases-request-timeout - // tag::update-aliases-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::update-aliases-request-masterTimeout - - // tag::update-aliases-execute - AcknowledgedResponse indicesAliasesResponse = - client.indices().updateAliases(request, RequestOptions.DEFAULT); - // end::update-aliases-execute - - // tag::update-aliases-response - boolean acknowledged = indicesAliasesResponse.isAcknowledged(); // <1> - // end::update-aliases-response - assertTrue(acknowledged); - } - - { - IndicesAliasesRequest request = new IndicesAliasesRequest(); - AliasActions aliasAction = new AliasActions(AliasActions.Type.ADD).index("index1").alias("async"); - request.addAliasAction(aliasAction); - - // tag::update-aliases-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse indicesAliasesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-aliases-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-aliases-execute-async - client.indices().updateAliasesAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::update-aliases-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testShrinkIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - Map nodes = getAsMap("_nodes"); - @SuppressWarnings("unchecked") - String firstNode = ((Map) nodes.get("nodes")).keySet().iterator().next(); - createIndex("source_index", Settings.builder().put("index.number_of_shards", 4).put("index.number_of_replicas", 0).build()); - updateIndexSettings( - "source_index", - Settings.builder().put("index.routing.allocation.require._name", firstNode).put("index.blocks.write", true) - ); - } - - // tag::shrink-index-request - ResizeRequest request = new ResizeRequest("target_index","source_index"); // <1> - // end::shrink-index-request - - // tag::shrink-index-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::shrink-index-request-timeout - // tag::shrink-index-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::shrink-index-request-masterTimeout - // tag::shrink-index-request-waitForActiveShards - request.setWaitForActiveShards(2); // <1> - request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <2> - // end::shrink-index-request-waitForActiveShards - if (randomBoolean()) { - // tag::shrink-index-request-settings - request.getTargetIndexRequest().settings(Settings.builder() - .put("index.number_of_shards", 2) // <1> - .putNull("index.routing.allocation.require._name")); // <2> - // end::shrink-index-request-settings - } else { - request.getTargetIndexRequest().settings(Settings.builder().putNull("index.routing.allocation.require._name")); - // tag::shrink-index-request-maxPrimaryShardSize - request.setMaxPrimaryShardSize(new ByteSizeValue(50, ByteSizeUnit.GB)); // <1> - // end::shrink-index-request-maxPrimaryShardSize - } - // tag::shrink-index-request-aliases - request.getTargetIndexRequest().alias(new Alias("target_alias")); // <1> - // end::shrink-index-request-aliases - - // tag::shrink-index-execute - ResizeResponse resizeResponse = client.indices().shrink(request, RequestOptions.DEFAULT); - // end::shrink-index-execute - - // tag::shrink-index-response - boolean acknowledged = resizeResponse.isAcknowledged(); // <1> - boolean shardsAcked = resizeResponse.isShardsAcknowledged(); // <2> - // end::shrink-index-response - assertTrue(acknowledged); - assertTrue(shardsAcked); - - // tag::shrink-index-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ResizeResponse resizeResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::shrink-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::shrink-index-execute-async - client.indices().shrinkAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::shrink-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testSplitIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createIndex( - "source_index", - Settings.builder() - .put("index.number_of_shards", 2) - .put("index.number_of_replicas", 0) - .put("index.number_of_routing_shards", 4) - .build() - ); - updateIndexSettings("source_index", Settings.builder().put("index.blocks.write", true)); - } - - // tag::split-index-request - ResizeRequest request = new ResizeRequest("target_index","source_index"); // <1> - request.setResizeType(ResizeType.SPLIT); // <2> - // end::split-index-request - - // tag::split-index-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::split-index-request-timeout - // tag::split-index-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::split-index-request-masterTimeout - // tag::split-index-request-waitForActiveShards - request.setWaitForActiveShards(2); // <1> - request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <2> - // end::split-index-request-waitForActiveShards - // tag::split-index-request-settings - request.getTargetIndexRequest().settings(Settings.builder() - .put("index.number_of_shards", 4)); // <1> - // end::split-index-request-settings - // tag::split-index-request-aliases - request.getTargetIndexRequest().alias(new Alias("target_alias")); // <1> - // end::split-index-request-aliases - - // tag::split-index-execute - ResizeResponse resizeResponse = client.indices().split(request, RequestOptions.DEFAULT); - // end::split-index-execute - - // tag::split-index-response - boolean acknowledged = resizeResponse.isAcknowledged(); // <1> - boolean shardsAcked = resizeResponse.isShardsAcknowledged(); // <2> - // end::split-index-response - assertTrue(acknowledged); - assertTrue(shardsAcked); - - // tag::split-index-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ResizeResponse resizeResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::split-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::split-index-execute-async - client.indices().splitAsync(request, RequestOptions.DEFAULT,listener); // <1> - // end::split-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testCloneIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createIndex("source_index", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build()); - updateIndexSettings("source_index", Settings.builder().put("index.blocks.write", true)); - } - - // tag::clone-index-request - ResizeRequest request = new ResizeRequest("target_index","source_index"); // <1> - request.setResizeType(ResizeType.CLONE); // <2> - // end::clone-index-request - - // tag::clone-index-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::clone-index-request-timeout - // tag::clone-index-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::clone-index-request-masterTimeout - // tag::clone-index-request-waitForActiveShards - request.setWaitForActiveShards(2); // <1> - request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <2> - // end::clone-index-request-waitForActiveShards - // tag::clone-index-request-settings - request.getTargetIndexRequest().settings(Settings.builder() - .put("index.number_of_shards", 2)); // <1> - // end::clone-index-request-settings - // tag::clone-index-request-aliases - request.getTargetIndexRequest().alias(new Alias("target_alias")); // <1> - // end::clone-index-request-aliases - - // tag::clone-index-execute - ResizeResponse resizeResponse = client.indices().clone(request, RequestOptions.DEFAULT); - // end::clone-index-execute - - // tag::clone-index-response - boolean acknowledged = resizeResponse.isAcknowledged(); // <1> - boolean shardsAcked = resizeResponse.isShardsAcknowledged(); // <2> - // end::clone-index-response - assertTrue(acknowledged); - assertTrue(shardsAcked); - - // tag::clone-index-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ResizeResponse resizeResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::clone-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clone-index-execute-async - client.indices().cloneAsync(request, RequestOptions.DEFAULT,listener); // <1> - // end::clone-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testRolloverIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - client.indices().create(new CreateIndexRequest("index-1").alias(new Alias("alias")), RequestOptions.DEFAULT); - } - - // tag::rollover-index-request - RolloverRequest request = new RolloverRequest("alias", "index-2"); // <1> - request.addMaxIndexAgeCondition(new TimeValue(7, TimeUnit.DAYS)); // <2> - request.addMaxIndexDocsCondition(1000); // <3> - request.addMaxIndexSizeCondition(new ByteSizeValue(5, ByteSizeUnit.GB)); // <4> - request.addMaxPrimaryShardSizeCondition(new ByteSizeValue(2, ByteSizeUnit.GB)); // <5> - // end::rollover-index-request - - // tag::rollover-index-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::rollover-index-request-timeout - // tag::rollover-index-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::rollover-index-request-masterTimeout - // tag::rollover-index-request-dryRun - request.dryRun(true); // <1> - // end::rollover-index-request-dryRun - // tag::rollover-index-request-waitForActiveShards - request.getCreateIndexRequest().waitForActiveShards(ActiveShardCount.from(2)); // <1> - request.getCreateIndexRequest().waitForActiveShards(ActiveShardCount.DEFAULT); // <2> - // end::rollover-index-request-waitForActiveShards - // tag::rollover-index-request-settings - request.getCreateIndexRequest().settings(Settings.builder() - .put("index.number_of_shards", 4)); // <1> - // end::rollover-index-request-settings - // tag::rollover-index-request-mapping - String mappings = """ - {"properties":{"field-1":{"type":"keyword"}}} - """; - request.getCreateIndexRequest().mapping(mappings, XContentType.JSON); // <1> - // end::rollover-index-request-mapping - // tag::rollover-index-request-alias - request.getCreateIndexRequest().alias(new Alias("another_alias")); // <1> - // end::rollover-index-request-alias - - // tag::rollover-index-execute - RolloverResponse rolloverResponse = client.indices().rollover(request, RequestOptions.DEFAULT); - // end::rollover-index-execute - - // tag::rollover-index-response - boolean acknowledged = rolloverResponse.isAcknowledged(); // <1> - boolean shardsAcked = rolloverResponse.isShardsAcknowledged(); // <2> - String oldIndex = rolloverResponse.getOldIndex(); // <3> - String newIndex = rolloverResponse.getNewIndex(); // <4> - boolean isRolledOver = rolloverResponse.isRolledOver(); // <5> - boolean isDryRun = rolloverResponse.isDryRun(); // <6> - Map conditionStatus = rolloverResponse.getConditionStatus();// <7> - // end::rollover-index-response - assertFalse(acknowledged); - assertFalse(shardsAcked); - assertEquals("index-1", oldIndex); - assertEquals("index-2", newIndex); - assertFalse(isRolledOver); - assertTrue(isDryRun); - assertEquals(4, conditionStatus.size()); - - // tag::rollover-index-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(RolloverResponse rolloverResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::rollover-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::rollover-index-execute-async - client.indices().rolloverAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::rollover-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testGetAlias() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices() - .create(new CreateIndexRequest("index").alias(new Alias("alias")), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::get-alias-request - GetAliasesRequest request = new GetAliasesRequest(); - GetAliasesRequest requestWithAlias = new GetAliasesRequest("alias1"); - GetAliasesRequest requestWithAliases = - new GetAliasesRequest(new String[]{"alias1", "alias2"}); - // end::get-alias-request - - // tag::get-alias-request-alias - request.aliases("alias"); // <1> - // end::get-alias-request-alias - // tag::get-alias-request-indices - request.indices("index"); // <1> - // end::get-alias-request-indices - - // tag::get-alias-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::get-alias-request-indicesOptions - - // tag::get-alias-request-local - request.local(true); // <1> - // end::get-alias-request-local - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::get-alias-execute - GetAliasesResponse response = client.indices().getAlias(request, requestOptions); - // end::get-alias-execute - - // tag::get-alias-response - Map> aliases = response.getAliases(); // <1> - // end::get-alias-response - - // tag::get-alias-response-error - RestStatus status = response.status(); // <1> - ElasticsearchException exception = response.getException(); // <2> - String error = response.getError(); // <3> - // end::get-alias-response-error - - assertThat(response.getAliases().get("index").size(), equalTo(1)); - assertThat(response.getAliases().get("index").iterator().next().alias(), equalTo("alias")); - assertThat(status, equalTo(RestStatus.OK)); - assertThat(error, nullValue()); - assertThat(exception, nullValue()); - - // tag::get-alias-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetAliasesResponse getAliasesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-alias-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-alias-execute-async - client.indices().getAliasAsync(request, requestOptions, listener); // <1> - // end::get-alias-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testIndexPutSettings() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - // tag::indices-put-settings-request - UpdateSettingsRequest request = new UpdateSettingsRequest("index1"); // <1> - UpdateSettingsRequest requestMultiple = - new UpdateSettingsRequest("index1", "index2"); // <2> - UpdateSettingsRequest requestAll = new UpdateSettingsRequest(); // <3> - // end::indices-put-settings-request - - // tag::indices-put-settings-create-settings - String settingKey = "index.number_of_replicas"; - int settingValue = 0; - Settings settings = - Settings.builder() - .put(settingKey, settingValue) - .build(); // <1> - // end::indices-put-settings-create-settings - // tag::indices-put-settings-request-index-settings - request.settings(settings); - // end::indices-put-settings-request-index-settings - - { - // tag::indices-put-settings-settings-builder - Settings.Builder settingsBuilder = - Settings.builder() - .put(settingKey, settingValue); - request.settings(settingsBuilder); // <1> - // end::indices-put-settings-settings-builder - } - { - // tag::indices-put-settings-settings-map - Map map = new HashMap<>(); - map.put(settingKey, settingValue); - request.settings(map); // <1> - // end::indices-put-settings-settings-map - } - { - // tag::indices-put-settings-settings-source - request.settings(""" - {"index.number_of_replicas": "2"} - """, XContentType.JSON); // <1> - // end::indices-put-settings-settings-source - } - - // tag::indices-put-settings-request-preserveExisting - request.setPreserveExisting(false); // <1> - // end::indices-put-settings-request-preserveExisting - // tag::indices-put-settings-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::indices-put-settings-request-timeout - // tag::indices-put-settings-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::indices-put-settings-request-masterTimeout - // tag::indices-put-settings-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::indices-put-settings-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::indices-put-settings-execute - AcknowledgedResponse updateSettingsResponse = - client.indices().putSettings(request, requestOptions); - // end::indices-put-settings-execute - - // tag::indices-put-settings-response - boolean acknowledged = updateSettingsResponse.isAcknowledged(); // <1> - // end::indices-put-settings-response - assertTrue(acknowledged); - - // tag::indices-put-settings-execute-listener - ActionListener listener = - new ActionListener() { - - @Override - public void onResponse(AcknowledgedResponse updateSettingsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::indices-put-settings-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::indices-put-settings-execute-async - client.indices().putSettingsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::indices-put-settings-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testPutTemplate() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::put-template-request - PutIndexTemplateRequest request = new PutIndexTemplateRequest( - "my-template", // <1> - List.of("pattern-1", "log-*") // <2> - ); - // end::put-template-request - - // tag::put-template-request-settings - request.settings(Settings.builder() // <1> - .put("index.number_of_shards", 3) - .put("index.number_of_replicas", 1) - ); - // end::put-template-request-settings - - { - // tag::put-template-request-mappings-json - request.mapping(// <1> - """ - { - "properties": { - "message": { - "type": "text" - } - } - }""", - XContentType.JSON); - // end::put-template-request-mappings-json - assertTrue(client.indices().putTemplate(request, LEGACY_TEMPLATE_OPTIONS).isAcknowledged()); - } - { - //tag::put-template-request-mappings-map - Map jsonMap = new HashMap<>(); - { - Map properties = new HashMap<>(); - { - Map message = new HashMap<>(); - message.put("type", "text"); - properties.put("message", message); - } - jsonMap.put("properties", properties); - } - request.mapping(jsonMap); // <1> - //end::put-template-request-mappings-map - assertTrue(client.indices().putTemplate(request, LEGACY_TEMPLATE_OPTIONS).isAcknowledged()); - } - { - //tag::put-template-request-mappings-xcontent - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.startObject("properties"); - { - builder.startObject("message"); - { - builder.field("type", "text"); - } - builder.endObject(); - } - builder.endObject(); - } - builder.endObject(); - request.mapping(builder); // <1> - //end::put-template-request-mappings-xcontent - assertTrue(client.indices().putTemplate(request, LEGACY_TEMPLATE_OPTIONS).isAcknowledged()); - } - - // tag::put-template-request-aliases - request.alias(new Alias("twitter_alias").filter(QueryBuilders.termQuery("user", "kimchy"))); // <1> - request.alias(new Alias("{index}_alias").searchRouting("xyz")); // <2> - // end::put-template-request-aliases - - // tag::put-template-request-order - request.order(20); // <1> - // end::put-template-request-order - - // tag::put-template-request-version - request.version(4); // <1> - // end::put-template-request-version - - // tag::put-template-whole-source - request.source(""" - { - "index_patterns": [ - "log-*", - "pattern-1" - ], - "order": 1, - "settings": { - "number_of_shards": 1 - }, - "mappings": { - "properties": { - "message": { - "type": "text" - } - } - }, - "aliases": { - "alias-1": {}, - "{index}-alias": {} - } - }""", XContentType.JSON); // <1> - // end::put-template-whole-source - - // tag::put-template-request-create - request.create(true); // <1> - // end::put-template-request-create - - // tag::put-template-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::put-template-request-masterTimeout - - request.create(false); // make test happy - - // tag::put-template-execute - AcknowledgedResponse putTemplateResponse = client.indices().putTemplate(request, LEGACY_TEMPLATE_OPTIONS); - // end::put-template-execute - - // tag::put-template-response - boolean acknowledged = putTemplateResponse.isAcknowledged(); // <1> - // end::put-template-response - assertTrue(acknowledged); - - // tag::put-template-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse putTemplateResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-template-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-template-execute-async - client.indices().putTemplateAsync(request, LEGACY_TEMPLATE_OPTIONS, listener); // <1> - // end::put-template-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetTemplates() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest("my-template", List.of("pattern-1", "log-*")); - putRequest.settings(Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 1)); - putRequest.mapping("{ \"properties\": { \"message\": { \"type\": \"text\" } } }", XContentType.JSON); - assertTrue(client.indices().putTemplate(putRequest, LEGACY_TEMPLATE_OPTIONS).isAcknowledged()); - } - - // tag::get-templates-request - GetIndexTemplatesRequest request = new GetIndexTemplatesRequest("my-template"); // <1> - request = new GetIndexTemplatesRequest("template-1", "template-2"); // <2> - request = new GetIndexTemplatesRequest("my-*"); // <3> - // end::get-templates-request - - // tag::get-templates-request-masterTimeout - request.setMasterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.setMasterNodeTimeout("1m"); // <2> - // end::get-templates-request-masterTimeout - - // tag::get-templates-execute - GetIndexTemplatesResponse getTemplatesResponse = client.indices().getIndexTemplate(request, RequestOptions.DEFAULT); - // end::get-templates-execute - - // tag::get-templates-response - List templates = getTemplatesResponse.getIndexTemplates(); // <1> - // end::get-templates-response - - assertThat(templates, hasSize(1)); - assertThat(templates.get(0).name(), equalTo("my-template")); - - // tag::get-templates-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetIndexTemplatesResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-templates-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-templates-execute-async - client.indices().getIndexTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-templates-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetIndexTemplatesV2() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - Template template = new Template( - Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 1).build(), - new CompressedXContent("{ \"properties\": { \"message\": { \"type\": \"text\" } } }"), - null - ); - PutComposableIndexTemplateRequest putRequest = new PutComposableIndexTemplateRequest().name("my-template") - .indexTemplate(new ComposableIndexTemplate(List.of("pattern-1", "log-*"), template, null, null, null, null)); - assertTrue(client.indices().putIndexTemplate(putRequest, RequestOptions.DEFAULT).isAcknowledged()); - } - - // tag::get-index-templates-v2-request - GetComposableIndexTemplateRequest request = new GetComposableIndexTemplateRequest("my-template"); // <1> - request = new GetComposableIndexTemplateRequest("my-*"); // <2> - // end::get-index-templates-v2-request - - // tag::get-index-templates-v2-request-masterTimeout - request.setMasterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.setMasterNodeTimeout("1m"); // <2> - // end::get-index-templates-v2-request-masterTimeout - - // tag::get-index-templates-v2-execute - GetComposableIndexTemplatesResponse getTemplatesResponse = client.indices().getIndexTemplate(request, RequestOptions.DEFAULT); - // end::get-index-templates-v2-execute - - // tag::get-index-templates-v2-response - Map templates = getTemplatesResponse.getIndexTemplates(); // <1> - // end::get-index-templates-v2-response - - assertThat(templates.size(), is(1)); - assertThat(templates.get("my-template"), is(notNullValue())); - - // tag::get-index-templates-v2-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetComposableIndexTemplatesResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-index-templates-v2-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-index-templates-v2-execute-async - client.indices().getIndexTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-index-templates-v2-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testPutIndexTemplateV2() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::put-index-template-v2-request - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest() - .name("my-template"); // <1> - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(List.of("pattern-1", "log-*"), - null, null, null, null, null); // <2> - request.indexTemplate(composableIndexTemplate); - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-index-template-v2-request - } - - { - // tag::put-index-template-v2-request-settings - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest() - .name("my-template"); - Settings settings = Settings.builder() // <1> - .put("index.number_of_shards", 3) - .put("index.number_of_replicas", 1) - .build(); - Template template = new Template(settings, null, null); // <2> - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(List.of("pattern-1", "log-*"), - template, null, null, null, null); // <3> - request.indexTemplate(composableIndexTemplate); - - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-index-template-v2-request-settings - } - - { - // tag::put-index-template-v2-request-mappings-json - String mappingJson = """ - { - "properties": { - "message": { - "type": "text" - } - } - }"""; // <1> - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest() - .name("my-template"); - Template template = new Template(null, new CompressedXContent(mappingJson), null); // <2> - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(List.of("pattern-1", "log-*"), - template, null, null, null, null); // <3> - request.indexTemplate(composableIndexTemplate); - - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-index-template-v2-request-mappings-json - } - - { - // tag::put-index-template-v2-request-aliases - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest() - .name("my-template"); - AliasMetadata twitterAlias = AliasMetadata.builder("twitter_alias").build(); // <1> - AliasMetadata placeholderAlias = AliasMetadata.builder("{index}_alias").searchRouting("xyz").build(); // <2> - Template template = new Template(null, null, Map.of("twitter_alias", twitterAlias, "{index}_alias", placeholderAlias)); // <3> - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(List.of("pattern-1", "log-*"), - template, null, null, null, null); // <3> - request.indexTemplate(composableIndexTemplate); - - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-index-template-v2-request-aliases - } - - { - Template template = new Template(Settings.builder().put("index.number_of_replicas", 3).build(), null, null); - ComponentTemplate componentTemplate = new ComponentTemplate(template, null, null); - client.cluster() - .putComponentTemplate( - new PutComponentTemplateRequest().name("ct1").componentTemplate(componentTemplate), - RequestOptions.DEFAULT - ); - - // tag::put-index-template-v2-request-component-template - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest() - .name("my-template"); - ComposableIndexTemplate composableIndexTemplate = - new ComposableIndexTemplate(List.of("pattern-1", "log-*"), null, List.of("ct1"), null, null, null); // <1> - request.indexTemplate(composableIndexTemplate); - - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-index-template-v2-request-component-template - } - - { - // tag::put-index-template-v2-request-priority - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest() - .name("my-template"); - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(List.of("pattern-1", "log-*"), - null, null, 20L, null, null); // <1> - request.indexTemplate(composableIndexTemplate); - - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-index-template-v2-request-priority - } - - { - // tag::put-index-template-v2-request-version - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest() - .name("my-template"); - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(List.of("pattern-1", "log-*"), - null, null, null, 3L, null); // <1> - request.indexTemplate(composableIndexTemplate); - - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - // end::put-index-template-v2-request-version - - // tag::put-index-template-v2-request-create - request.create(true); // <1> - // end::put-index-template-v2-request-create - - // tag::put-index-template-v2-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::put-index-template-v2-request-masterTimeout - - request.create(false); // make test happy - - // tag::put-index-template-v2-execute - AcknowledgedResponse putTemplateResponse = client.indices().putIndexTemplate(request, RequestOptions.DEFAULT); - // end::put-index-template-v2-execute - - // tag::put-index-template-v2-response - boolean acknowledged = putTemplateResponse.isAcknowledged(); // <1> - // end::put-index-template-v2-response - assertTrue(acknowledged); - - // tag::put-index-template-v2-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse putIndexTemplateResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-index-template-v2-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-index-template-v2-execute-async - client.indices().putIndexTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-index-template-v2-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteIndexTemplateV2() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest().name("my-template"); - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate( - List.of("pattern-1", "log-*"), - null, - null, - null, - null, - null - ); // <2> - request.indexTemplate(composableIndexTemplate); - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - } - - // tag::delete-index-template-v2-request - DeleteComposableIndexTemplateRequest deleteRequest = new DeleteComposableIndexTemplateRequest("my-template"); // <1> - // end::delete-index-template-v2-request - - // tag::delete-index-template-v2-request-masterTimeout - deleteRequest.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::delete-index-template-v2-request-masterTimeout - - // tag::delete-index-template-v2-execute - AcknowledgedResponse deleteTemplateAcknowledge = client.indices().deleteIndexTemplate(deleteRequest, RequestOptions.DEFAULT); - // end::delete-index-template-v2-execute - - // tag::delete-index-template-v2-response - boolean acknowledged = deleteTemplateAcknowledge.isAcknowledged(); // <1> - // end::delete-index-template-v2-response - assertThat(acknowledged, equalTo(true)); - - { - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest().name("my-template"); - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate( - List.of("pattern-1", "log-*"), - null, - null, - null, - null, - null - ); // <2> - request.indexTemplate(composableIndexTemplate); - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - } - - // tag::delete-index-template-v2-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-index-template-v2-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-index-template-v2-execute-async - client.indices().deleteIndexTemplateAsync(deleteRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-index-template-v2-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testSimulateIndexTemplate() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest().name("my-template"); // <1> - Template template = new Template(Settings.builder().put("index.number_of_replicas", 3).build(), null, null); - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate( - List.of("pattern-1", "log-*"), - template, - null, - null, - null, - null - ); - request.indexTemplate(composableIndexTemplate); - assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged()); - } - - // tag::simulate-index-template-request - SimulateIndexTemplateRequest simulateRequest = new SimulateIndexTemplateRequest("log-000001"); // <1> - PutComposableIndexTemplateRequest newIndexTemplateRequest = new PutComposableIndexTemplateRequest() - .name("used-for-simulation"); - Settings settings = Settings.builder().put("index.number_of_shards", 6).build(); - Template template = new Template(settings, null, null); // <2> - ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(List.of("log-*"), - template, null, 90L, null, null); - newIndexTemplateRequest.indexTemplate(composableIndexTemplate); - - simulateRequest.indexTemplateV2Request(newIndexTemplateRequest); // <2> - // end::simulate-index-template-request - - // tag::simulate-index-template-response - SimulateIndexTemplateResponse simulateIndexTemplateResponse = client.indices().simulateIndexTemplate(simulateRequest, - RequestOptions.DEFAULT); - assertThat(simulateIndexTemplateResponse.resolvedTemplate().settings().get("index.number_of_shards"), is("6")); // <1> - assertThat(simulateIndexTemplateResponse.overlappingTemplates().get("my-template"), - containsInAnyOrder("pattern-1", "log-*")); // <2> - // end::simulate-index-template-response - - // tag::simulate-index-template-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(SimulateIndexTemplateResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::simulate-index-template-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::simulate-index-template-execute-async - client.indices().simulateIndexTemplateAsync(simulateRequest, RequestOptions.DEFAULT, listener); // <1> - // end::simulate-index-template-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testTemplatesExist() throws Exception { - final RestHighLevelClient client = highLevelClient(); - { - final PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest("my-template", List.of("foo")); - assertTrue(client.indices().putTemplate(putRequest, LEGACY_TEMPLATE_OPTIONS).isAcknowledged()); - } - - { - // tag::templates-exist-request - IndexTemplatesExistRequest request; - request = new IndexTemplatesExistRequest("my-template"); // <1> - request = new IndexTemplatesExistRequest("template-1", "template-2"); // <2> - request = new IndexTemplatesExistRequest("my-*"); // <3> - // end::templates-exist-request - - // tag::templates-exist-request-optionals - request.setLocal(true); // <1> - request.setMasterNodeTimeout(TimeValue.timeValueMinutes(1)); // <2> - request.setMasterNodeTimeout("1m"); // <3> - // end::templates-exist-request-optionals - - // tag::templates-exist-execute - boolean exists = client.indices().existsTemplate(request, RequestOptions.DEFAULT); - // end::templates-exist-execute - assertTrue(exists); - - // tag::templates-exist-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(Boolean aBoolean) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::templates-exist-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::templates-exist-execute-async - client.indices().existsTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::templates-exist-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - } - - @SuppressWarnings("unused") - public void testValidateQuery() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String index = "some_index"; - createIndex(index, Settings.EMPTY); - - // tag::indices-validate-query-request - ValidateQueryRequest request = new ValidateQueryRequest(index); // <1> - // end::indices-validate-query-request - - // tag::indices-validate-query-request-query - QueryBuilder builder = QueryBuilders - .boolQuery() // <1> - .must(QueryBuilders.queryStringQuery("*:*")) - .filter(QueryBuilders.termQuery("user", "kimchy")); - request.query(builder); // <2> - // end::indices-validate-query-request-query - - // tag::indices-validate-query-request-explain - request.explain(true); // <1> - // end::indices-validate-query-request-explain - - // tag::indices-validate-query-request-allShards - request.allShards(true); // <1> - // end::indices-validate-query-request-allShards - - // tag::indices-validate-query-request-rewrite - request.rewrite(true); // <1> - // end::indices-validate-query-request-rewrite - - // tag::indices-validate-query-execute - ValidateQueryResponse response = client.indices().validateQuery(request, RequestOptions.DEFAULT); // <1> - // end::indices-validate-query-execute - - // tag::indices-validate-query-response - boolean isValid = response.isValid(); // <1> - int totalShards = response.getTotalShards(); // <2> - int successfulShards = response.getSuccessfulShards(); // <3> - int failedShards = response.getFailedShards(); // <4> - if (failedShards > 0) { - for(DefaultShardOperationFailedException failure: response.getShardFailures()) { // <5> - String failedIndex = failure.index(); // <6> - int shardId = failure.shardId(); // <7> - String reason = failure.reason(); // <8> - } - } - for(QueryExplanation explanation: response.getQueryExplanation()) { // <9> - String explanationIndex = explanation.getIndex(); // <10> - int shardId = explanation.getShard(); // <11> - String explanationString = explanation.getExplanation(); // <12> - } - // end::indices-validate-query-response - - // tag::indices-validate-query-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ValidateQueryResponse validateQueryResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::indices-validate-query-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::indices-validate-query-execute-async - client.indices().validateQueryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::indices-validate-query-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testAnalyze() throws IOException, InterruptedException { - - RestHighLevelClient client = highLevelClient(); - - { - // tag::analyze-builtin-request - AnalyzeRequest request = AnalyzeRequest.withGlobalAnalyzer("english", // <1> - "Some text to analyze", "Some more text to analyze"); // <2> - // end::analyze-builtin-request - } - - { - // tag::analyze-custom-request - Map stopFilter = new HashMap<>(); - stopFilter.put("type", "stop"); - stopFilter.put("stopwords", new String[]{ "to" }); // <1> - AnalyzeRequest request = AnalyzeRequest.buildCustomAnalyzer("standard") // <2> - .addCharFilter("html_strip") // <3> - .addTokenFilter("lowercase") // <4> - .addTokenFilter(stopFilter) // <5> - .build("Some text to analyze"); - // end::analyze-custom-request - } - - { - // tag::analyze-custom-normalizer-request - AnalyzeRequest request = AnalyzeRequest.buildCustomNormalizer() - .addTokenFilter("lowercase") - .build("BaR"); - // end::analyze-custom-normalizer-request - - // tag::analyze-request-explain - request.explain(true); // <1> - request.attributes("keyword", "type"); // <2> - // end::analyze-request-explain - - // tag::analyze-execute - AnalyzeResponse response = client.indices().analyze(request, RequestOptions.DEFAULT); - // end::analyze-execute - - // tag::analyze-response-tokens - List tokens = response.getTokens(); // <1> - // end::analyze-response-tokens - // tag::analyze-response-detail - DetailAnalyzeResponse detail = response.detail(); // <1> - // end::analyze-response-detail - - assertNull(tokens); - assertNotNull(detail.tokenizer()); - } - - CreateIndexRequest req = new CreateIndexRequest("my_index"); - CreateIndexResponse resp = client.indices().create(req, RequestOptions.DEFAULT); - assertTrue(resp.isAcknowledged()); - - PutMappingRequest pmReq = new PutMappingRequest("my_index").source( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("my_field") - .field("type", "text") - .field("analyzer", "english") - .endObject() - .endObject() - .endObject() - ); - AcknowledgedResponse pmResp = client.indices().putMapping(pmReq, RequestOptions.DEFAULT); - assertTrue(pmResp.isAcknowledged()); - - { - // tag::analyze-index-request - AnalyzeRequest request = AnalyzeRequest.withIndexAnalyzer( - "my_index", // <1> - "my_analyzer", // <2> - "some text to analyze" - ); - // end::analyze-index-request - - // tag::analyze-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AnalyzeResponse analyzeTokens) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::analyze-execute-listener - - // use a built-in analyzer in the test - request = AnalyzeRequest.withField("my_index", "my_field", "some text to analyze"); - // Use a blocking listener in the test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::analyze-execute-async - client.indices().analyzeAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::analyze-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::analyze-index-normalizer-request - AnalyzeRequest request = AnalyzeRequest.withNormalizer( - "my_index", // <1> - "my_normalizer", // <2> - "some text to analyze" - ); - // end::analyze-index-normalizer-request - } - - { - // tag::analyze-field-request - AnalyzeRequest request = AnalyzeRequest.withField("my_index", "my_field", "some text to analyze"); - // end::analyze-field-request - } - - } - - public void testUnfreezeIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::unfreeze-index-request - UnfreezeIndexRequest request = new UnfreezeIndexRequest("index"); // <1> - // end::unfreeze-index-request - - // tag::unfreeze-index-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::unfreeze-index-request-timeout - // tag::unfreeze-index-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::unfreeze-index-request-masterTimeout - // tag::unfreeze-index-request-waitForActiveShards - request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <1> - // end::unfreeze-index-request-waitForActiveShards - - // tag::unfreeze-index-request-indicesOptions - request.setIndicesOptions(IndicesOptions.strictExpandOpen()); // <1> - // end::unfreeze-index-request-indicesOptions - - // tag::unfreeze-index-execute - final RequestOptions unfreezeIndexOptions = RequestOptions.DEFAULT.toBuilder() - .setWarningsHandler( - warnings -> List.of(FROZEN_INDICES_DEPRECATION_WARNING, IGNORE_THROTTLED_DEPRECATION_WARNING).equals(warnings) == false - ).build(); - ShardsAcknowledgedResponse openIndexResponse = client.indices().unfreeze(request, unfreezeIndexOptions); - // end::unfreeze-index-execute - - // tag::unfreeze-index-response - boolean acknowledged = openIndexResponse.isAcknowledged(); // <1> - boolean shardsAcked = openIndexResponse.isShardsAcknowledged(); // <2> - // end::unfreeze-index-response - assertTrue(acknowledged); - assertTrue(shardsAcked); - - // tag::unfreeze-index-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ShardsAcknowledgedResponse freezeIndexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::unfreeze-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::unfreeze-index-execute-async - client.indices().unfreezeAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::unfreeze-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::unfreeze-index-notfound - try { - UnfreezeIndexRequest request = new UnfreezeIndexRequest("does_not_exist"); - client.indices().unfreeze(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.BAD_REQUEST) { - // <1> - } - } - // end::unfreeze-index-notfound - } - } - - public void testDeleteTemplate() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest("my-template", List.of("pattern-1", "log-*")); - putRequest.settings(Settings.builder().put("index.number_of_shards", 3)); - assertTrue(client.indices().putTemplate(putRequest, LEGACY_TEMPLATE_OPTIONS).isAcknowledged()); - } - - // tag::delete-template-request - DeleteIndexTemplateRequest request = new DeleteIndexTemplateRequest(); - request.name("my-template"); // <1> - // end::delete-template-request - - // tag::delete-template-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::delete-template-request-masterTimeout - - // tag::delete-template-execute - AcknowledgedResponse deleteTemplateAcknowledge = client.indices().deleteTemplate(request, RequestOptions.DEFAULT); - // end::delete-template-execute - - // tag::delete-template-response - boolean acknowledged = deleteTemplateAcknowledge.isAcknowledged(); // <1> - // end::delete-template-response - assertThat(acknowledged, equalTo(true)); - - { - PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest("my-template", List.of("pattern-1", "log-*")); - putRequest.settings(Settings.builder().put("index.number_of_shards", 3)); - assertTrue(client.indices().putTemplate(putRequest, LEGACY_TEMPLATE_OPTIONS).isAcknowledged()); - } - // tag::delete-template-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-template-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-template-execute-async - client.indices().deleteTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-template-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testReloadSearchAnalyzers() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::reload-analyzers-request - ReloadAnalyzersRequest request = new ReloadAnalyzersRequest("index"); // <1> - // end::reload-analyzers-request - - // tag::reload-analyzers-request-indicesOptions - request.setIndicesOptions(IndicesOptions.strictExpandOpen()); // <1> - // end::reload-analyzers-request-indicesOptions - - // tag::reload-analyzers-execute - ReloadAnalyzersResponse reloadResponse = client.indices().reloadAnalyzers(request, RequestOptions.DEFAULT); - // end::reload-analyzers-execute - - // tag::reload-analyzers-response - Shards shards = reloadResponse.shards(); // <1> - Map reloadDetails = reloadResponse.getReloadedDetails(); // <2> - ReloadDetails details = reloadDetails.get("index"); // <3> - String indexName = details.getIndexName(); // <4> - Set indicesNodes = details.getReloadedIndicesNodes(); // <5> - Set analyzers = details.getReloadedAnalyzers(); // <6> - // end::reload-analyzers-response - assertNotNull(shards); - assertEquals("index", indexName); - assertEquals(1, indicesNodes.size()); - assertEquals(0, analyzers.size()); - - // tag::reload-analyzers-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ReloadAnalyzersResponse reloadResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::reload-analyzers-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::reload-analyzers-execute-async - client.indices().reloadAnalyzersAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::reload-analyzers-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::reload-analyzers-notfound - try { - ReloadAnalyzersRequest request = new ReloadAnalyzersRequest("does_not_exist"); - client.indices().reloadAnalyzers(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.BAD_REQUEST) { - // <1> - } - } - // end::reload-analyzers-notfound - } - } - - @SuppressWarnings("unused") - public void testDeleteAlias() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index1"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - { - IndicesAliasesRequest request = new IndicesAliasesRequest(); - AliasActions aliasAction = new AliasActions(AliasActions.Type.ADD).index("index1").alias("alias1"); - request.addAliasAction(aliasAction); - AcknowledgedResponse indicesAliasesResponse = client.indices().updateAliases(request, RequestOptions.DEFAULT); - assertTrue(indicesAliasesResponse.isAcknowledged()); - } - { - IndicesAliasesRequest request = new IndicesAliasesRequest(); - AliasActions aliasAction = new AliasActions(AliasActions.Type.ADD).index("index1").alias("alias2"); - request.addAliasAction(aliasAction); - AcknowledgedResponse indicesAliasesResponse = client.indices().updateAliases(request, RequestOptions.DEFAULT); - assertTrue(indicesAliasesResponse.isAcknowledged()); - } - { - // tag::delete-alias-request - DeleteAliasRequest request = new DeleteAliasRequest("index1", "alias1"); - // end::delete-alias-request - - // tag::delete-alias-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::delete-alias-request-timeout - // tag::delete-alias-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::delete-alias-request-masterTimeout - - // tag::delete-alias-execute - org.elasticsearch.client.core.AcknowledgedResponse deleteAliasResponse = - client.indices().deleteAlias(request, RequestOptions.DEFAULT); - // end::delete-alias-execute - - // tag::delete-alias-response - boolean acknowledged = deleteAliasResponse.isAcknowledged(); // <1> - // end::delete-alias-response - assertTrue(acknowledged); - } - - { - DeleteAliasRequest request = new DeleteAliasRequest("index1", "alias2"); // <1> - - // tag::delete-alias-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(org.elasticsearch.client.core.AcknowledgedResponse deleteAliasResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-alias-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-alias-execute-async - client.indices().deleteAliasAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-alias-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java deleted file mode 100644 index 51d8ef58db4b..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.ingest.DeletePipelineRequest; -import org.elasticsearch.action.ingest.GetPipelineRequest; -import org.elasticsearch.action.ingest.GetPipelineResponse; -import org.elasticsearch.action.ingest.PutPipelineRequest; -import org.elasticsearch.action.ingest.SimulateDocumentBaseResult; -import org.elasticsearch.action.ingest.SimulateDocumentResult; -import org.elasticsearch.action.ingest.SimulateDocumentVerboseResult; -import org.elasticsearch.action.ingest.SimulatePipelineRequest; -import org.elasticsearch.action.ingest.SimulatePipelineResponse; -import org.elasticsearch.action.ingest.SimulateProcessorResult; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.ingest.PipelineConfiguration; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * This class is used to generate the Java Ingest 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,macros"] - * -------------------------------------------------- - * include-tagged::{doc-tests}/IngestClientDocumentationIT.java[example] - * -------------------------------------------------- - * - * The column width of the code block is 84. If the code contains a line longer - * than 84, the line will be cut and a horizontal scroll bar will be displayed. - * (the code indentation of the tag is not included in the width) - */ -@SuppressWarnings("removal") -public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testPutPipeline() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - // tag::put-pipeline-request - String source = """ - { - "description": "my set of processors", - "processors": [ - { - "set": { - "field": "foo", - "value": "bar" - } - } - ] - } - """; - PutPipelineRequest request = new PutPipelineRequest( - "my-pipeline-id", // <1> - new BytesArray(source.getBytes(StandardCharsets.UTF_8)), // <2> - XContentType.JSON // <3> - ); - // end::put-pipeline-request - - // tag::put-pipeline-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::put-pipeline-request-timeout - - // tag::put-pipeline-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::put-pipeline-request-masterTimeout - - // tag::put-pipeline-execute - AcknowledgedResponse response = client.ingest().putPipeline(request, RequestOptions.DEFAULT); // <1> - // end::put-pipeline-execute - - // tag::put-pipeline-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::put-pipeline-response - assertTrue(acknowledged); - } - } - - public void testPutPipelineAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - String source = """ - { - "description": "my set of processors", - "processors": [ { "set": { "field": "foo", "value": "bar" } } ] - }"""; - PutPipelineRequest request = new PutPipelineRequest( - "my-pipeline-id", - new BytesArray(source.getBytes(StandardCharsets.UTF_8)), - XContentType.JSON - ); - - // tag::put-pipeline-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-pipeline-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-pipeline-execute-async - client.ingest().putPipelineAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-pipeline-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testGetPipeline() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - createPipeline("my-pipeline-id"); - } - - { - // tag::get-pipeline-request - GetPipelineRequest request = new GetPipelineRequest("my-pipeline-id"); // <1> - // end::get-pipeline-request - - // tag::get-pipeline-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::get-pipeline-request-masterTimeout - - // tag::get-pipeline-execute - GetPipelineResponse response = client.ingest().getPipeline(request, RequestOptions.DEFAULT); // <1> - // end::get-pipeline-execute - - // tag::get-pipeline-response - boolean successful = response.isFound(); // <1> - List pipelines = response.pipelines(); // <2> - for(PipelineConfiguration pipeline: pipelines) { - Map config = pipeline.getConfigAsMap(); // <3> - } - // end::get-pipeline-response - - assertTrue(successful); - } - } - - public void testGetPipelineAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createPipeline("my-pipeline-id"); - } - - { - GetPipelineRequest request = new GetPipelineRequest("my-pipeline-id"); - - // tag::get-pipeline-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetPipelineResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-pipeline-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-pipeline-execute-async - client.ingest().getPipelineAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-pipeline-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeletePipeline() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - createPipeline("my-pipeline-id"); - } - - { - // tag::delete-pipeline-request - DeletePipelineRequest request = new DeletePipelineRequest("my-pipeline-id"); // <1> - // end::delete-pipeline-request - - // tag::delete-pipeline-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::delete-pipeline-request-timeout - - // tag::delete-pipeline-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::delete-pipeline-request-masterTimeout - - // tag::delete-pipeline-execute - AcknowledgedResponse response = client.ingest().deletePipeline(request, RequestOptions.DEFAULT); // <1> - // end::delete-pipeline-execute - - // tag::delete-pipeline-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::delete-pipeline-response - assertTrue(acknowledged); - } - } - - public void testDeletePipelineAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - createPipeline("my-pipeline-id"); - } - - { - DeletePipelineRequest request = new DeletePipelineRequest("my-pipeline-id"); - - // tag::delete-pipeline-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-pipeline-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-pipeline-execute-async - client.ingest().deletePipelineAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-pipeline-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSimulatePipeline() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - // tag::simulate-pipeline-request - String source = """ - { - "pipeline": { - "description": "_description", - "processors": [ { "set": { "field": "field2", "value": "_value" } } ] - }, - "docs": [ - { - "_index": "index", - "_id": "id", - "_source": { - "foo": "bar" - } - }, - { - "_index": "index", - "_id": "id", - "_source": { - "foo": "rab" - } - } - ] - }"""; - SimulatePipelineRequest request = new SimulatePipelineRequest( - new BytesArray(source.getBytes(StandardCharsets.UTF_8)), // <1> - XContentType.JSON // <2> - ); - // end::simulate-pipeline-request - - // tag::simulate-pipeline-request-pipeline-id - request.setId("my-pipeline-id"); // <1> - // end::simulate-pipeline-request-pipeline-id - - // For testing we set this back to null - request.setId(null); - - // tag::simulate-pipeline-request-verbose - request.setVerbose(true); // <1> - // end::simulate-pipeline-request-verbose - - // tag::simulate-pipeline-execute - SimulatePipelineResponse response = client.ingest().simulate(request, RequestOptions.DEFAULT); // <1> - // end::simulate-pipeline-execute - - // tag::simulate-pipeline-response - for (SimulateDocumentResult result: response.getResults()) { // <1> - if (request.isVerbose()) { - assert result instanceof SimulateDocumentVerboseResult; - SimulateDocumentVerboseResult verboseResult = (SimulateDocumentVerboseResult)result; // <2> - for (SimulateProcessorResult processorResult: verboseResult.getProcessorResults()) { // <3> - processorResult.getIngestDocument(); // <4> - processorResult.getFailure(); // <5> - } - } else { - assert result instanceof SimulateDocumentBaseResult; - SimulateDocumentBaseResult baseResult = (SimulateDocumentBaseResult)result; // <6> - baseResult.getIngestDocument(); // <7> - baseResult.getFailure(); // <8> - } - } - // end::simulate-pipeline-response - assert (response.getResults().size() > 0); - } - } - - public void testSimulatePipelineAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - String source = """ - { - "pipeline": { - "description": "_description", - "processors": [ { "set": { "field": "field2", "value": "_value" } } ] - }, - "docs": [ - { - "_index": "index", - "_id": "id", - "_source": { - "foo": "bar" - } - }, - { - "_index": "index", - "_id": "id", - "_source": { - "foo": "rab" - } - } - ] - }"""; - SimulatePipelineRequest request = new SimulatePipelineRequest( - new BytesArray(source.getBytes(StandardCharsets.UTF_8)), - XContentType.JSON - ); - - // tag::simulate-pipeline-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(SimulatePipelineResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::simulate-pipeline-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::simulate-pipeline-execute-async - client.ingest().simulateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::simulate-pipeline-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java deleted file mode 100644 index 14f9c97b8db6..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.Build; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.license.DeleteLicenseRequest; -import org.elasticsearch.client.license.GetBasicStatusResponse; -import org.elasticsearch.client.license.GetLicenseRequest; -import org.elasticsearch.client.license.GetLicenseResponse; -import org.elasticsearch.client.license.GetTrialStatusResponse; -import org.elasticsearch.client.license.LicensesStatus; -import org.elasticsearch.client.license.PutLicenseRequest; -import org.elasticsearch.client.license.PutLicenseResponse; -import org.elasticsearch.client.license.StartBasicRequest; -import org.elasticsearch.client.license.StartBasicResponse; -import org.elasticsearch.client.license.StartTrialRequest; -import org.elasticsearch.client.license.StartTrialResponse; -import org.elasticsearch.core.Booleans; -import org.junit.After; -import org.junit.BeforeClass; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.client.LicenseIT.putTrialLicense; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.core.Is.is; - -/** - * Documentation for Licensing APIs in the high level java client. - * Code wrapped in {@code tag} and {@code end} tags is included in the docs. - */ -@SuppressWarnings("removal") -public class LicensingDocumentationIT extends ESRestHighLevelClientTestCase { - - @BeforeClass - public static void checkForSnapshot() { - assumeTrue("Trial license used to rollback is only valid when tested against snapshot/test builds", Build.CURRENT.isSnapshot()); - } - - @After - public void rollbackToTrial() throws IOException { - putTrialLicense(); - } - - public void testLicense() throws Exception { - RestHighLevelClient client = highLevelClient(); - String license = """ - { - "license": { - "uid": "893361dc-9749-4997-93cb-802e3d7fa4a8", - "type": "gold", - "issue_date_in_millis": 1411948800000, - "expiry_date_in_millis": 1914278399999, - "max_nodes": 1, - "issued_to": "issued_to", - "issuer": "issuer", - "signature": "AAAAAgAAAA3U8+YmnvwC+CWsV/mRAAABmC9ZN0hjZDBGYnVyRXpCOW5Bb3FjZDAxOWpSbTVoMVZwUzRxVk1PSmkxakxZdW5IMlhlTHNoN1N2\ - MXMvRFk4d3JTZEx3R3RRZ0pzU3lobWJKZnQvSEFva0ppTHBkWkprZWZSQi9iNmRQNkw1SlpLN0lDalZCS095MXRGN1lIZlpYcVVTTnFrcTE2dzhJZmZrdFQrN3JQeG\ - wxb0U0MXZ0dDJHSERiZTVLOHNzSDByWnpoZEphZHBEZjUrTVBxRENNSXNsWWJjZllaODdzVmEzUjNiWktNWGM5TUhQV2plaUo4Q1JOUml4MXNuL0pSOEhQaVB2azhm\ - Uk9QVzhFeTFoM1Q0RnJXSG53MWk2K055c28zSmRnVkF1b2JSQkFLV2VXUmVHNDZ2R3o2VE1qbVNQS2lxOHN5bUErZlNIWkZSVmZIWEtaSU9wTTJENDVvT1NCYklacU\ - YyK2FwRW9xa0t6dldMbmMzSGtQc3FWOTgzZ3ZUcXMvQkt2RUZwMFJnZzlvL2d2bDRWUzh6UG5pdENGWFRreXNKNkE9PQAAAQBe8GfzDm6T537Iuuvjetb3xK5dvg0K\ - 5NQapv+rczWcQFxgCuzbF8plkgetP1aAGZP4uRESDQPMlOCsx4d0UqqAm9f7GbBQ3l93P+PogInPFeEH9NvOmaAQovmxVM9SE6DsDqlX4cXSO+bgWpXPTd2LmpoQc1\ - fXd6BZ8GeuyYpVHVKp9hVU0tAYjw6HzYOE7+zuO1oJYOxElqy66AnIfkvHrvni+flym3tE7tDTgsDRaz7W3iBhaqiSntEqabEkvHdPHQdSR99XGaEvnHO1paK01/35\ - iZF6OXHsF7CCj+558GRXiVxzueOe7TsGSSt8g7YjZwV9bRCyU7oB4B/nidgI" - } - }"""; - { - //tag::put-license-execute - PutLicenseRequest request = new PutLicenseRequest(); - request.setLicenseDefinition(license); // <1> - request.setAcknowledge(false); // <2> - - PutLicenseResponse response = client.license().putLicense(request, RequestOptions.DEFAULT); - //end::put-license-execute - - //tag::put-license-response - LicensesStatus status = response.status(); // <1> - assertEquals(status, LicensesStatus.VALID); // <2> - boolean acknowledged = response.isAcknowledged(); // <3> - String acknowledgeHeader = response.acknowledgeHeader(); // <4> - Map acknowledgeMessages = response.acknowledgeMessages(); // <5> - //end::put-license-response - - assertFalse(acknowledged); // Should fail because we are trying to downgrade from platinum trial to gold - assertThat(acknowledgeHeader, startsWith("This license update requires acknowledgement.")); - assertThat(acknowledgeMessages.keySet(), not(hasSize(0))); - } - { - PutLicenseRequest request = new PutLicenseRequest(); - // tag::put-license-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutLicenseResponse putLicenseResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-license-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-license-execute-async - client.license().putLicenseAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::put-license-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - // we cannot actually delete the license, otherwise the remaining tests won't work - if (Booleans.isTrue("true")) { - return; - } - { - //tag::delete-license-execute - DeleteLicenseRequest request = new DeleteLicenseRequest(); - - AcknowledgedResponse response = client.license().deleteLicense(request, RequestOptions.DEFAULT); - //end::delete-license-execute - - //tag::delete-license-response - boolean acknowledged = response.isAcknowledged(); // <1> - //end::delete-license-response - - assertTrue(acknowledged); - } - { - DeleteLicenseRequest request = new DeleteLicenseRequest(); - // tag::delete-license-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse deleteLicenseResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-license-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-license-execute-async - client.license().deleteLicenseAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-license-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetLicense() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-license-execute - GetLicenseRequest request = new GetLicenseRequest(); - - GetLicenseResponse response = client.license().getLicense(request, RequestOptions.DEFAULT); - //end::get-license-execute - - //tag::get-license-response - String currentLicense = response.getLicenseDefinition(); // <1> - //end::get-license-response - - assertThat(currentLicense, containsString("trial")); - assertThat(currentLicense, containsString("ntegTest")); - } - { - GetLicenseRequest request = new GetLicenseRequest(); - // tag::get-license-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetLicenseResponse indexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-license-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-license-execute-async - client.license().getLicenseAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::get-license-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - { - GetLicenseRequest request = new GetLicenseRequest(); - RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder(); - // Make sure that it still works in other formats - builder.addHeader("Accept", randomFrom("application/smile", "application/cbor")); - RequestOptions options = builder.build(); - GetLicenseResponse response = client.license().getLicense(request, options); - String currentLicense = response.getLicenseDefinition(); - assertThat(currentLicense, startsWith("{")); - assertThat(currentLicense, containsString("trial")); - assertThat(currentLicense, containsString("ntegTest")); - assertThat(currentLicense, endsWith("}")); - } - } - - public void testStartTrial() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::start-trial-execute - StartTrialRequest request = new StartTrialRequest(true); // <1> - - StartTrialResponse response = client.license().startTrial(request, RequestOptions.DEFAULT); - // end::start-trial-execute - - // tag::start-trial-response - boolean acknowledged = response.isAcknowledged(); // <1> - boolean trialWasStarted = response.isTrialWasStarted(); // <2> - String licenseType = response.getLicenseType(); // <3> - String errorMessage = response.getErrorMessage(); // <4> - String acknowledgeHeader = response.getAcknowledgeHeader(); // <5> - Map acknowledgeMessages = response.getAcknowledgeMessages(); // <6> - // end::start-trial-response - - assertTrue(acknowledged); - assertFalse(trialWasStarted); - assertThat(licenseType, nullValue()); - assertThat(errorMessage, is("Operation failed: Trial was already activated.")); - assertThat(acknowledgeHeader, nullValue()); - assertThat(acknowledgeMessages, nullValue()); - } - - { - StartTrialRequest request = new StartTrialRequest(); - - // tag::start-trial-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StartTrialResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-trial-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::start-trial-execute-async - client.license().startTrialAsync(request, RequestOptions.DEFAULT, listener); - // end::start-trial-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPostStartBasic() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::start-basic-execute - StartBasicRequest request = new StartBasicRequest(); - - StartBasicResponse response = client.license().startBasic(request, RequestOptions.DEFAULT); - //end::start-basic-execute - - //tag::start-basic-response - boolean acknowledged = response.isAcknowledged(); // <1> - boolean basicStarted = response.isBasicStarted(); // <2> - String errorMessage = response.getErrorMessage(); // <3> - String acknowledgeMessage = response.getAcknowledgeMessage(); // <4> - Map acknowledgeMessages = response.getAcknowledgeMessages(); // <5> - //end::start-basic-response - } - { - StartBasicRequest request = new StartBasicRequest(); - // tag::start-basic-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StartBasicResponse indexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-basic-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::start-basic-execute-async - client.license().startBasicAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::start-basic-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetTrialStatus() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-trial-status-execute - GetTrialStatusResponse response = client.license().getTrialStatus(RequestOptions.DEFAULT); - //end::get-trial-status-execute - - //tag::get-trial-status-response - boolean eligibleToStartTrial = response.isEligibleToStartTrial(); // <1> - //end::get-trial-status-response - } - } - - public void testGetBasicStatus() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-basic-status-execute - GetBasicStatusResponse response = client.license().getBasicStatus(RequestOptions.DEFAULT); - //end::get-basic-status-execute - - //tag::get-basic-status-response - boolean eligibleToStartbasic = response.isEligibleToStartBasic(); // <1> - //end::get-basic-status-response - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java deleted file mode 100644 index 44b0e9e30be9..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.migration.DeprecationInfoRequest; -import org.elasticsearch.client.migration.DeprecationInfoResponse; -import org.elasticsearch.common.settings.Settings; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * This class is used to generate the Java Migration 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,macros"] - * -------------------------------------------------- - * include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[example] - * -------------------------------------------------- - * - * The column width of the code block is 84. If the code contains a line longer - * than 84, the line will be cut and a horizontal scroll bar will be displayed. - * (the code indentation of the tag is not included in the width) - */ -@SuppressWarnings("removal") -public class MigrationClientDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testGetDeprecationInfo() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - createIndex("test", Settings.EMPTY); - - //tag::get-deprecation-info-request - List indices = new ArrayList<>(); - indices.add("test"); - DeprecationInfoRequest deprecationInfoRequest = new DeprecationInfoRequest(indices); // <1> - //end::get-deprecation-info-request - - // tag::get-deprecation-info-execute - DeprecationInfoResponse deprecationInfoResponse = - client.migration().getDeprecationInfo(deprecationInfoRequest, RequestOptions.DEFAULT); - // end::get-deprecation-info-execute - - // tag::get-deprecation-info-response - List clusterIssues = - deprecationInfoResponse.getClusterSettingsIssues(); // <1> - List nodeIssues = - deprecationInfoResponse.getNodeSettingsIssues(); // <2> - Map> indexIssues = - deprecationInfoResponse.getIndexSettingsIssues(); // <3> - List mlIssues = - deprecationInfoResponse.getMlSettingsIssues(); // <4> - // end::get-deprecation-info-response - - // tag::get-deprecation-info-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(DeprecationInfoResponse deprecationInfoResponse1) { // <1> - List clusterIssues = - deprecationInfoResponse.getClusterSettingsIssues(); - List nodeIssues = - deprecationInfoResponse.getNodeSettingsIssues(); - Map> indexIssues = - deprecationInfoResponse.getIndexSettingsIssues(); - List mlIssues = - deprecationInfoResponse.getMlSettingsIssues(); - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-deprecation-info-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-deprecation-info-execute-async - client.migration().getDeprecationInfoAsync(deprecationInfoRequest, - RequestOptions.DEFAULT, listener); // <1> - // end::get-deprecation-info-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java deleted file mode 100644 index 16623f062dc0..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.delete.DeleteRequest; -import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.get.GetRequest; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; - -/** - * This class is used to generate the documentation for the - * docs/java-rest/high-level/migration.asciidoc page. - * - * 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,macros"] - * -------------------------------------------------- - * include-tagged::{doc-tests}/MigrationDocumentationIT.java[example] - * -------------------------------------------------- - */ -@SuppressWarnings("removal") -public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase { - public void testClusterHealth() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - //tag::migration-cluster-health - Request request = new Request("GET", "/_cluster/health"); - request.addParameter("wait_for_status", "green"); // <1> - Response response = client.getLowLevelClient().performRequest(request); // <2> - - ClusterHealthStatus healthStatus; - try (InputStream is = response.getEntity().getContent()) { // <3> - Map map = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); // <4> - healthStatus = ClusterHealthStatus.fromString((String) map.get("status")); // <5> - } - - if (healthStatus != ClusterHealthStatus.GREEN) { - // <6> - } - //end::migration-cluster-health - assertSame(ClusterHealthStatus.GREEN, healthStatus); - } - } - - public void testRequests() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::migration-request-ctor - IndexRequest request = new IndexRequest("index").id("id"); // <1> - request.source("{\"field\":\"value\"}", XContentType.JSON); - //end::migration-request-ctor - - //tag::migration-request-ctor-execution - IndexResponse response = client.index(request, RequestOptions.DEFAULT); - //end::migration-request-ctor-execution - assertEquals(RestStatus.CREATED, response.status()); - } - { - //tag::migration-request-async-execution - DeleteRequest request = new DeleteRequest("index", "id"); // <1> - client.deleteAsync(request, RequestOptions.DEFAULT, new ActionListener() { // <2> - @Override - public void onResponse(DeleteResponse deleteResponse) { - // <3> - } - - @Override - public void onFailure(Exception e) { - // <4> - } - }); - //end::migration-request-async-execution - assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "id"), RequestOptions.DEFAULT))); - } - { - //tag::migration-request-sync-execution - DeleteRequest request = new DeleteRequest("index", "id"); - DeleteResponse response = client.delete(request, RequestOptions.DEFAULT); // <1> - //end::migration-request-sync-execution - assertEquals(RestStatus.NOT_FOUND, response.status()); - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MiscellaneousDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MiscellaneousDocumentationIT.java deleted file mode 100644 index 977a4c4c4b44..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MiscellaneousDocumentationIT.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.apache.http.HttpHost; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.MainResponse; -import org.elasticsearch.client.xpack.XPackInfoRequest; -import org.elasticsearch.client.xpack.XPackInfoResponse; -import org.elasticsearch.client.xpack.XPackInfoResponse.BuildInfo; -import org.elasticsearch.client.xpack.XPackInfoResponse.FeatureSetsInfo; -import org.elasticsearch.client.xpack.XPackInfoResponse.LicenseInfo; -import org.elasticsearch.client.xpack.XPackUsageRequest; -import org.elasticsearch.client.xpack.XPackUsageResponse; - -import java.io.IOException; -import java.time.Instant; -import java.util.EnumSet; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; - -/** - * Documentation for miscellaneous APIs in the high level java client. - * Code wrapped in {@code tag} and {@code end} tags is included in the docs. - */ -@SuppressWarnings("removal") -public class MiscellaneousDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testMain() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - //tag::main-execute - MainResponse response = client.info(RequestOptions.DEFAULT); - //end::main-execute - //tag::main-response - String clusterName = response.getClusterName(); - String clusterUuid = response.getClusterUuid(); - String nodeName = response.getNodeName(); - MainResponse.Version version = response.getVersion(); - String buildDate = version.getBuildDate(); - String buildFlavor = version.getBuildFlavor(); - String buildHash = version.getBuildHash(); - String buildType = version.getBuildType(); - String luceneVersion = version.getLuceneVersion(); - String minimumIndexCompatibilityVersion= version.getMinimumIndexCompatibilityVersion(); - String minimumWireCompatibilityVersion = version.getMinimumWireCompatibilityVersion(); - String number = version.getNumber(); - //end::main-response - assertNotNull(clusterName); - assertNotNull(clusterUuid); - assertNotNull(nodeName); - assertNotNull(version); - assertNotNull(buildDate); - assertNotNull(buildFlavor); - assertNotNull(buildHash); - assertNotNull(buildType); - assertNotNull(luceneVersion); - assertNotNull(minimumIndexCompatibilityVersion); - assertNotNull(minimumWireCompatibilityVersion); - assertNotNull(number); - } - } - - public void testPing() throws IOException { - RestHighLevelClient client = highLevelClient(); - //tag::ping-execute - boolean response = client.ping(RequestOptions.DEFAULT); - //end::ping-execute - assertTrue(response); - } - - public void testXPackInfo() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::x-pack-info-execute - XPackInfoRequest request = new XPackInfoRequest(); - request.setVerbose(true); // <1> - request.setCategories(EnumSet.of( // <2> - XPackInfoRequest.Category.BUILD, - XPackInfoRequest.Category.LICENSE, - XPackInfoRequest.Category.FEATURES)); - XPackInfoResponse response = client.xpack().info(request, RequestOptions.DEFAULT); - //end::x-pack-info-execute - - //tag::x-pack-info-response - BuildInfo build = response.getBuildInfo(); // <1> - LicenseInfo license = response.getLicenseInfo(); // <2> - assertThat(license.getExpiryDate(), is(greaterThan(Instant.now().toEpochMilli()))); // <3> - FeatureSetsInfo features = response.getFeatureSetsInfo(); // <4> - //end::x-pack-info-response - - assertNotNull(response.getBuildInfo()); - assertNotNull(response.getLicenseInfo()); - assertNotNull(response.getFeatureSetsInfo()); - } - { - XPackInfoRequest request = new XPackInfoRequest(); - // tag::x-pack-info-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(XPackInfoResponse indexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-info-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-info-execute-async - client.xpack().infoAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-info-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testXPackUsage() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::x-pack-usage-execute - XPackUsageRequest request = new XPackUsageRequest(); - XPackUsageResponse response = client.xpack().usage(request, RequestOptions.DEFAULT); - //end::x-pack-usage-execute - - //tag::x-pack-usage-response - Map> usages = response.getUsages(); - Map monitoringUsage = usages.get("monitoring"); - assertThat(monitoringUsage.get("available"), is(true)); - assertThat(monitoringUsage.get("enabled"), is(true)); - assertThat(monitoringUsage.get("collection_enabled"), is(false)); - //end::x-pack-usage-response - } - { - XPackUsageRequest request = new XPackUsageRequest(); - // tag::x-pack-usage-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(XPackUsageResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-usage-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-usage-execute-async - client.xpack().usageAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-usage-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testInitializationFromClientBuilder() throws IOException { - //tag::rest-high-level-client-init - RestHighLevelClient client = new RestHighLevelClient( - RestClient.builder( - new HttpHost("localhost", 9200, "http"), - new HttpHost("localhost", 9201, "http"))); - //end::rest-high-level-client-init - - //tag::rest-high-level-client-close - client.close(); - //end::rest-high-level-client-close - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java deleted file mode 100644 index eea8cd2223e7..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java +++ /dev/null @@ -1,4706 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.documentation; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.bulk.BulkRequest; -import org.elasticsearch.action.get.GetRequest; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.support.WriteRequest; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.MachineLearningGetResultsIT; -import org.elasticsearch.client.MachineLearningIT; -import org.elasticsearch.client.MlTestStateCleaner; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.PageParams; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.ml.CloseJobRequest; -import org.elasticsearch.client.ml.CloseJobResponse; -import org.elasticsearch.client.ml.DeleteCalendarEventRequest; -import org.elasticsearch.client.ml.DeleteCalendarJobRequest; -import org.elasticsearch.client.ml.DeleteCalendarRequest; -import org.elasticsearch.client.ml.DeleteDataFrameAnalyticsRequest; -import org.elasticsearch.client.ml.DeleteDatafeedRequest; -import org.elasticsearch.client.ml.DeleteExpiredDataRequest; -import org.elasticsearch.client.ml.DeleteExpiredDataResponse; -import org.elasticsearch.client.ml.DeleteFilterRequest; -import org.elasticsearch.client.ml.DeleteForecastRequest; -import org.elasticsearch.client.ml.DeleteJobRequest; -import org.elasticsearch.client.ml.DeleteJobResponse; -import org.elasticsearch.client.ml.DeleteModelSnapshotRequest; -import org.elasticsearch.client.ml.DeleteTrainedModelAliasRequest; -import org.elasticsearch.client.ml.DeleteTrainedModelRequest; -import org.elasticsearch.client.ml.EstimateModelMemoryRequest; -import org.elasticsearch.client.ml.EstimateModelMemoryResponse; -import org.elasticsearch.client.ml.EvaluateDataFrameRequest; -import org.elasticsearch.client.ml.EvaluateDataFrameResponse; -import org.elasticsearch.client.ml.ExplainDataFrameAnalyticsRequest; -import org.elasticsearch.client.ml.ExplainDataFrameAnalyticsResponse; -import org.elasticsearch.client.ml.FlushJobRequest; -import org.elasticsearch.client.ml.FlushJobResponse; -import org.elasticsearch.client.ml.ForecastJobRequest; -import org.elasticsearch.client.ml.ForecastJobResponse; -import org.elasticsearch.client.ml.GetBucketsRequest; -import org.elasticsearch.client.ml.GetBucketsResponse; -import org.elasticsearch.client.ml.GetCalendarEventsRequest; -import org.elasticsearch.client.ml.GetCalendarEventsResponse; -import org.elasticsearch.client.ml.GetCalendarsRequest; -import org.elasticsearch.client.ml.GetCalendarsResponse; -import org.elasticsearch.client.ml.GetCategoriesRequest; -import org.elasticsearch.client.ml.GetCategoriesResponse; -import org.elasticsearch.client.ml.GetDataFrameAnalyticsRequest; -import org.elasticsearch.client.ml.GetDataFrameAnalyticsResponse; -import org.elasticsearch.client.ml.GetDataFrameAnalyticsStatsRequest; -import org.elasticsearch.client.ml.GetDataFrameAnalyticsStatsResponse; -import org.elasticsearch.client.ml.GetDatafeedRequest; -import org.elasticsearch.client.ml.GetDatafeedResponse; -import org.elasticsearch.client.ml.GetDatafeedStatsRequest; -import org.elasticsearch.client.ml.GetDatafeedStatsResponse; -import org.elasticsearch.client.ml.GetFiltersRequest; -import org.elasticsearch.client.ml.GetFiltersResponse; -import org.elasticsearch.client.ml.GetInfluencersRequest; -import org.elasticsearch.client.ml.GetInfluencersResponse; -import org.elasticsearch.client.ml.GetJobRequest; -import org.elasticsearch.client.ml.GetJobResponse; -import org.elasticsearch.client.ml.GetJobStatsRequest; -import org.elasticsearch.client.ml.GetJobStatsResponse; -import org.elasticsearch.client.ml.GetModelSnapshotsRequest; -import org.elasticsearch.client.ml.GetModelSnapshotsResponse; -import org.elasticsearch.client.ml.GetOverallBucketsRequest; -import org.elasticsearch.client.ml.GetOverallBucketsResponse; -import org.elasticsearch.client.ml.GetRecordsRequest; -import org.elasticsearch.client.ml.GetRecordsResponse; -import org.elasticsearch.client.ml.GetTrainedModelsRequest; -import org.elasticsearch.client.ml.GetTrainedModelsResponse; -import org.elasticsearch.client.ml.GetTrainedModelsStatsRequest; -import org.elasticsearch.client.ml.GetTrainedModelsStatsResponse; -import org.elasticsearch.client.ml.MlInfoRequest; -import org.elasticsearch.client.ml.MlInfoResponse; -import org.elasticsearch.client.ml.OpenJobRequest; -import org.elasticsearch.client.ml.OpenJobResponse; -import org.elasticsearch.client.ml.PostCalendarEventRequest; -import org.elasticsearch.client.ml.PostCalendarEventResponse; -import org.elasticsearch.client.ml.PostDataRequest; -import org.elasticsearch.client.ml.PostDataResponse; -import org.elasticsearch.client.ml.PreviewDatafeedRequest; -import org.elasticsearch.client.ml.PreviewDatafeedResponse; -import org.elasticsearch.client.ml.PutCalendarJobRequest; -import org.elasticsearch.client.ml.PutCalendarRequest; -import org.elasticsearch.client.ml.PutCalendarResponse; -import org.elasticsearch.client.ml.PutDataFrameAnalyticsRequest; -import org.elasticsearch.client.ml.PutDataFrameAnalyticsResponse; -import org.elasticsearch.client.ml.PutDatafeedRequest; -import org.elasticsearch.client.ml.PutDatafeedResponse; -import org.elasticsearch.client.ml.PutFilterRequest; -import org.elasticsearch.client.ml.PutFilterResponse; -import org.elasticsearch.client.ml.PutJobRequest; -import org.elasticsearch.client.ml.PutJobResponse; -import org.elasticsearch.client.ml.PutTrainedModelAliasRequest; -import org.elasticsearch.client.ml.PutTrainedModelRequest; -import org.elasticsearch.client.ml.PutTrainedModelResponse; -import org.elasticsearch.client.ml.RevertModelSnapshotRequest; -import org.elasticsearch.client.ml.RevertModelSnapshotResponse; -import org.elasticsearch.client.ml.SetUpgradeModeRequest; -import org.elasticsearch.client.ml.StartDataFrameAnalyticsRequest; -import org.elasticsearch.client.ml.StartDataFrameAnalyticsResponse; -import org.elasticsearch.client.ml.StartDatafeedRequest; -import org.elasticsearch.client.ml.StartDatafeedResponse; -import org.elasticsearch.client.ml.StopDataFrameAnalyticsRequest; -import org.elasticsearch.client.ml.StopDataFrameAnalyticsResponse; -import org.elasticsearch.client.ml.StopDatafeedRequest; -import org.elasticsearch.client.ml.StopDatafeedResponse; -import org.elasticsearch.client.ml.UpdateDataFrameAnalyticsRequest; -import org.elasticsearch.client.ml.UpdateDatafeedRequest; -import org.elasticsearch.client.ml.UpdateFilterRequest; -import org.elasticsearch.client.ml.UpdateJobRequest; -import org.elasticsearch.client.ml.UpdateModelSnapshotRequest; -import org.elasticsearch.client.ml.UpdateModelSnapshotResponse; -import org.elasticsearch.client.ml.UpgradeJobModelSnapshotRequest; -import org.elasticsearch.client.ml.UpgradeJobModelSnapshotResponse; -import org.elasticsearch.client.ml.calendars.Calendar; -import org.elasticsearch.client.ml.calendars.ScheduledEvent; -import org.elasticsearch.client.ml.calendars.ScheduledEventTests; -import org.elasticsearch.client.ml.datafeed.ChunkingConfig; -import org.elasticsearch.client.ml.datafeed.DatafeedConfig; -import org.elasticsearch.client.ml.datafeed.DatafeedStats; -import org.elasticsearch.client.ml.datafeed.DatafeedUpdate; -import org.elasticsearch.client.ml.datafeed.DelayedDataCheckConfig; -import org.elasticsearch.client.ml.dataframe.Classification; -import org.elasticsearch.client.ml.dataframe.DataFrameAnalysis; -import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig; -import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfigUpdate; -import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsDest; -import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsSource; -import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsState; -import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsStats; -import org.elasticsearch.client.ml.dataframe.QueryConfig; -import org.elasticsearch.client.ml.dataframe.Regression; -import org.elasticsearch.client.ml.dataframe.evaluation.Evaluation; -import org.elasticsearch.client.ml.dataframe.evaluation.EvaluationMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.classification.AccuracyMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.classification.AucRocMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.classification.MulticlassConfusionMatrixMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.classification.MulticlassConfusionMatrixMetric.ActualClass; -import org.elasticsearch.client.ml.dataframe.evaluation.classification.MulticlassConfusionMatrixMetric.PredictedClass; -import org.elasticsearch.client.ml.dataframe.evaluation.classification.PrecisionMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.classification.RecallMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.common.AucRocResult; -import org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.ConfusionMatrixMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.ConfusionMatrixMetric.ConfusionMatrix; -import org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.OutlierDetection; -import org.elasticsearch.client.ml.dataframe.evaluation.regression.HuberMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.regression.MeanSquaredErrorMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.regression.MeanSquaredLogarithmicErrorMetric; -import org.elasticsearch.client.ml.dataframe.evaluation.regression.RSquaredMetric; -import org.elasticsearch.client.ml.dataframe.explain.FieldSelection; -import org.elasticsearch.client.ml.dataframe.explain.MemoryEstimation; -import org.elasticsearch.client.ml.inference.InferenceToXContentCompressor; -import org.elasticsearch.client.ml.inference.MlInferenceNamedXContentProvider; -import org.elasticsearch.client.ml.inference.TrainedModelConfig; -import org.elasticsearch.client.ml.inference.TrainedModelDefinition; -import org.elasticsearch.client.ml.inference.TrainedModelDefinitionTests; -import org.elasticsearch.client.ml.inference.TrainedModelInput; -import org.elasticsearch.client.ml.inference.TrainedModelStats; -import org.elasticsearch.client.ml.inference.TrainedModelType; -import org.elasticsearch.client.ml.inference.preprocessing.OneHotEncoding; -import org.elasticsearch.client.ml.inference.trainedmodel.RegressionConfig; -import org.elasticsearch.client.ml.inference.trainedmodel.TargetType; -import org.elasticsearch.client.ml.job.config.AnalysisConfig; -import org.elasticsearch.client.ml.job.config.AnalysisLimits; -import org.elasticsearch.client.ml.job.config.DataDescription; -import org.elasticsearch.client.ml.job.config.DetectionRule; -import org.elasticsearch.client.ml.job.config.Detector; -import org.elasticsearch.client.ml.job.config.Job; -import org.elasticsearch.client.ml.job.config.JobUpdate; -import org.elasticsearch.client.ml.job.config.MlFilter; -import org.elasticsearch.client.ml.job.config.ModelPlotConfig; -import org.elasticsearch.client.ml.job.config.Operator; -import org.elasticsearch.client.ml.job.config.RuleCondition; -import org.elasticsearch.client.ml.job.process.DataCounts; -import org.elasticsearch.client.ml.job.process.ModelSnapshot; -import org.elasticsearch.client.ml.job.results.AnomalyRecord; -import org.elasticsearch.client.ml.job.results.Bucket; -import org.elasticsearch.client.ml.job.results.CategoryDefinition; -import org.elasticsearch.client.ml.job.results.Influencer; -import org.elasticsearch.client.ml.job.results.OverallBucket; -import org.elasticsearch.client.ml.job.stats.JobStats; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.query.MatchAllQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.fetch.subphase.FetchSourceContext; -import org.elasticsearch.tasks.TaskId; -import org.elasticsearch.xcontent.NamedXContentRegistry; -import org.elasticsearch.xcontent.XContentFactory; -import org.elasticsearch.xcontent.XContentType; -import org.junit.After; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.function.BiFunction; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static java.util.stream.Collectors.toList; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.lessThan; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.core.Is.is; - -@SuppressWarnings("removal") -public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase { - - private static final RequestOptions POST_DATA_OPTIONS = RequestOptions.DEFAULT.toBuilder() - .setWarningsHandler( - warnings -> Collections.singletonList( - "Posting data directly to anomaly detection jobs is deprecated, " - + "in a future major version it will be compulsory to use a datafeed" - ).equals(warnings) == false - ) - .build(); - - @After - public void cleanUp() throws IOException { - new MlTestStateCleaner(logger, adminHighLevelClient()).clearMlMetadata(); - } - - public void testCreateJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - // tag::put-job-detector - Detector.Builder detectorBuilder = new Detector.Builder() - .setFunction("sum") // <1> - .setFieldName("total") // <2> - .setDetectorDescription("Sum of total"); // <3> - // end::put-job-detector - - // tag::put-job-analysis-config - List detectors = Collections.singletonList(detectorBuilder.build()); // <1> - AnalysisConfig.Builder analysisConfigBuilder = new AnalysisConfig.Builder(detectors) // <2> - .setBucketSpan(TimeValue.timeValueMinutes(10)); // <3> - // end::put-job-analysis-config - - // tag::put-job-data-description - DataDescription.Builder dataDescriptionBuilder = new DataDescription.Builder() - .setTimeField("timestamp"); // <1> - // end::put-job-data-description - - { - String id = "job_1"; - - // tag::put-job-config - Job.Builder jobBuilder = new Job.Builder(id) // <1> - .setAnalysisConfig(analysisConfigBuilder) // <2> - .setDataDescription(dataDescriptionBuilder) // <3> - .setDescription("Total sum of requests"); // <4> - // end::put-job-config - - // tag::put-job-request - PutJobRequest request = new PutJobRequest(jobBuilder.build()); // <1> - // end::put-job-request - - // tag::put-job-execute - PutJobResponse response = client.machineLearning().putJob(request, RequestOptions.DEFAULT); - // end::put-job-execute - - // tag::put-job-response - Date createTime = response.getResponse().getCreateTime(); // <1> - // end::put-job-response - assertThat(createTime.getTime(), greaterThan(0L)); - } - { - String id = "job_2"; - Job.Builder jobBuilder = new Job.Builder(id).setAnalysisConfig(analysisConfigBuilder) - .setDataDescription(dataDescriptionBuilder) - .setDescription("Total sum of requests"); - - PutJobRequest request = new PutJobRequest(jobBuilder.build()); - // tag::put-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutJobResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-job-execute-async - client.machineLearning().putJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("get-machine-learning-job1"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - Job secondJob = MachineLearningIT.buildJob("get-machine-learning-job2"); - client.machineLearning().putJob(new PutJobRequest(secondJob), RequestOptions.DEFAULT); - - { - // tag::get-job-request - GetJobRequest request = new GetJobRequest("get-machine-learning-job1", "get-machine-learning-job*"); // <1> - request.setAllowNoMatch(true); // <2> - request.setExcludeGenerated(false); // <3> - // end::get-job-request - - // tag::get-job-execute - GetJobResponse response = client.machineLearning().getJob(request, RequestOptions.DEFAULT); - // end::get-job-execute - - // tag::get-job-response - long numberOfJobs = response.count(); // <1> - List jobs = response.jobs(); // <2> - // end::get-job-response - assertEquals(2, response.count()); - assertThat(response.jobs(), hasSize(2)); - assertThat( - response.jobs().stream().map(Job::getId).collect(Collectors.toList()), - containsInAnyOrder(job.getId(), secondJob.getId()) - ); - } - { - GetJobRequest request = new GetJobRequest("get-machine-learning-job1", "get-machine-learning-job*"); - - // tag::get-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetJobResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-job-execute-async - client.machineLearning().getJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - String jobId = "my-first-machine-learning-job"; - - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - Job secondJob = MachineLearningIT.buildJob("my-second-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(secondJob), RequestOptions.DEFAULT); - - { - //tag::delete-job-request - DeleteJobRequest deleteJobRequest = new DeleteJobRequest("my-first-machine-learning-job"); // <1> - //end::delete-job-request - - //tag::delete-job-request-force - deleteJobRequest.setForce(false); // <1> - //end::delete-job-request-force - - //tag::delete-job-request-wait-for-completion - deleteJobRequest.setWaitForCompletion(true); // <1> - //end::delete-job-request-wait-for-completion - - //tag::delete-job-execute - DeleteJobResponse deleteJobResponse = client.machineLearning().deleteJob(deleteJobRequest, RequestOptions.DEFAULT); - //end::delete-job-execute - - //tag::delete-job-response - Boolean isAcknowledged = deleteJobResponse.getAcknowledged(); // <1> - TaskId task = deleteJobResponse.getTask(); // <2> - //end::delete-job-response - - assertTrue(isAcknowledged); - assertNull(task); - } - { - //tag::delete-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(DeleteJobResponse deleteJobResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - DeleteJobRequest deleteJobRequest = new DeleteJobRequest("my-second-machine-learning-job"); - // tag::delete-job-execute-async - client.machineLearning().deleteJobAsync(deleteJobRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testOpenJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("opening-my-first-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - Job secondJob = MachineLearningIT.buildJob("opening-my-second-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(secondJob), RequestOptions.DEFAULT); - - { - // tag::open-job-request - OpenJobRequest openJobRequest = new OpenJobRequest("opening-my-first-machine-learning-job"); // <1> - openJobRequest.setTimeout(TimeValue.timeValueMinutes(10)); // <2> - // end::open-job-request - - // tag::open-job-execute - OpenJobResponse openJobResponse = client.machineLearning().openJob(openJobRequest, RequestOptions.DEFAULT); - // end::open-job-execute - - // tag::open-job-response - boolean isOpened = openJobResponse.isOpened(); // <1> - String node = openJobResponse.getNode(); // <2> - // end::open-job-response - - assertThat(node, notNullValue()); - } - { - // tag::open-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(OpenJobResponse openJobResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::open-job-execute-listener - OpenJobRequest openJobRequest = new OpenJobRequest("opening-my-second-machine-learning-job"); - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::open-job-execute-async - client.machineLearning().openJobAsync(openJobRequest, RequestOptions.DEFAULT, listener); // <1> - // end::open-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testCloseJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - Job job = MachineLearningIT.buildJob("closing-my-first-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(job.getId()), RequestOptions.DEFAULT); - - // tag::close-job-request - CloseJobRequest closeJobRequest = new CloseJobRequest("closing-my-first-machine-learning-job", "otherjobs*"); // <1> - closeJobRequest.setForce(false); // <2> - closeJobRequest.setAllowNoMatch(true); // <3> - closeJobRequest.setTimeout(TimeValue.timeValueMinutes(10)); // <4> - // end::close-job-request - - // tag::close-job-execute - CloseJobResponse closeJobResponse = client.machineLearning().closeJob(closeJobRequest, RequestOptions.DEFAULT); - // end::close-job-execute - - // tag::close-job-response - boolean isClosed = closeJobResponse.isClosed(); // <1> - // end::close-job-response - - } - { - Job job = MachineLearningIT.buildJob("closing-my-second-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(job.getId()), RequestOptions.DEFAULT); - - // tag::close-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(CloseJobResponse closeJobResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::close-job-execute-listener - CloseJobRequest closeJobRequest = new CloseJobRequest("closing-my-second-machine-learning-job"); - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::close-job-execute-async - client.machineLearning().closeJobAsync(closeJobRequest, RequestOptions.DEFAULT, listener); // <1> - // end::close-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testUpdateJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - String jobId = "test-update-job"; - Job tempJob = MachineLearningIT.buildJob(jobId); - Job job = new Job.Builder(tempJob).setAnalysisConfig( - new AnalysisConfig.Builder(tempJob.getAnalysisConfig()).setCategorizationFieldName("categorization-field") - .setDetector( - 0, - new Detector.Builder().setFieldName("total") - .setFunction("sum") - .setPartitionFieldName("mlcategory") - .setDetectorDescription(randomAlphaOfLength(10)) - .build() - ) - ).build(); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - { - - List detectionRules = Arrays.asList( - new DetectionRule.Builder(Arrays.asList(RuleCondition.createTime(Operator.GT, 100L))).build() - ); - Map customSettings = new HashMap<>(); - customSettings.put("custom-setting-1", "custom-value"); - - // tag::update-job-detector-options - JobUpdate.DetectorUpdate detectorUpdate = new JobUpdate.DetectorUpdate(0, // <1> - "detector description", // <2> - detectionRules); // <3> - // end::update-job-detector-options - - // tag::update-job-options - JobUpdate update = new JobUpdate.Builder(jobId) // <1> - .setDescription("My description") // <2> - .setAnalysisLimits(new AnalysisLimits(1000L, null)) // <3> - .setBackgroundPersistInterval(TimeValue.timeValueHours(3)) // <4> - .setDetectorUpdates(Arrays.asList(detectorUpdate)) // <5> - .setGroups(Arrays.asList("job-group-1")) // <6> - .setResultsRetentionDays(10L) // <7> - .setModelPlotConfig(new ModelPlotConfig(true, null, true)) // <8> - .setModelSnapshotRetentionDays(7L) // <9> - .setCustomSettings(customSettings) // <10> - .setRenormalizationWindowDays(3L) // <11> - .build(); - // end::update-job-options - - // tag::update-job-request - UpdateJobRequest updateJobRequest = new UpdateJobRequest(update); // <1> - // end::update-job-request - - // tag::update-job-execute - PutJobResponse updateJobResponse = client.machineLearning().updateJob(updateJobRequest, RequestOptions.DEFAULT); - // end::update-job-execute - - // tag::update-job-response - Job updatedJob = updateJobResponse.getResponse(); // <1> - // end::update-job-response - - assertEquals(update.getDescription(), updatedJob.getDescription()); - } - { - // tag::update-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutJobResponse updateJobResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-job-execute-listener - UpdateJobRequest updateJobRequest = new UpdateJobRequest(new JobUpdate.Builder(jobId).build()); - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-job-execute-async - client.machineLearning().updateJobAsync(updateJobRequest, RequestOptions.DEFAULT, listener); // <1> - // end::update-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPutDatafeed() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // We need to create a job for the datafeed request to be valid - String jobId = "put-datafeed-job-1"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - String id = "datafeed-1"; - - // tag::put-datafeed-config - DatafeedConfig.Builder datafeedBuilder = new DatafeedConfig.Builder(id, jobId) // <1> - .setIndices("index_1", "index_2"); // <2> - // end::put-datafeed-config - - AggregatorFactories.Builder aggs = AggregatorFactories.builder(); - - // tag::put-datafeed-config-set-aggregations - datafeedBuilder.setAggregations(aggs); // <1> - // end::put-datafeed-config-set-aggregations - - // Clearing aggregation to avoid complex validation rules - datafeedBuilder.setAggregations((String) null); - - // tag::put-datafeed-config-set-chunking-config - datafeedBuilder.setChunkingConfig(ChunkingConfig.newAuto()); // <1> - // end::put-datafeed-config-set-chunking-config - - // tag::put-datafeed-config-set-frequency - datafeedBuilder.setFrequency(TimeValue.timeValueSeconds(30)); // <1> - // end::put-datafeed-config-set-frequency - - // tag::put-datafeed-config-set-query - datafeedBuilder.setQuery(QueryBuilders.matchAllQuery()); // <1> - // end::put-datafeed-config-set-query - - // tag::put-datafeed-config-set-query-delay - datafeedBuilder.setQueryDelay(TimeValue.timeValueMinutes(1)); // <1> - // end::put-datafeed-config-set-query-delay - - // tag::put-datafeed-config-set-delayed-data-check-config - datafeedBuilder.setDelayedDataCheckConfig(DelayedDataCheckConfig - .enabledDelayedDataCheckConfig(TimeValue.timeValueHours(1))); // <1> - // end::put-datafeed-config-set-delayed-data-check-config - - // no need to accidentally trip internal validations due to job bucket size - datafeedBuilder.setDelayedDataCheckConfig(null); - - List scriptFields = Collections.emptyList(); - // tag::put-datafeed-config-set-script-fields - datafeedBuilder.setScriptFields(scriptFields); // <1> - // end::put-datafeed-config-set-script-fields - - // tag::put-datafeed-config-set-scroll-size - datafeedBuilder.setScrollSize(1000); // <1> - // end::put-datafeed-config-set-scroll-size - - // tag::put-datafeed-config-set-runtime-mappings - Map fieldProperties = new HashMap<>(); - fieldProperties.put("type", "keyword"); - fieldProperties.put("script", "emit(params._source.agent.toLowerCase())"); - Map runtimeMappings = new HashMap<>(); - runtimeMappings.put("agent_lowercase", fieldProperties); - - datafeedBuilder.setRuntimeMappings(runtimeMappings); // <1> - // end::put-datafeed-config-set-runtime-mappings - - // tag::put-datafeed-request - PutDatafeedRequest request = new PutDatafeedRequest(datafeedBuilder.build()); // <1> - // end::put-datafeed-request - - // tag::put-datafeed-execute - PutDatafeedResponse response = client.machineLearning().putDatafeed(request, RequestOptions.DEFAULT); - // end::put-datafeed-execute - - // tag::put-datafeed-response - DatafeedConfig datafeed = response.getResponse(); // <1> - // end::put-datafeed-response - assertThat(datafeed.getId(), equalTo("datafeed-1")); - } - { - // We need to create a job for the datafeed request to be valid - String jobId = "put-datafeed-job-2"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - String id = "datafeed-2"; - - DatafeedConfig datafeed = new DatafeedConfig.Builder(id, jobId).setIndices("index_1", "index_2").build(); - - PutDatafeedRequest request = new PutDatafeedRequest(datafeed); - // tag::put-datafeed-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutDatafeedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-datafeed-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-datafeed-execute-async - client.machineLearning().putDatafeedAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-datafeed-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testUpdateDatafeed() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("update-datafeed-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - String datafeedId = job.getId() + "-feed"; - DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId()).setIndices("foo").build(); - client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT); - - { - AggregatorFactories.Builder aggs = AggregatorFactories.builder(); - List scriptFields = Collections.emptyList(); - Map runtimeMappings = Collections.emptyMap(); - // tag::update-datafeed-config - DatafeedUpdate.Builder datafeedUpdateBuilder = new DatafeedUpdate.Builder(datafeedId) // <1> - .setAggregations(aggs) // <2> - .setIndices("index_1", "index_2") // <3> - .setChunkingConfig(ChunkingConfig.newAuto()) // <4> - .setFrequency(TimeValue.timeValueSeconds(30)) // <5> - .setQuery(QueryBuilders.matchAllQuery()) // <6> - .setQueryDelay(TimeValue.timeValueMinutes(1)) // <7> - .setScriptFields(scriptFields) // <8> - .setScrollSize(1000) // <9> - .setRuntimeMappings(runtimeMappings); // <10> - // end::update-datafeed-config - - // Clearing aggregation to avoid complex validation rules - datafeedUpdateBuilder.setAggregations((String) null); - - // tag::update-datafeed-request - UpdateDatafeedRequest request = new UpdateDatafeedRequest(datafeedUpdateBuilder.build()); // <1> - // end::update-datafeed-request - - // tag::update-datafeed-execute - PutDatafeedResponse response = client.machineLearning().updateDatafeed(request, RequestOptions.DEFAULT); - // end::update-datafeed-execute - - // tag::update-datafeed-response - DatafeedConfig updatedDatafeed = response.getResponse(); // <1> - // end::update-datafeed-response - assertThat(updatedDatafeed.getId(), equalTo(datafeedId)); - } - { - DatafeedUpdate datafeedUpdate = new DatafeedUpdate.Builder(datafeedId).setIndices("index_1", "index_2").build(); - - UpdateDatafeedRequest request = new UpdateDatafeedRequest(datafeedUpdate); - // tag::update-datafeed-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutDatafeedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-datafeed-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-datafeed-execute-async - client.machineLearning().updateDatafeedAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::update-datafeed-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetDatafeed() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("get-datafeed-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - String datafeedId = job.getId() + "-feed"; - DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId()).setIndices("foo").build(); - client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT); - - { - // tag::get-datafeed-request - GetDatafeedRequest request = new GetDatafeedRequest(datafeedId); // <1> - request.setAllowNoMatch(true); // <2> - request.setExcludeGenerated(false); // <3> - // end::get-datafeed-request - - // tag::get-datafeed-execute - GetDatafeedResponse response = client.machineLearning().getDatafeed(request, RequestOptions.DEFAULT); - // end::get-datafeed-execute - - // tag::get-datafeed-response - long numberOfDatafeeds = response.count(); // <1> - List datafeeds = response.datafeeds(); // <2> - // end::get-datafeed-response - - assertEquals(1, numberOfDatafeeds); - assertEquals(1, datafeeds.size()); - } - { - GetDatafeedRequest request = new GetDatafeedRequest(datafeedId); - - // tag::get-datafeed-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetDatafeedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-datafeed-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-datafeed-execute-async - client.machineLearning().getDatafeedAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-datafeed-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteDatafeed() throws Exception { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-delete-datafeed-job"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - String datafeedId = "test-delete-datafeed"; - DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, jobId).setIndices("foo").build(); - client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT); - - { - // tag::delete-datafeed-request - DeleteDatafeedRequest deleteDatafeedRequest = new DeleteDatafeedRequest(datafeedId); - deleteDatafeedRequest.setForce(false); // <1> - // end::delete-datafeed-request - - // tag::delete-datafeed-execute - AcknowledgedResponse deleteDatafeedResponse = client.machineLearning().deleteDatafeed( - deleteDatafeedRequest, RequestOptions.DEFAULT); - // end::delete-datafeed-execute - - // tag::delete-datafeed-response - boolean isAcknowledged = deleteDatafeedResponse.isAcknowledged(); // <1> - // end::delete-datafeed-response - } - - // Recreate datafeed to allow second deletion - client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT); - - { - // tag::delete-datafeed-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse acknowledgedResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-datafeed-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - DeleteDatafeedRequest deleteDatafeedRequest = new DeleteDatafeedRequest(datafeedId); - - // tag::delete-datafeed-execute-async - client.machineLearning().deleteDatafeedAsync(deleteDatafeedRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-datafeed-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPreviewDatafeed() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("preview-datafeed-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - String datafeedId = job.getId() + "-feed"; - String indexName = "preview_data_2"; - createIndex(indexName); - DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId()).setIndices(indexName).build(); - client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT); - { - // tag::preview-datafeed-request - PreviewDatafeedRequest request = new PreviewDatafeedRequest(datafeedId); // <1> - // end::preview-datafeed-request - - // tag::preview-datafeed-execute - PreviewDatafeedResponse response = client.machineLearning().previewDatafeed(request, RequestOptions.DEFAULT); - // end::preview-datafeed-execute - - // tag::preview-datafeed-response - BytesReference rawPreview = response.getPreview(); // <1> - List> semiParsedPreview = response.getDataList(); // <2> - // end::preview-datafeed-response - - assertTrue(semiParsedPreview.isEmpty()); - } - { - PreviewDatafeedRequest request = new PreviewDatafeedRequest(datafeedId); - - // tag::preview-datafeed-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PreviewDatafeedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::preview-datafeed-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::preview-datafeed-execute-async - client.machineLearning().previewDatafeedAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::preview-datafeed-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testStartDatafeed() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("start-datafeed-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - String datafeedId = job.getId() + "-feed"; - String indexName = "start_data_2"; - createIndex(indexName); - DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId()).setIndices(indexName).build(); - client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(job.getId()), RequestOptions.DEFAULT); - { - // tag::start-datafeed-request - StartDatafeedRequest request = new StartDatafeedRequest(datafeedId); // <1> - // end::start-datafeed-request - - // tag::start-datafeed-request-options - request.setEnd("2018-08-21T00:00:00Z"); // <1> - request.setStart("2018-08-20T00:00:00Z"); // <2> - request.setTimeout(TimeValue.timeValueMinutes(10)); // <3> - // end::start-datafeed-request-options - - // tag::start-datafeed-execute - StartDatafeedResponse response = client.machineLearning().startDatafeed(request, RequestOptions.DEFAULT); - // end::start-datafeed-execute - - // tag::start-datafeed-response - boolean started = response.isStarted(); // <1> - String node = response.getNode(); // <2> - // end::start-datafeed-response - - assertTrue(started); - assertThat(node, notNullValue()); - } - { - StartDatafeedRequest request = new StartDatafeedRequest(datafeedId); - - // tag::start-datafeed-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StartDatafeedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-datafeed-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::start-datafeed-execute-async - client.machineLearning().startDatafeedAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::start-datafeed-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testStopDatafeed() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::stop-datafeed-request - StopDatafeedRequest request = new StopDatafeedRequest("datafeed_id1", "datafeed_id*"); // <1> - // end::stop-datafeed-request - request = StopDatafeedRequest.stopAllDatafeedsRequest(); - - // tag::stop-datafeed-request-options - request.setAllowNoMatch(true); // <1> - request.setForce(true); // <2> - request.setTimeout(TimeValue.timeValueMinutes(10)); // <3> - // end::stop-datafeed-request-options - - // tag::stop-datafeed-execute - StopDatafeedResponse response = client.machineLearning().stopDatafeed(request, RequestOptions.DEFAULT); - // end::stop-datafeed-execute - // tag::stop-datafeed-response - boolean stopped = response.isStopped(); // <1> - // end::stop-datafeed-response - - assertTrue(stopped); - } - { - StopDatafeedRequest request = StopDatafeedRequest.stopAllDatafeedsRequest(); - - // tag::stop-datafeed-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StopDatafeedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::stop-datafeed-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::stop-datafeed-execute-async - client.machineLearning().stopDatafeedAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::stop-datafeed-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetDatafeedStats() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("get-machine-learning-datafeed-stats1"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - Job secondJob = MachineLearningIT.buildJob("get-machine-learning-datafeed-stats2"); - client.machineLearning().putJob(new PutJobRequest(secondJob), RequestOptions.DEFAULT); - String datafeedId1 = job.getId() + "-feed"; - String indexName = "datafeed_stats_data_2"; - createIndex(indexName); - DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId1, job.getId()).setIndices(indexName).build(); - client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT); - - String datafeedId2 = secondJob.getId() + "-feed"; - DatafeedConfig secondDatafeed = DatafeedConfig.builder(datafeedId2, secondJob.getId()).setIndices(indexName).build(); - client.machineLearning().putDatafeed(new PutDatafeedRequest(secondDatafeed), RequestOptions.DEFAULT); - - { - //tag::get-datafeed-stats-request - GetDatafeedStatsRequest request = - new GetDatafeedStatsRequest("get-machine-learning-datafeed-stats1-feed", "get-machine-learning-datafeed*"); // <1> - request.setAllowNoMatch(true); // <2> - //end::get-datafeed-stats-request - - //tag::get-datafeed-stats-execute - GetDatafeedStatsResponse response = client.machineLearning().getDatafeedStats(request, RequestOptions.DEFAULT); - //end::get-datafeed-stats-execute - - //tag::get-datafeed-stats-response - long numberOfDatafeedStats = response.count(); // <1> - List datafeedStats = response.datafeedStats(); // <2> - //end::get-datafeed-stats-response - - assertEquals(2, response.count()); - assertThat(response.datafeedStats(), hasSize(2)); - assertThat( - response.datafeedStats().stream().map(DatafeedStats::getDatafeedId).collect(Collectors.toList()), - containsInAnyOrder(datafeed.getId(), secondDatafeed.getId()) - ); - } - { - GetDatafeedStatsRequest request = new GetDatafeedStatsRequest("*"); - - // tag::get-datafeed-stats-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetDatafeedStatsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-datafeed-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-datafeed-stats-execute-async - client.machineLearning().getDatafeedStatsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-datafeed-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetBuckets() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-get-buckets"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a bucket - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "test-get-buckets", - "result_type": "bucket", - "timestamp": 1533081600000, - "bucket_span": 600, - "is_interim": false, - "anomaly_score": 80 - }""", XContentType.JSON); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::get-buckets-request - GetBucketsRequest request = new GetBucketsRequest(jobId); // <1> - // end::get-buckets-request - - // tag::get-buckets-timestamp - request.setTimestamp("2018-08-17T00:00:00Z"); // <1> - // end::get-buckets-timestamp - - // Set timestamp to null as it is incompatible with other args - request.setTimestamp(null); - - // tag::get-buckets-anomaly-score - request.setAnomalyScore(75.0); // <1> - // end::get-buckets-anomaly-score - - // tag::get-buckets-desc - request.setDescending(true); // <1> - // end::get-buckets-desc - - // tag::get-buckets-end - request.setEnd("2018-08-21T00:00:00Z"); // <1> - // end::get-buckets-end - - // tag::get-buckets-exclude-interim - request.setExcludeInterim(true); // <1> - // end::get-buckets-exclude-interim - - // tag::get-buckets-expand - request.setExpand(true); // <1> - // end::get-buckets-expand - - // tag::get-buckets-page - request.setPageParams(new PageParams(100, 200)); // <1> - // end::get-buckets-page - - // Set page params back to null so the response contains the bucket we indexed - request.setPageParams(null); - - // tag::get-buckets-sort - request.setSort("anomaly_score"); // <1> - // end::get-buckets-sort - - // tag::get-buckets-start - request.setStart("2018-08-01T00:00:00Z"); // <1> - // end::get-buckets-start - - // tag::get-buckets-execute - GetBucketsResponse response = client.machineLearning().getBuckets(request, RequestOptions.DEFAULT); - // end::get-buckets-execute - - // tag::get-buckets-response - long count = response.count(); // <1> - List buckets = response.buckets(); // <2> - // end::get-buckets-response - assertEquals(1, buckets.size()); - } - { - GetBucketsRequest request = new GetBucketsRequest(jobId); - - // tag::get-buckets-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetBucketsResponse getBucketsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-buckets-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-buckets-execute-async - client.machineLearning().getBucketsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-buckets-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testFlushJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("flushing-my-first-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(job.getId()), RequestOptions.DEFAULT); - - Job secondJob = MachineLearningIT.buildJob("flushing-my-second-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(secondJob), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(secondJob.getId()), RequestOptions.DEFAULT); - - { - // tag::flush-job-request - FlushJobRequest flushJobRequest = new FlushJobRequest("flushing-my-first-machine-learning-job"); // <1> - // end::flush-job-request - - // tag::flush-job-request-options - flushJobRequest.setCalcInterim(true); // <1> - flushJobRequest.setAdvanceTime("2018-08-31T16:35:07+00:00"); // <2> - flushJobRequest.setStart("2018-08-31T16:35:17+00:00"); // <3> - flushJobRequest.setEnd("2018-08-31T16:35:27+00:00"); // <4> - flushJobRequest.setSkipTime("2018-08-31T16:35:00+00:00"); // <5> - // end::flush-job-request-options - - // tag::flush-job-execute - FlushJobResponse flushJobResponse = client.machineLearning().flushJob(flushJobRequest, RequestOptions.DEFAULT); - // end::flush-job-execute - - // tag::flush-job-response - boolean isFlushed = flushJobResponse.isFlushed(); // <1> - Date lastFinalizedBucketEnd = flushJobResponse.getLastFinalizedBucketEnd(); // <2> - // end::flush-job-response - - } - { - // tag::flush-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(FlushJobResponse FlushJobResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::flush-job-execute-listener - FlushJobRequest flushJobRequest = new FlushJobRequest("flushing-my-second-machine-learning-job"); - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::flush-job-execute-async - client.machineLearning().flushJobAsync(flushJobRequest, RequestOptions.DEFAULT, listener); // <1> - // end::flush-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteForecast() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("deleting-forecast-for-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(job.getId()), RequestOptions.DEFAULT); - PostDataRequest.JsonBuilder builder = new PostDataRequest.JsonBuilder(); - for (int i = 0; i < 30; i++) { - Map hashMap = new HashMap<>(); - hashMap.put("total", randomInt(1000)); - hashMap.put("timestamp", (i + 1) * 1000); - builder.addDoc(hashMap); - } - - PostDataRequest postDataRequest = new PostDataRequest(job.getId(), builder); - // Post data is deprecated, so expect a deprecation warning - client.machineLearning().postData(postDataRequest, POST_DATA_OPTIONS); - client.machineLearning().flushJob(new FlushJobRequest(job.getId()), RequestOptions.DEFAULT); - - ForecastJobResponse forecastJobResponse = client.machineLearning() - .forecastJob(new ForecastJobRequest(job.getId()), RequestOptions.DEFAULT); - String forecastId = forecastJobResponse.getForecastId(); - - GetRequest request = new GetRequest(".ml-anomalies-" + job.getId()); - request.id(job.getId() + "_model_forecast_request_stats_" + forecastId); - assertBusy(() -> { - GetResponse getResponse = highLevelClient().get(request, RequestOptions.DEFAULT); - assertTrue(getResponse.isExists()); - assertTrue(getResponse.getSourceAsString().contains("finished")); - }, 30, TimeUnit.SECONDS); - - { - // tag::delete-forecast-request - DeleteForecastRequest deleteForecastRequest = new DeleteForecastRequest("deleting-forecast-for-job"); // <1> - // end::delete-forecast-request - - // tag::delete-forecast-request-options - deleteForecastRequest.setForecastIds(forecastId); // <1> - deleteForecastRequest.timeout("30s"); // <2> - deleteForecastRequest.setAllowNoForecasts(true); // <3> - // end::delete-forecast-request-options - - // tag::delete-forecast-execute - AcknowledgedResponse deleteForecastResponse = client.machineLearning().deleteForecast(deleteForecastRequest, - RequestOptions.DEFAULT); - // end::delete-forecast-execute - - // tag::delete-forecast-response - boolean isAcknowledged = deleteForecastResponse.isAcknowledged(); // <1> - // end::delete-forecast-response - } - { - // tag::delete-forecast-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse DeleteForecastResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-forecast-execute-listener - DeleteForecastRequest deleteForecastRequest = DeleteForecastRequest.deleteAllForecasts(job.getId()); - deleteForecastRequest.setAllowNoForecasts(true); - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-forecast-execute-async - client.machineLearning().deleteForecastAsync(deleteForecastRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-forecast-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetJobStats() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("get-machine-learning-job-stats1"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - Job secondJob = MachineLearningIT.buildJob("get-machine-learning-job-stats2"); - client.machineLearning().putJob(new PutJobRequest(secondJob), RequestOptions.DEFAULT); - - { - // tag::get-job-stats-request - GetJobStatsRequest request = new GetJobStatsRequest("get-machine-learning-job-stats1", "get-machine-learning-job-*"); // <1> - request.setAllowNoMatch(true); // <2> - // end::get-job-stats-request - - // tag::get-job-stats-execute - GetJobStatsResponse response = client.machineLearning().getJobStats(request, RequestOptions.DEFAULT); - // end::get-job-stats-execute - - // tag::get-job-stats-response - long numberOfJobStats = response.count(); // <1> - List jobStats = response.jobStats(); // <2> - // end::get-job-stats-response - - assertEquals(2, response.count()); - assertThat(response.jobStats(), hasSize(2)); - assertThat( - response.jobStats().stream().map(JobStats::getJobId).collect(Collectors.toList()), - containsInAnyOrder(job.getId(), secondJob.getId()) - ); - } - { - GetJobStatsRequest request = new GetJobStatsRequest("get-machine-learning-job-stats1", "get-machine-learning-job-*"); - - // tag::get-job-stats-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetJobStatsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-job-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-job-stats-execute-async - client.machineLearning().getJobStatsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-job-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testForecastJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("forecasting-my-first-machine-learning-job"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(job.getId()), RequestOptions.DEFAULT); - - PostDataRequest.JsonBuilder builder = new PostDataRequest.JsonBuilder(); - for (int i = 0; i < 30; i++) { - Map hashMap = new HashMap<>(); - hashMap.put("total", randomInt(1000)); - hashMap.put("timestamp", (i + 1) * 1000); - builder.addDoc(hashMap); - } - PostDataRequest postDataRequest = new PostDataRequest(job.getId(), builder); - // Post data is deprecated, so expect a deprecation warning - client.machineLearning().postData(postDataRequest, POST_DATA_OPTIONS); - client.machineLearning().flushJob(new FlushJobRequest(job.getId()), RequestOptions.DEFAULT); - - { - // tag::forecast-job-request - ForecastJobRequest forecastJobRequest = new ForecastJobRequest("forecasting-my-first-machine-learning-job"); // <1> - // end::forecast-job-request - - // tag::forecast-job-request-options - forecastJobRequest.setExpiresIn(TimeValue.timeValueHours(48)); // <1> - forecastJobRequest.setDuration(TimeValue.timeValueHours(24)); // <2> - forecastJobRequest.setMaxModelMemory(new ByteSizeValue(30, ByteSizeUnit.MB)); // <3> - // end::forecast-job-request-options - - // tag::forecast-job-execute - ForecastJobResponse forecastJobResponse = client.machineLearning().forecastJob(forecastJobRequest, RequestOptions.DEFAULT); - // end::forecast-job-execute - - // tag::forecast-job-response - boolean isAcknowledged = forecastJobResponse.isAcknowledged(); // <1> - String forecastId = forecastJobResponse.getForecastId(); // <2> - // end::forecast-job-response - assertTrue(isAcknowledged); - assertNotNull(forecastId); - } - { - // tag::forecast-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ForecastJobResponse forecastJobResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::forecast-job-execute-listener - ForecastJobRequest forecastJobRequest = new ForecastJobRequest("forecasting-my-first-machine-learning-job"); - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::forecast-job-execute-async - client.machineLearning().forecastJobAsync(forecastJobRequest, RequestOptions.DEFAULT, listener); // <1> - // end::forecast-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetOverallBuckets() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId1 = "test-get-overall-buckets-1"; - String jobId2 = "test-get-overall-buckets-2"; - Job job1 = MachineLearningGetResultsIT.buildJob(jobId1); - Job job2 = MachineLearningGetResultsIT.buildJob(jobId2); - client.machineLearning().putJob(new PutJobRequest(job1), RequestOptions.DEFAULT); - client.machineLearning().putJob(new PutJobRequest(job2), RequestOptions.DEFAULT); - - // Let us index some buckets - BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - - { - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.source(""" - { - "job_id": "test-get-overall-buckets-1", - "result_type": "bucket", - "timestamp": 1533081600000, - "bucket_span": 600, - "is_interim": false, - "anomaly_score": 60 - }""", XContentType.JSON); - bulkRequest.add(indexRequest); - } - { - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.source(""" - { - "job_id": "test-get-overall-buckets-2", - "result_type": "bucket", - "timestamp": 1533081600000, - "bucket_span": 3600, - "is_interim": false, - "anomaly_score": 100 - }""", XContentType.JSON); - bulkRequest.add(indexRequest); - } - - client.bulk(bulkRequest, RequestOptions.DEFAULT); - - { - // tag::get-overall-buckets-request - GetOverallBucketsRequest request = new GetOverallBucketsRequest(jobId1, jobId2); // <1> - // end::get-overall-buckets-request - - // tag::get-overall-buckets-bucket-span - request.setBucketSpan(TimeValue.timeValueHours(24)); // <1> - // end::get-overall-buckets-bucket-span - - // tag::get-overall-buckets-end - request.setEnd("2018-08-21T00:00:00Z"); // <1> - // end::get-overall-buckets-end - - // tag::get-overall-buckets-exclude-interim - request.setExcludeInterim(true); // <1> - // end::get-overall-buckets-exclude-interim - - // tag::get-overall-buckets-overall-score - request.setOverallScore(75.0); // <1> - // end::get-overall-buckets-overall-score - - // tag::get-overall-buckets-start - request.setStart("2018-08-01T00:00:00Z"); // <1> - // end::get-overall-buckets-start - - // tag::get-overall-buckets-top-n - request.setTopN(2); // <1> - // end::get-overall-buckets-top-n - - // tag::get-overall-buckets-execute - GetOverallBucketsResponse response = client.machineLearning().getOverallBuckets(request, RequestOptions.DEFAULT); - // end::get-overall-buckets-execute - - // tag::get-overall-buckets-response - long count = response.count(); // <1> - List overallBuckets = response.overallBuckets(); // <2> - // end::get-overall-buckets-response - - assertEquals(1, overallBuckets.size()); - assertThat(overallBuckets.get(0).getOverallScore(), is(closeTo(80.0, 0.001))); - - } - { - GetOverallBucketsRequest request = new GetOverallBucketsRequest(jobId1, jobId2); - - // tag::get-overall-buckets-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetOverallBucketsResponse getOverallBucketsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-overall-buckets-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-overall-buckets-execute-async - client.machineLearning().getOverallBucketsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-overall-buckets-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetRecords() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-get-records"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a record - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "test-get-records", - "result_type": "record", - "timestamp": 1533081600000, - "bucket_span": 600, - "is_interim": false, - "record_score": 80 - }""", XContentType.JSON); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::get-records-request - GetRecordsRequest request = new GetRecordsRequest(jobId); // <1> - // end::get-records-request - - // tag::get-records-desc - request.setDescending(true); // <1> - // end::get-records-desc - - // tag::get-records-end - request.setEnd("2018-08-21T00:00:00Z"); // <1> - // end::get-records-end - - // tag::get-records-exclude-interim - request.setExcludeInterim(true); // <1> - // end::get-records-exclude-interim - - // tag::get-records-page - request.setPageParams(new PageParams(100, 200)); // <1> - // end::get-records-page - - // Set page params back to null so the response contains the record we indexed - request.setPageParams(null); - - // tag::get-records-record-score - request.setRecordScore(75.0); // <1> - // end::get-records-record-score - - // tag::get-records-sort - request.setSort("probability"); // <1> - // end::get-records-sort - - // tag::get-records-start - request.setStart("2018-08-01T00:00:00Z"); // <1> - // end::get-records-start - - // tag::get-records-execute - GetRecordsResponse response = client.machineLearning().getRecords(request, RequestOptions.DEFAULT); - // end::get-records-execute - - // tag::get-records-response - long count = response.count(); // <1> - List records = response.records(); // <2> - // end::get-records-response - assertEquals(1, records.size()); - } - { - GetRecordsRequest request = new GetRecordsRequest(jobId); - - // tag::get-records-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetRecordsResponse getRecordsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-records-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-records-execute-async - client.machineLearning().getRecordsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-records-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPostData() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Job job = MachineLearningIT.buildJob("test-post-data"); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - client.machineLearning().openJob(new OpenJobRequest(job.getId()), RequestOptions.DEFAULT); - - { - // tag::post-data-request - PostDataRequest.JsonBuilder jsonBuilder = new PostDataRequest.JsonBuilder(); // <1> - Map mapData = new HashMap<>(); - mapData.put("total", 109); - jsonBuilder.addDoc(mapData); // <2> - jsonBuilder.addDoc("{\"total\":1000}"); // <3> - PostDataRequest postDataRequest = new PostDataRequest("test-post-data", jsonBuilder); // <4> - // end::post-data-request - - // tag::post-data-request-options - postDataRequest.setResetStart("2018-08-31T16:35:07+00:00"); // <1> - postDataRequest.setResetEnd("2018-08-31T16:35:17+00:00"); // <2> - // end::post-data-request-options - postDataRequest.setResetEnd(null); - postDataRequest.setResetStart(null); - - // Post data is deprecated, so expect a deprecation warning - PostDataResponse postDataResponse = client.machineLearning().postData(postDataRequest, POST_DATA_OPTIONS); - // The end user can use the default options without it being a fatal error (this is only in the test framework) - /* - // tag::post-data-execute - PostDataResponse postDataResponse = client.machineLearning().postData(postDataRequest, RequestOptions.DEFAULT); - // end::post-data-execute - */ - - // tag::post-data-response - DataCounts dataCounts = postDataResponse.getDataCounts(); // <1> - // end::post-data-response - assertEquals(2, dataCounts.getInputRecordCount()); - - } - { - // tag::post-data-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PostDataResponse postDataResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::post-data-execute-listener - PostDataRequest.JsonBuilder jsonBuilder = new PostDataRequest.JsonBuilder(); - Map mapData = new HashMap<>(); - mapData.put("total", 109); - jsonBuilder.addDoc(mapData); - PostDataRequest postDataRequest = new PostDataRequest("test-post-data", jsonBuilder); // <1> - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // Post data is deprecated, so expect a deprecation warning - client.machineLearning().postDataAsync(postDataRequest, POST_DATA_OPTIONS, listener); - // The end user can use the default options without it being a fatal error (this is only in the test framework) - /* - // tag::post-data-execute-async - client.machineLearning().postDataAsync(postDataRequest, RequestOptions.DEFAULT, listener); // <1> - // end::post-data-execute-async - */ - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetInfluencers() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-get-influencers"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a record - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "test-get-influencers", - "result_type": "influencer", - "timestamp": 1533081600000, - "bucket_span": 600, - "is_interim": false, - "influencer_score": 80, - "influencer_field_name": "my_influencer", - "influencer_field_value": "foo" - }""", XContentType.JSON); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::get-influencers-request - GetInfluencersRequest request = new GetInfluencersRequest(jobId); // <1> - // end::get-influencers-request - - // tag::get-influencers-desc - request.setDescending(true); // <1> - // end::get-influencers-desc - - // tag::get-influencers-end - request.setEnd("2018-08-21T00:00:00Z"); // <1> - // end::get-influencers-end - - // tag::get-influencers-exclude-interim - request.setExcludeInterim(true); // <1> - // end::get-influencers-exclude-interim - - // tag::get-influencers-influencer-score - request.setInfluencerScore(75.0); // <1> - // end::get-influencers-influencer-score - - // tag::get-influencers-page - request.setPageParams(new PageParams(100, 200)); // <1> - // end::get-influencers-page - - // Set page params back to null so the response contains the influencer we indexed - request.setPageParams(null); - - // tag::get-influencers-sort - request.setSort("probability"); // <1> - // end::get-influencers-sort - - // tag::get-influencers-start - request.setStart("2018-08-01T00:00:00Z"); // <1> - // end::get-influencers-start - - // tag::get-influencers-execute - GetInfluencersResponse response = client.machineLearning().getInfluencers(request, RequestOptions.DEFAULT); - // end::get-influencers-execute - - // tag::get-influencers-response - long count = response.count(); // <1> - List influencers = response.influencers(); // <2> - // end::get-influencers-response - assertEquals(1, influencers.size()); - } - { - GetInfluencersRequest request = new GetInfluencersRequest(jobId); - - // tag::get-influencers-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetInfluencersResponse getInfluencersResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-influencers-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-influencers-execute-async - client.machineLearning().getInfluencersAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-influencers-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetCategories() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-get-categories"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a category - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source( - "{\"job_id\": \"test-get-categories\", \"category_id\": 1, \"terms\": \"AAL\"," - + " \"regex\": \".*?AAL.*\", \"max_matching_length\": 3, \"examples\": [\"AAL\"]}", - XContentType.JSON - ); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::get-categories-request - GetCategoriesRequest request = new GetCategoriesRequest(jobId); // <1> - // end::get-categories-request - - // tag::get-categories-category-id - request.setCategoryId(1L); // <1> - // end::get-categories-category-id - - // tag::get-categories-page - request.setPageParams(new PageParams(100, 200)); // <1> - // end::get-categories-page - - // Set page params back to null so the response contains the category we indexed - request.setPageParams(null); - - // tag::get-categories-execute - GetCategoriesResponse response = client.machineLearning().getCategories(request, RequestOptions.DEFAULT); - // end::get-categories-execute - - // tag::get-categories-response - long count = response.count(); // <1> - List categories = response.categories(); // <2> - // end::get-categories-response - assertEquals(1, categories.size()); - } - { - GetCategoriesRequest request = new GetCategoriesRequest(jobId); - - // tag::get-categories-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetCategoriesResponse getcategoriesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-categories-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-categories-execute-async - client.machineLearning().getCategoriesAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-categories-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteExpiredData() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-delete-expired-data"; - MachineLearningIT.buildJob(jobId); - { - // tag::delete-expired-data-request - DeleteExpiredDataRequest request = new DeleteExpiredDataRequest( // <1> - null, // <2> - 1000.0f, // <3> - TimeValue.timeValueHours(12) // <4> - ); - - // end::delete-expired-data-request - - // tag::delete-expired-data-execute - DeleteExpiredDataResponse response = client.machineLearning().deleteExpiredData(request, RequestOptions.DEFAULT); - // end::delete-expired-data-execute - - // tag::delete-expired-data-response - boolean deleted = response.getDeleted(); // <1> - // end::delete-expired-data-response - - assertTrue(deleted); - } - { - // tag::delete-expired-data-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(DeleteExpiredDataResponse deleteExpiredDataResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-expired-data-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - DeleteExpiredDataRequest deleteExpiredDataRequest = new DeleteExpiredDataRequest(); - - // tag::delete-expired-data-execute-async - client.machineLearning().deleteExpiredDataAsync(deleteExpiredDataRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-expired-data-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteModelSnapshot() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-delete-model-snapshot"; - String snapshotId = "1541587919"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a snapshot - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "%s", - "timestamp": 1541587919000, - "description": "State persisted due to job close at 2018-11-07T10:51:59+0000", - "snapshot_id": "%s", - "snapshot_doc_count": 1, - "model_size_stats": { - "job_id": "%s", - "result_type": "model_size_stats", - "model_bytes": 51722, - "total_by_field_count": 3, - "total_over_field_count": 0, - "total_partition_field_count": 2, - "bucket_allocation_failures_count": 0, - "memory_status": "ok", - "log_time": 1541587919000, - "timestamp": 1519930800000 - }, - "latest_record_time_stamp": 1519931700000, - "latest_result_time_stamp": 1519930800000, - "retain": false - }""".formatted(jobId, snapshotId, jobId), XContentType.JSON); - { - client.index(indexRequest, RequestOptions.DEFAULT); - - // tag::delete-model-snapshot-request - DeleteModelSnapshotRequest request = new DeleteModelSnapshotRequest(jobId, snapshotId); // <1> - // end::delete-model-snapshot-request - - // tag::delete-model-snapshot-execute - AcknowledgedResponse response = client.machineLearning().deleteModelSnapshot(request, RequestOptions.DEFAULT); - // end::delete-model-snapshot-execute - - // tag::delete-model-snapshot-response - boolean isAcknowledged = response.isAcknowledged(); // <1> - // end::delete-model-snapshot-response - - assertTrue(isAcknowledged); - } - { - client.index(indexRequest, RequestOptions.DEFAULT); - - // tag::delete-model-snapshot-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse acknowledgedResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-model-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - DeleteModelSnapshotRequest deleteModelSnapshotRequest = new DeleteModelSnapshotRequest(jobId, "1541587919"); - - // tag::delete-model-snapshot-execute-async - client.machineLearning().deleteModelSnapshotAsync(deleteModelSnapshotRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-model-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetModelSnapshots() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-get-model-snapshots"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a snapshot - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "test-get-model-snapshots", - "timestamp": 1541587919000, - "description": "State persisted due to job close at 2018-11-07T10:51:59+0000", - "snapshot_id": "1541587919", - "snapshot_doc_count": 1, - "model_size_stats": { - "job_id": "test-get-model-snapshots", - "result_type": "model_size_stats", - "model_bytes": 51722, - "total_by_field_count": 3, - "total_over_field_count": 0, - "total_partition_field_count": 2, - "bucket_allocation_failures_count": 0, - "memory_status": "ok", - "log_time": 1541587919000, - "timestamp": 1519930800000 - }, - "latest_record_time_stamp": 1519931700000, - "latest_result_time_stamp": 1519930800000, - "retain": false - }""", XContentType.JSON); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::get-model-snapshots-request - GetModelSnapshotsRequest request = new GetModelSnapshotsRequest(jobId); // <1> - // end::get-model-snapshots-request - - // tag::get-model-snapshots-snapshot-id - request.setSnapshotId("1541587919"); // <1> - // end::get-model-snapshots-snapshot-id - - // Set snapshot id to null as it is incompatible with other args - request.setSnapshotId(null); - - // tag::get-model-snapshots-desc - request.setDesc(true); // <1> - // end::get-model-snapshots-desc - - // tag::get-model-snapshots-end - request.setEnd("2018-11-07T21:00:00Z"); // <1> - // end::get-model-snapshots-end - - // tag::get-model-snapshots-page - request.setPageParams(new PageParams(100, 200)); // <1> - // end::get-model-snapshots-page - - // Set page params back to null so the response contains the snapshot we indexed - request.setPageParams(null); - - // tag::get-model-snapshots-sort - request.setSort("latest_result_time_stamp"); // <1> - // end::get-model-snapshots-sort - - // tag::get-model-snapshots-start - request.setStart("2018-11-07T00:00:00Z"); // <1> - // end::get-model-snapshots-start - - // tag::get-model-snapshots-execute - GetModelSnapshotsResponse response = client.machineLearning().getModelSnapshots(request, RequestOptions.DEFAULT); - // end::get-model-snapshots-execute - - // tag::get-model-snapshots-response - long count = response.count(); // <1> - List modelSnapshots = response.snapshots(); // <2> - // end::get-model-snapshots-response - - assertEquals(1, modelSnapshots.size()); - } - { - GetModelSnapshotsRequest request = new GetModelSnapshotsRequest(jobId); - - // tag::get-model-snapshots-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetModelSnapshotsResponse getModelSnapshotsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-model-snapshots-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-model-snapshots-execute-async - client.machineLearning().getModelSnapshotsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-model-snapshots-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testRevertModelSnapshot() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-revert-model-snapshot"; - String snapshotId = "1541587919"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a snapshot - String documentId = jobId + "_model_snapshot_" + snapshotId; - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared").id(documentId); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "test-revert-model-snapshot", - "timestamp": 1541587919000, - "description": "State persisted due to job close at 2018-11-07T10:51:59+0000", - "snapshot_id": "1541587919", - "snapshot_doc_count": 1, - "model_size_stats": { - "job_id": "test-revert-model-snapshot", - "result_type": "model_size_stats", - "model_bytes": 51722, - "total_by_field_count": 3, - "total_over_field_count": 0, - "total_partition_field_count": 2, - "bucket_allocation_failures_count": 0, - "memory_status": "ok", - "log_time": 1541587919000, - "timestamp": 1519930800000 - }, - "latest_record_time_stamp": 1519931700000, - "latest_result_time_stamp": 1519930800000, - "retain": false, - "quantiles": { - "job_id": "test-revert-model-snapshot", - "timestamp": 1541587919000, - "quantile_state": "state" - } - }""", XContentType.JSON); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::revert-model-snapshot-request - RevertModelSnapshotRequest request = new RevertModelSnapshotRequest(jobId, snapshotId); // <1> - // end::revert-model-snapshot-request - - // tag::revert-model-snapshot-delete-intervening-results - request.setDeleteInterveningResults(true); // <1> - // end::revert-model-snapshot-delete-intervening-results - - // tag::revert-model-snapshot-execute - RevertModelSnapshotResponse response = client.machineLearning().revertModelSnapshot(request, RequestOptions.DEFAULT); - // end::revert-model-snapshot-execute - - // tag::revert-model-snapshot-response - ModelSnapshot modelSnapshot = response.getModel(); // <1> - // end::revert-model-snapshot-response - - assertEquals(snapshotId, modelSnapshot.getSnapshotId()); - assertEquals("State persisted due to job close at 2018-11-07T10:51:59+0000", modelSnapshot.getDescription()); - assertEquals(51722, modelSnapshot.getModelSizeStats().getModelBytes()); - } - { - RevertModelSnapshotRequest request = new RevertModelSnapshotRequest(jobId, snapshotId); - - // tag::revert-model-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(RevertModelSnapshotResponse revertModelSnapshotResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::revert-model-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::revert-model-snapshot-execute-async - client.machineLearning().revertModelSnapshotAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::revert-model-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testUpgradeJobSnapshot() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-upgrade-job-model-snapshot"; - String snapshotId = "1541587919"; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a snapshot - String documentId = jobId + "_model_snapshot_" + snapshotId; - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared").id(documentId); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "test-upgrade-job-model-snapshot", - "timestamp": 1541587919000, - "description": "State persisted due to job close at 2018-11-07T10:51:59+0000", - "snapshot_id": "1541587919", - "snapshot_doc_count": 1, - "model_size_stats": { - "job_id": "test-revert-model-snapshot", - "result_type": "model_size_stats", - "model_bytes": 51722, - "total_by_field_count": 3, - "total_over_field_count": 0, - "total_partition_field_count": 2, - "bucket_allocation_failures_count": 0, - "memory_status": "ok", - "log_time": 1541587919000, - "timestamp": 1519930800000 - }, - "latest_record_time_stamp": 1519931700000, - "latest_result_time_stamp": 1519930800000, - "retain": false, - "quantiles": { - "job_id": "test-revert-model-snapshot", - "timestamp": 1541587919000, - "quantile_state": "state" - } - }""", XContentType.JSON); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::upgrade-job-model-snapshot-request - UpgradeJobModelSnapshotRequest request = new UpgradeJobModelSnapshotRequest( - jobId, // <1> - snapshotId, // <2> - TimeValue.timeValueMinutes(30), // <3> - true); // <4> - // end::upgrade-job-model-snapshot-request - - try { - // tag::upgrade-job-model-snapshot-execute - UpgradeJobModelSnapshotResponse response = client.machineLearning().upgradeJobSnapshot(request, RequestOptions.DEFAULT); - // end::upgrade-job-model-snapshot-execute - fail("upgrade model snapshot should not have succeeded."); - } catch (ElasticsearchException ex) { - assertThat(ex.getMessage(), containsString("Unexpected state [failed] while waiting for to be assigned to a node")); - } - UpgradeJobModelSnapshotResponse response = new UpgradeJobModelSnapshotResponse(true, ""); - - // tag::upgrade-job-model-snapshot-response - boolean completed = response.isCompleted(); // <1> - String node = response.getNode(); // <2> - // end::upgrade-job-model-snapshot-response - } - { - UpgradeJobModelSnapshotRequest request = new UpgradeJobModelSnapshotRequest(jobId, snapshotId, null, true); - - // tag::upgrade-job-model-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(UpgradeJobModelSnapshotResponse revertModelSnapshotResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::upgrade-job-model-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::upgrade-job-model-snapshot-execute-async - client.machineLearning().upgradeJobSnapshotAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::upgrade-job-model-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testUpdateModelSnapshot() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - String jobId = "test-update-model-snapshot"; - String snapshotId = "1541587919"; - String documentId = jobId + "_model_snapshot_" + snapshotId; - Job job = MachineLearningIT.buildJob(jobId); - client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT); - - // Let us index a snapshot - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared").id(documentId); - indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - indexRequest.source(""" - { - "job_id": "test-update-model-snapshot", - "timestamp": 1541587919000, - "description": "State persisted due to job close at 2018-11-07T10:51:59+0000", - "snapshot_id": "1541587919", - "snapshot_doc_count": 1, - "model_size_stats": { - "job_id": "test-update-model-snapshot", - "result_type": "model_size_stats", - "model_bytes": 51722, - "total_by_field_count": 3, - "total_over_field_count": 0, - "total_partition_field_count": 2, - "bucket_allocation_failures_count": 0, - "memory_status": "ok", - "log_time": 1541587919000, - "timestamp": 1519930800000 - }, - "latest_record_time_stamp": 1519931700000, - "latest_result_time_stamp": 1519930800000, - "retain": false - }""", XContentType.JSON); - client.index(indexRequest, RequestOptions.DEFAULT); - - { - // tag::update-model-snapshot-request - UpdateModelSnapshotRequest request = new UpdateModelSnapshotRequest(jobId, snapshotId); // <1> - // end::update-model-snapshot-request - - // tag::update-model-snapshot-description - request.setDescription("My Snapshot"); // <1> - // end::update-model-snapshot-description - - // tag::update-model-snapshot-retain - request.setRetain(true); // <1> - // end::update-model-snapshot-retain - - // tag::update-model-snapshot-execute - UpdateModelSnapshotResponse response = client.machineLearning().updateModelSnapshot(request, RequestOptions.DEFAULT); - // end::update-model-snapshot-execute - - // tag::update-model-snapshot-response - boolean acknowledged = response.getAcknowledged(); // <1> - ModelSnapshot modelSnapshot = response.getModel(); // <2> - // end::update-model-snapshot-response - - assertTrue(acknowledged); - assertEquals("My Snapshot", modelSnapshot.getDescription()); - } - { - UpdateModelSnapshotRequest request = new UpdateModelSnapshotRequest(jobId, snapshotId); - - // tag::update-model-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(UpdateModelSnapshotResponse updateModelSnapshotResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-model-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-model-snapshot-execute-async - client.machineLearning().updateModelSnapshotAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::update-model-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPutCalendar() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - // tag::put-calendar-request - Calendar calendar = new Calendar("public_holidays", Collections.singletonList("job_1"), "A calendar for public holidays"); - PutCalendarRequest request = new PutCalendarRequest(calendar); // <1> - // end::put-calendar-request - - // tag::put-calendar-execute - PutCalendarResponse response = client.machineLearning().putCalendar(request, RequestOptions.DEFAULT); - // end::put-calendar-execute - - // tag::put-calendar-response - Calendar newCalendar = response.getCalendar(); // <1> - // end::put-calendar-response - assertThat(newCalendar.getId(), equalTo("public_holidays")); - - // tag::put-calendar-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutCalendarResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-calendar-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-calendar-execute-async - client.machineLearning().putCalendarAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-calendar-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testPutCalendarJob() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - Calendar calendar = new Calendar("holidays", Collections.singletonList("job_1"), "A calendar for public holidays"); - PutCalendarRequest putRequest = new PutCalendarRequest(calendar); - client.machineLearning().putCalendar(putRequest, RequestOptions.DEFAULT); - { - // tag::put-calendar-job-request - PutCalendarJobRequest request = new PutCalendarJobRequest("holidays", // <1> - "job_2", "job_group_1"); // <2> - // end::put-calendar-job-request - - // tag::put-calendar-job-execute - PutCalendarResponse response = client.machineLearning().putCalendarJob(request, RequestOptions.DEFAULT); - // end::put-calendar-job-execute - - // tag::put-calendar-job-response - Calendar updatedCalendar = response.getCalendar(); // <1> - // end::put-calendar-job-response - - assertThat(updatedCalendar.getJobIds(), containsInAnyOrder("job_1", "job_2", "job_group_1")); - } - { - PutCalendarJobRequest request = new PutCalendarJobRequest("holidays", "job_4"); - - // tag::put-calendar-job-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(PutCalendarResponse putCalendarsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-calendar-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-calendar-job-execute-async - client.machineLearning().putCalendarJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-calendar-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteCalendarJob() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - Calendar calendar = new Calendar("holidays", Arrays.asList("job_1", "job_group_1", "job_2"), "A calendar for public holidays"); - PutCalendarRequest putRequest = new PutCalendarRequest(calendar); - client.machineLearning().putCalendar(putRequest, RequestOptions.DEFAULT); - { - // tag::delete-calendar-job-request - DeleteCalendarJobRequest request = new DeleteCalendarJobRequest("holidays", // <1> - "job_1", "job_group_1"); // <2> - // end::delete-calendar-job-request - - // tag::delete-calendar-job-execute - PutCalendarResponse response = client.machineLearning().deleteCalendarJob(request, RequestOptions.DEFAULT); - // end::delete-calendar-job-execute - - // tag::delete-calendar-job-response - Calendar updatedCalendar = response.getCalendar(); // <1> - // end::delete-calendar-job-response - - assertThat(updatedCalendar.getJobIds(), containsInAnyOrder("job_2")); - } - { - DeleteCalendarJobRequest request = new DeleteCalendarJobRequest("holidays", "job_2"); - - // tag::delete-calendar-job-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(PutCalendarResponse deleteCalendarsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-calendar-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-calendar-job-execute-async - client.machineLearning().deleteCalendarJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-calendar-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetCalendar() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - Calendar calendar = new Calendar("holidays", Collections.singletonList("job_1"), "A calendar for public holidays"); - PutCalendarRequest putRequest = new PutCalendarRequest(calendar); - client.machineLearning().putCalendar(putRequest, RequestOptions.DEFAULT); - { - // tag::get-calendars-request - GetCalendarsRequest request = new GetCalendarsRequest(); // <1> - // end::get-calendars-request - - // tag::get-calendars-id - request.setCalendarId("holidays"); // <1> - // end::get-calendars-id - - // tag::get-calendars-page - request.setPageParams(new PageParams(10, 20)); // <1> - // end::get-calendars-page - - // reset page params - request.setPageParams(null); - - // tag::get-calendars-execute - GetCalendarsResponse response = client.machineLearning().getCalendars(request, RequestOptions.DEFAULT); - // end::get-calendars-execute - - // tag::get-calendars-response - long count = response.count(); // <1> - List calendars = response.calendars(); // <2> - // end::get-calendars-response - assertEquals(1, calendars.size()); - } - { - GetCalendarsRequest request = new GetCalendarsRequest("holidays"); - - // tag::get-calendars-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetCalendarsResponse getCalendarsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-calendars-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-calendars-execute-async - client.machineLearning().getCalendarsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-calendars-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteCalendar() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - Calendar calendar = new Calendar("holidays", Collections.singletonList("job_1"), "A calendar for public holidays"); - PutCalendarRequest putCalendarRequest = new PutCalendarRequest(calendar); - client.machineLearning().putCalendar(putCalendarRequest, RequestOptions.DEFAULT); - - // tag::delete-calendar-request - DeleteCalendarRequest request = new DeleteCalendarRequest("holidays"); // <1> - // end::delete-calendar-request - - // tag::delete-calendar-execute - AcknowledgedResponse response = client.machineLearning().deleteCalendar(request, RequestOptions.DEFAULT); - // end::delete-calendar-execute - - // tag::delete-calendar-response - boolean isAcknowledged = response.isAcknowledged(); // <1> - // end::delete-calendar-response - - assertTrue(isAcknowledged); - - // tag::delete-calendar-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-calendar-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-calendar-execute-async - client.machineLearning().deleteCalendarAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-calendar-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testGetCalendarEvent() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - Calendar calendar = new Calendar("holidays", Collections.singletonList("job_1"), "A calendar for public holidays"); - PutCalendarRequest putRequest = new PutCalendarRequest(calendar); - client.machineLearning().putCalendar(putRequest, RequestOptions.DEFAULT); - List events = Collections.singletonList(ScheduledEventTests.testInstance(calendar.getId(), null)); - client.machineLearning().postCalendarEvent(new PostCalendarEventRequest("holidays", events), RequestOptions.DEFAULT); - { - // tag::get-calendar-events-request - GetCalendarEventsRequest request = new GetCalendarEventsRequest("holidays"); // <1> - // end::get-calendar-events-request - - // tag::get-calendar-events-page - request.setPageParams(new PageParams(10, 20)); // <1> - // end::get-calendar-events-page - - // tag::get-calendar-events-start - request.setStart("2018-08-01T00:00:00Z"); // <1> - // end::get-calendar-events-start - - // tag::get-calendar-events-end - request.setEnd("2018-08-02T00:00:00Z"); // <1> - // end::get-calendar-events-end - - // tag::get-calendar-events-jobid - request.setJobId("job_1"); // <1> - // end::get-calendar-events-jobid - - // reset params - request.setPageParams(null); - request.setJobId(null); - request.setStart(null); - request.setEnd(null); - - // tag::get-calendar-events-execute - GetCalendarEventsResponse response = client.machineLearning().getCalendarEvents(request, RequestOptions.DEFAULT); - // end::get-calendar-events-execute - - // tag::get-calendar-events-response - long count = response.count(); // <1> - List scheduledEvents = response.events(); // <2> - // end::get-calendar-events-response - assertEquals(1, scheduledEvents.size()); - } - { - GetCalendarEventsRequest request = new GetCalendarEventsRequest("holidays"); - - // tag::get-calendar-events-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetCalendarEventsResponse getCalendarsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-calendar-events-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-calendar-events-execute-async - client.machineLearning().getCalendarEventsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-calendar-events-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPostCalendarEvent() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - Calendar calendar = new Calendar("holidays", Collections.singletonList("job_1"), "A calendar for public holidays"); - PutCalendarRequest putRequest = new PutCalendarRequest(calendar); - client.machineLearning().putCalendar(putRequest, RequestOptions.DEFAULT); - { - List events = Collections.singletonList(ScheduledEventTests.testInstance(calendar.getId(), null)); - - // tag::post-calendar-event-request - PostCalendarEventRequest request = new PostCalendarEventRequest("holidays", // <1> - events); // <2> - // end::post-calendar-event-request - - // tag::post-calendar-event-execute - PostCalendarEventResponse response = client.machineLearning().postCalendarEvent(request, RequestOptions.DEFAULT); - // end::post-calendar-event-execute - - // tag::post-calendar-event-response - List scheduledEvents = response.getScheduledEvents(); // <1> - // end::post-calendar-event-response - - assertEquals(1, scheduledEvents.size()); - } - { - List events = Collections.singletonList(ScheduledEventTests.testInstance()); - PostCalendarEventRequest request = new PostCalendarEventRequest("holidays", events); // <1> - - // tag::post-calendar-event-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(PostCalendarEventResponse postCalendarsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::post-calendar-event-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::post-calendar-event-execute-async - client.machineLearning().postCalendarEventAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::post-calendar-event-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteCalendarEvent() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - - Calendar calendar = new Calendar("holidays", Arrays.asList("job_1", "job_group_1", "job_2"), "A calendar for public holidays"); - PutCalendarRequest putRequest = new PutCalendarRequest(calendar); - client.machineLearning().putCalendar(putRequest, RequestOptions.DEFAULT); - List events = Arrays.asList( - ScheduledEventTests.testInstance(calendar.getId(), null), - ScheduledEventTests.testInstance(calendar.getId(), null) - ); - client.machineLearning().postCalendarEvent(new PostCalendarEventRequest("holidays", events), RequestOptions.DEFAULT); - GetCalendarEventsResponse getCalendarEventsResponse = client.machineLearning() - .getCalendarEvents(new GetCalendarEventsRequest("holidays"), RequestOptions.DEFAULT); - { - - // tag::delete-calendar-event-request - DeleteCalendarEventRequest request = new DeleteCalendarEventRequest("holidays", // <1> - "EventId"); // <2> - // end::delete-calendar-event-request - - request = new DeleteCalendarEventRequest("holidays", getCalendarEventsResponse.events().get(0).getEventId()); - - // tag::delete-calendar-event-execute - AcknowledgedResponse response = client.machineLearning().deleteCalendarEvent(request, RequestOptions.DEFAULT); - // end::delete-calendar-event-execute - - // tag::delete-calendar-event-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::delete-calendar-event-response - - assertThat(acknowledged, is(true)); - } - { - DeleteCalendarEventRequest request = new DeleteCalendarEventRequest( - "holidays", - getCalendarEventsResponse.events().get(1).getEventId() - ); - - // tag::delete-calendar-event-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse deleteCalendarEventResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-calendar-event-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-calendar-event-execute-async - client.machineLearning().deleteCalendarEventAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-calendar-event-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetDataFrameAnalytics() throws Exception { - createIndex(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]); - - RestHighLevelClient client = highLevelClient(); - client.machineLearning().putDataFrameAnalytics(new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG), RequestOptions.DEFAULT); - { - // tag::get-data-frame-analytics-request - GetDataFrameAnalyticsRequest request = new GetDataFrameAnalyticsRequest("my-analytics-config"); // <1> - request.setExcludeGenerated(false); // <2> - // end::get-data-frame-analytics-request - - // tag::get-data-frame-analytics-execute - GetDataFrameAnalyticsResponse response = client.machineLearning().getDataFrameAnalytics(request, RequestOptions.DEFAULT); - // end::get-data-frame-analytics-execute - - // tag::get-data-frame-analytics-response - List configs = response.getAnalytics(); - // end::get-data-frame-analytics-response - - assertThat(configs, hasSize(1)); - } - { - GetDataFrameAnalyticsRequest request = new GetDataFrameAnalyticsRequest("my-analytics-config"); - - // tag::get-data-frame-analytics-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(GetDataFrameAnalyticsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-data-frame-analytics-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-data-frame-analytics-execute-async - client.machineLearning().getDataFrameAnalyticsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-data-frame-analytics-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetDataFrameAnalyticsStats() throws Exception { - createIndex(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]); - - RestHighLevelClient client = highLevelClient(); - client.machineLearning().putDataFrameAnalytics(new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG), RequestOptions.DEFAULT); - { - // tag::get-data-frame-analytics-stats-request - GetDataFrameAnalyticsStatsRequest request = new GetDataFrameAnalyticsStatsRequest("my-analytics-config"); // <1> - // end::get-data-frame-analytics-stats-request - - // tag::get-data-frame-analytics-stats-execute - GetDataFrameAnalyticsStatsResponse response = - client.machineLearning().getDataFrameAnalyticsStats(request, RequestOptions.DEFAULT); - // end::get-data-frame-analytics-stats-execute - - // tag::get-data-frame-analytics-stats-response - List stats = response.getAnalyticsStats(); - // end::get-data-frame-analytics-stats-response - - assertThat(stats, hasSize(1)); - } - { - GetDataFrameAnalyticsStatsRequest request = new GetDataFrameAnalyticsStatsRequest("my-analytics-config"); - - // tag::get-data-frame-analytics-stats-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(GetDataFrameAnalyticsStatsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-data-frame-analytics-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-data-frame-analytics-stats-execute-async - client.machineLearning().getDataFrameAnalyticsStatsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-data-frame-analytics-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPutDataFrameAnalytics() throws Exception { - createIndex(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]); - - RestHighLevelClient client = highLevelClient(); - { - // tag::put-data-frame-analytics-query-config - QueryConfig queryConfig = new QueryConfig(new MatchAllQueryBuilder()); - // end::put-data-frame-analytics-query-config - - Map runtimeMappings = Collections.emptyMap(); - - // tag::put-data-frame-analytics-source-config - DataFrameAnalyticsSource sourceConfig = DataFrameAnalyticsSource.builder() // <1> - .setIndex("put-test-source-index") // <2> - .setQueryConfig(queryConfig) // <3> - .setRuntimeMappings(runtimeMappings) // <4> - .setSourceFiltering(new FetchSourceContext(true, - new String[] { "included_field_1", "included_field_2" }, - new String[] { "excluded_field" })) // <5> - .build(); - // end::put-data-frame-analytics-source-config - - // tag::put-data-frame-analytics-dest-config - DataFrameAnalyticsDest destConfig = DataFrameAnalyticsDest.builder() // <1> - .setIndex("put-test-dest-index") // <2> - .build(); - // end::put-data-frame-analytics-dest-config - - // tag::put-data-frame-analytics-outlier-detection-default - DataFrameAnalysis outlierDetection = org.elasticsearch.client.ml.dataframe.OutlierDetection.createDefault(); // <1> - // end::put-data-frame-analytics-outlier-detection-default - - // tag::put-data-frame-analytics-outlier-detection-customized - DataFrameAnalysis outlierDetectionCustomized = org.elasticsearch.client.ml.dataframe.OutlierDetection.builder() // <1> - .setMethod(org.elasticsearch.client.ml.dataframe.OutlierDetection.Method.DISTANCE_KNN) // <2> - .setNNeighbors(5) // <3> - .setFeatureInfluenceThreshold(0.1) // <4> - .setComputeFeatureInfluence(true) // <5> - .setOutlierFraction(0.05) // <6> - .setStandardizationEnabled(true) // <7> - .build(); - // end::put-data-frame-analytics-outlier-detection-customized - - // tag::put-data-frame-analytics-classification - DataFrameAnalysis classification = Classification.builder("my_dependent_variable") // <1> - .setLambda(1.0) // <2> - .setGamma(5.5) // <3> - .setEta(5.5) // <4> - .setMaxTrees(50) // <5> - .setFeatureBagFraction(0.4) // <6> - .setNumTopFeatureImportanceValues(3) // <7> - .setPredictionFieldName("my_prediction_field_name") // <8> - .setTrainingPercent(50.0) // <9> - .setRandomizeSeed(1234L) // <10> - .setClassAssignmentObjective(Classification.ClassAssignmentObjective.MAXIMIZE_ACCURACY) // <11> - .setNumTopClasses(1) // <12> - .setFeatureProcessors(Arrays.asList(OneHotEncoding.builder("categorical_feature") // <13> - .addOneHot("cat", "cat_column") - .build())) - .setAlpha(1.0) // <14> - .setEtaGrowthRatePerTree(1.0) // <15> - .setSoftTreeDepthLimit(1.0) // <16> - .setSoftTreeDepthTolerance(1.0) // <17> - .setDownsampleFactor(0.5) // <18> - .setMaxOptimizationRoundsPerHyperparameter(3) // <19> - .setEarlyStoppingEnabled(true) // <20> - .build(); - // end::put-data-frame-analytics-classification - - // tag::put-data-frame-analytics-regression - DataFrameAnalysis regression = org.elasticsearch.client.ml.dataframe.Regression.builder("my_dependent_variable") // <1> - .setLambda(1.0) // <2> - .setGamma(5.5) // <3> - .setEta(5.5) // <4> - .setMaxTrees(50) // <5> - .setFeatureBagFraction(0.4) // <6> - .setNumTopFeatureImportanceValues(3) // <7> - .setPredictionFieldName("my_prediction_field_name") // <8> - .setTrainingPercent(50.0) // <9> - .setRandomizeSeed(1234L) // <10> - .setLossFunction(Regression.LossFunction.MSE) // <11> - .setLossFunctionParameter(1.0) // <12> - .setFeatureProcessors(Arrays.asList(OneHotEncoding.builder("categorical_feature") // <13> - .addOneHot("cat", "cat_column") - .build())) - .setAlpha(1.0) // <14> - .setEtaGrowthRatePerTree(1.0) // <15> - .setSoftTreeDepthLimit(1.0) // <16> - .setSoftTreeDepthTolerance(1.0) // <17> - .setDownsampleFactor(0.5) // <18> - .setMaxOptimizationRoundsPerHyperparameter(3) // <19> - .setEarlyStoppingEnabled(true) // <20> - .build(); - // end::put-data-frame-analytics-regression - - // tag::put-data-frame-analytics-analyzed-fields - FetchSourceContext analyzedFields = - new FetchSourceContext( - true, - new String[] { "included_field_1", "included_field_2" }, - new String[] { "excluded_field" }); - // end::put-data-frame-analytics-analyzed-fields - - // tag::put-data-frame-analytics-config - DataFrameAnalyticsConfig config = DataFrameAnalyticsConfig.builder() - .setId("my-analytics-config") // <1> - .setSource(sourceConfig) // <2> - .setDest(destConfig) // <3> - .setAnalysis(outlierDetection) // <4> - .setAnalyzedFields(analyzedFields) // <5> - .setModelMemoryLimit(new ByteSizeValue(5, ByteSizeUnit.MB)) // <6> - .setDescription("this is an example description") // <7> - .setMaxNumThreads(1) // <8> - .build(); - // end::put-data-frame-analytics-config - - // tag::put-data-frame-analytics-request - PutDataFrameAnalyticsRequest request = new PutDataFrameAnalyticsRequest(config); // <1> - // end::put-data-frame-analytics-request - - // tag::put-data-frame-analytics-execute - PutDataFrameAnalyticsResponse response = client.machineLearning().putDataFrameAnalytics(request, RequestOptions.DEFAULT); - // end::put-data-frame-analytics-execute - - // tag::put-data-frame-analytics-response - DataFrameAnalyticsConfig createdConfig = response.getConfig(); - // end::put-data-frame-analytics-response - - assertThat(createdConfig.getId(), equalTo("my-analytics-config")); - } - { - PutDataFrameAnalyticsRequest request = new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG); - // tag::put-data-frame-analytics-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(PutDataFrameAnalyticsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-data-frame-analytics-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-data-frame-analytics-execute-async - client.machineLearning().putDataFrameAnalyticsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-data-frame-analytics-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testUpdateDataFrameAnalytics() throws Exception { - createIndex(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]); - - RestHighLevelClient client = highLevelClient(); - client.machineLearning().putDataFrameAnalytics(new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG), RequestOptions.DEFAULT); - { - // tag::update-data-frame-analytics-config-update - DataFrameAnalyticsConfigUpdate update = DataFrameAnalyticsConfigUpdate.builder() - .setId("my-analytics-config") // <1> - .setDescription("new description") // <2> - .setModelMemoryLimit(new ByteSizeValue(128, ByteSizeUnit.MB)) // <3> - .setMaxNumThreads(4) // <4> - .build(); - // end::update-data-frame-analytics-config-update - - // tag::update-data-frame-analytics-request - UpdateDataFrameAnalyticsRequest request = new UpdateDataFrameAnalyticsRequest(update); // <1> - // end::update-data-frame-analytics-request - - // tag::update-data-frame-analytics-execute - PutDataFrameAnalyticsResponse response = client.machineLearning().updateDataFrameAnalytics(request, RequestOptions.DEFAULT); - // end::update-data-frame-analytics-execute - - // tag::update-data-frame-analytics-response - DataFrameAnalyticsConfig updatedConfig = response.getConfig(); - // end::update-data-frame-analytics-response - - assertThat(updatedConfig.getDescription(), is(equalTo("new description"))); - assertThat(updatedConfig.getModelMemoryLimit(), is(equalTo(new ByteSizeValue(128, ByteSizeUnit.MB)))); - } - { - DataFrameAnalyticsConfigUpdate update = DataFrameAnalyticsConfigUpdate.builder().setId("my-analytics-config").build(); - UpdateDataFrameAnalyticsRequest request = new UpdateDataFrameAnalyticsRequest(update); - - // tag::update-data-frame-analytics-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(PutDataFrameAnalyticsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-data-frame-analytics-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-data-frame-analytics-execute-async - client.machineLearning().updateDataFrameAnalyticsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::update-data-frame-analytics-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteDataFrameAnalytics() throws Exception { - createIndex(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]); - - RestHighLevelClient client = highLevelClient(); - client.machineLearning().putDataFrameAnalytics(new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG), RequestOptions.DEFAULT); - { - // tag::delete-data-frame-analytics-request - DeleteDataFrameAnalyticsRequest request = new DeleteDataFrameAnalyticsRequest("my-analytics-config"); // <1> - // end::delete-data-frame-analytics-request - - //tag::delete-data-frame-analytics-request-options - request.setForce(false); // <1> - request.setTimeout(TimeValue.timeValueMinutes(1)); // <2> - //end::delete-data-frame-analytics-request-options - - // tag::delete-data-frame-analytics-execute - AcknowledgedResponse response = client.machineLearning().deleteDataFrameAnalytics(request, RequestOptions.DEFAULT); - // end::delete-data-frame-analytics-execute - - // tag::delete-data-frame-analytics-response - boolean acknowledged = response.isAcknowledged(); - // end::delete-data-frame-analytics-response - - assertThat(acknowledged, is(true)); - } - client.machineLearning().putDataFrameAnalytics(new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG), RequestOptions.DEFAULT); - { - DeleteDataFrameAnalyticsRequest request = new DeleteDataFrameAnalyticsRequest("my-analytics-config"); - - // tag::delete-data-frame-analytics-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-data-frame-analytics-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-data-frame-analytics-execute-async - client.machineLearning().deleteDataFrameAnalyticsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-data-frame-analytics-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testStartDataFrameAnalytics() throws Exception { - createIndex(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]); - highLevelClient().index( - new IndexRequest(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]).source(XContentType.JSON, "total", 10000) - .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE), - RequestOptions.DEFAULT - ); - RestHighLevelClient client = highLevelClient(); - client.machineLearning().putDataFrameAnalytics(new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG), RequestOptions.DEFAULT); - { - // tag::start-data-frame-analytics-request - StartDataFrameAnalyticsRequest request = new StartDataFrameAnalyticsRequest("my-analytics-config"); // <1> - // end::start-data-frame-analytics-request - - // tag::start-data-frame-analytics-execute - StartDataFrameAnalyticsResponse response = client.machineLearning().startDataFrameAnalytics(request, RequestOptions.DEFAULT); - // end::start-data-frame-analytics-execute - - // tag::start-data-frame-analytics-response - boolean acknowledged = response.isAcknowledged(); - String node = response.getNode(); // <1> - // end::start-data-frame-analytics-response - - assertThat(acknowledged, is(true)); - assertThat(node, notNullValue()); - } - assertBusy( - () -> assertThat(getAnalyticsState(DF_ANALYTICS_CONFIG.getId()), equalTo(DataFrameAnalyticsState.STOPPED)), - 30, - TimeUnit.SECONDS - ); - { - StartDataFrameAnalyticsRequest request = new StartDataFrameAnalyticsRequest("my-analytics-config"); - - // tag::start-data-frame-analytics-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(StartDataFrameAnalyticsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-data-frame-analytics-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::start-data-frame-analytics-execute-async - client.machineLearning().startDataFrameAnalyticsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::start-data-frame-analytics-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - assertBusy( - () -> assertThat(getAnalyticsState(DF_ANALYTICS_CONFIG.getId()), equalTo(DataFrameAnalyticsState.STOPPED)), - 30, - TimeUnit.SECONDS - ); - } - - public void testStopDataFrameAnalytics() throws Exception { - createIndex(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]); - highLevelClient().index( - new IndexRequest(DF_ANALYTICS_CONFIG.getSource().getIndex()[0]).source(XContentType.JSON, "total", 10000) - .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE), - RequestOptions.DEFAULT - ); - RestHighLevelClient client = highLevelClient(); - client.machineLearning().putDataFrameAnalytics(new PutDataFrameAnalyticsRequest(DF_ANALYTICS_CONFIG), RequestOptions.DEFAULT); - { - // tag::stop-data-frame-analytics-request - StopDataFrameAnalyticsRequest request = new StopDataFrameAnalyticsRequest("my-analytics-config"); // <1> - request.setForce(false); // <2> - // end::stop-data-frame-analytics-request - - // tag::stop-data-frame-analytics-execute - StopDataFrameAnalyticsResponse response = client.machineLearning().stopDataFrameAnalytics(request, RequestOptions.DEFAULT); - // end::stop-data-frame-analytics-execute - - // tag::stop-data-frame-analytics-response - boolean acknowledged = response.isStopped(); - // end::stop-data-frame-analytics-response - - assertThat(acknowledged, is(true)); - } - assertBusy( - () -> assertThat(getAnalyticsState(DF_ANALYTICS_CONFIG.getId()), equalTo(DataFrameAnalyticsState.STOPPED)), - 30, - TimeUnit.SECONDS - ); - { - StopDataFrameAnalyticsRequest request = new StopDataFrameAnalyticsRequest("my-analytics-config"); - - // tag::stop-data-frame-analytics-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(StopDataFrameAnalyticsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::stop-data-frame-analytics-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::stop-data-frame-analytics-execute-async - client.machineLearning().stopDataFrameAnalyticsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::stop-data-frame-analytics-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - assertBusy( - () -> assertThat(getAnalyticsState(DF_ANALYTICS_CONFIG.getId()), equalTo(DataFrameAnalyticsState.STOPPED)), - 30, - TimeUnit.SECONDS - ); - } - - public void testEvaluateDataFrame_OutlierDetection() throws Exception { - String indexName = "evaluate-test-index"; - CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName).mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("label") - .field("type", "keyword") - .endObject() - .startObject("p") - .field("type", "double") - .endObject() - .endObject() - .endObject() - ); - BulkRequest bulkRequest = new BulkRequest(indexName).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", false, "p", 0.1)) // #0 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", false, "p", 0.2)) // #1 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", false, "p", 0.3)) // #2 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", false, "p", 0.4)) // #3 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", false, "p", 0.7)) // #4 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", true, "p", 0.2)) // #5 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", true, "p", 0.3)) // #6 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", true, "p", 0.4)) // #7 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", true, "p", 0.8)) // #8 - .add(new IndexRequest().source(XContentType.JSON, "dataset", "blue", "label", true, "p", 0.9)); // #9 - RestHighLevelClient client = highLevelClient(); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - client.bulk(bulkRequest, RequestOptions.DEFAULT); - { - // tag::evaluate-data-frame-evaluation-outlierdetection - Evaluation evaluation = - new OutlierDetection( // <1> - "label", // <2> - "p", // <3> - // Evaluation metrics // <4> - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.PrecisionMetric.at(0.4, 0.5, 0.6), // <5> - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.RecallMetric.at(0.5, 0.7), // <6> - ConfusionMatrixMetric.at(0.5), // <7> - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.AucRocMetric.withCurve()); // <8> - // end::evaluate-data-frame-evaluation-outlierdetection - - // tag::evaluate-data-frame-request - EvaluateDataFrameRequest request = - new EvaluateDataFrameRequest( // <1> - indexName, // <2> - new QueryConfig(QueryBuilders.termQuery("dataset", "blue")), // <3> - evaluation); // <4> - // end::evaluate-data-frame-request - - // tag::evaluate-data-frame-execute - EvaluateDataFrameResponse response = client.machineLearning().evaluateDataFrame(request, RequestOptions.DEFAULT); - // end::evaluate-data-frame-execute - - // tag::evaluate-data-frame-response - List metrics = response.getMetrics(); // <1> - // end::evaluate-data-frame-response - - // tag::evaluate-data-frame-results-outlierdetection - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.PrecisionMetric.Result precisionResult = - response.getMetricByName(org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.PrecisionMetric.NAME); // <1> - double precision = precisionResult.getScoreByThreshold("0.4"); // <2> - - ConfusionMatrixMetric.Result confusionMatrixResult = response.getMetricByName(ConfusionMatrixMetric.NAME); // <3> - ConfusionMatrix confusionMatrix = confusionMatrixResult.getScoreByThreshold("0.5"); // <4> - // end::evaluate-data-frame-results-outlierdetection - - assertThat( - metrics.stream().map(EvaluationMetric.Result::getMetricName).collect(Collectors.toList()), - containsInAnyOrder( - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.PrecisionMetric.NAME, - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.RecallMetric.NAME, - ConfusionMatrixMetric.NAME, - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.AucRocMetric.NAME - ) - ); - assertThat(precision, closeTo(0.6, 1e-9)); - assertThat(confusionMatrix.getTruePositives(), equalTo(2L)); // docs #8 and #9 - assertThat(confusionMatrix.getFalsePositives(), equalTo(1L)); // doc #4 - assertThat(confusionMatrix.getTrueNegatives(), equalTo(4L)); // docs #0, #1, #2 and #3 - assertThat(confusionMatrix.getFalseNegatives(), equalTo(3L)); // docs #5, #6 and #7 - } - { - EvaluateDataFrameRequest request = new EvaluateDataFrameRequest( - indexName, - new QueryConfig(QueryBuilders.termQuery("dataset", "blue")), - new OutlierDetection( - "label", - "p", - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.PrecisionMetric.at(0.4, 0.5, 0.6), - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.RecallMetric.at(0.5, 0.7), - ConfusionMatrixMetric.at(0.5), - org.elasticsearch.client.ml.dataframe.evaluation.outlierdetection.AucRocMetric.withCurve() - ) - ); - - // tag::evaluate-data-frame-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(EvaluateDataFrameResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::evaluate-data-frame-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::evaluate-data-frame-execute-async - client.machineLearning().evaluateDataFrameAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::evaluate-data-frame-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testEvaluateDataFrame_Classification() throws Exception { - String indexName = "evaluate-classification-test-index"; - CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName).mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("actual_class") - .field("type", "keyword") - .endObject() - .startObject("predicted_class") - .field("type", "keyword") - .endObject() - .startObject("ml.top_classes") - .field("type", "nested") - .endObject() - .endObject() - .endObject() - ); - BiFunction indexRequest = (actualClass, topPredictedClasses) -> { - assert topPredictedClasses.length > 0; - return new IndexRequest().source( - XContentType.JSON, - "actual_class", - actualClass, - "predicted_class", - topPredictedClasses[0], - "ml.top_classes", - IntStream.range(0, topPredictedClasses.length) - // Consecutive assigned probabilities are: 0.5, 0.25, 0.125, etc. - .mapToObj(i -> Map.of("class_name", topPredictedClasses[i], "class_probability", 1.0 / (2 << i))) - .collect(toList()) - ); - }; - BulkRequest bulkRequest = new BulkRequest(indexName).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .add(indexRequest.apply("cat", new String[] { "cat", "dog", "ant" })) // #0 - .add(indexRequest.apply("cat", new String[] { "cat", "dog", "ant" })) // #1 - .add(indexRequest.apply("cat", new String[] { "cat", "horse", "dog" })) // #2 - .add(indexRequest.apply("cat", new String[] { "dog", "cat", "mule" })) // #3 - .add(indexRequest.apply("cat", new String[] { "fox", "cat", "dog" })) // #4 - .add(indexRequest.apply("dog", new String[] { "cat", "dog", "mule" })) // #5 - .add(indexRequest.apply("dog", new String[] { "dog", "cat", "ant" })) // #6 - .add(indexRequest.apply("dog", new String[] { "dog", "cat", "ant" })) // #7 - .add(indexRequest.apply("dog", new String[] { "dog", "cat", "ant" })) // #8 - .add(indexRequest.apply("ant", new String[] { "cat", "ant", "wasp" })); // #9 - RestHighLevelClient client = highLevelClient(); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - client.bulk(bulkRequest, RequestOptions.DEFAULT); - { - // tag::evaluate-data-frame-evaluation-classification - Evaluation evaluation = - new org.elasticsearch.client.ml.dataframe.evaluation.classification.Classification( // <1> - "actual_class", // <2> - "predicted_class", // <3> - "ml.top_classes", // <4> - // Evaluation metrics // <5> - new AccuracyMetric(), // <6> - new PrecisionMetric(), // <7> - new RecallMetric(), // <8> - new MulticlassConfusionMatrixMetric(3), // <9> - AucRocMetric.forClass("cat")); // <10> - // end::evaluate-data-frame-evaluation-classification - - EvaluateDataFrameRequest request = new EvaluateDataFrameRequest(indexName, null, evaluation); - EvaluateDataFrameResponse response = client.machineLearning().evaluateDataFrame(request, RequestOptions.DEFAULT); - - // tag::evaluate-data-frame-results-classification - AccuracyMetric.Result accuracyResult = response.getMetricByName(AccuracyMetric.NAME); // <1> - double accuracy = accuracyResult.getOverallAccuracy(); // <2> - - PrecisionMetric.Result precisionResult = response.getMetricByName(PrecisionMetric.NAME); // <3> - double precision = precisionResult.getAvgPrecision(); // <4> - - RecallMetric.Result recallResult = response.getMetricByName(RecallMetric.NAME); // <5> - double recall = recallResult.getAvgRecall(); // <6> - - MulticlassConfusionMatrixMetric.Result multiclassConfusionMatrix = - response.getMetricByName(MulticlassConfusionMatrixMetric.NAME); // <7> - - List confusionMatrix = multiclassConfusionMatrix.getConfusionMatrix(); // <8> - long otherClassesCount = multiclassConfusionMatrix.getOtherActualClassCount(); // <9> - - AucRocResult aucRocResult = response.getMetricByName(AucRocMetric.NAME); // <10> - double aucRocScore = aucRocResult.getValue(); // <11> - // end::evaluate-data-frame-results-classification - - assertThat(accuracyResult.getMetricName(), equalTo(AccuracyMetric.NAME)); - assertThat(accuracy, equalTo(0.6)); - - assertThat(precisionResult.getMetricName(), equalTo(PrecisionMetric.NAME)); - assertThat(precision, equalTo(0.675)); - - assertThat(recallResult.getMetricName(), equalTo(RecallMetric.NAME)); - assertThat(recall, equalTo(0.45)); - - assertThat(multiclassConfusionMatrix.getMetricName(), equalTo(MulticlassConfusionMatrixMetric.NAME)); - assertThat( - confusionMatrix, - equalTo( - List.of( - new ActualClass( - "ant", - 1L, - List.of(new PredictedClass("ant", 0L), new PredictedClass("cat", 1L), new PredictedClass("dog", 0L)), - 0L - ), - new ActualClass( - "cat", - 5L, - List.of(new PredictedClass("ant", 0L), new PredictedClass("cat", 3L), new PredictedClass("dog", 1L)), - 1L - ), - new ActualClass( - "dog", - 4L, - List.of(new PredictedClass("ant", 0L), new PredictedClass("cat", 1L), new PredictedClass("dog", 3L)), - 0L - ) - ) - ) - ); - assertThat(otherClassesCount, equalTo(0L)); - - assertThat(aucRocResult.getMetricName(), equalTo(AucRocMetric.NAME)); - assertThat(aucRocScore, closeTo(0.619, 1e-3)); - } - } - - public void testEvaluateDataFrame_Regression() throws Exception { - String indexName = "evaluate-classification-test-index"; - CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName).mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("actual_value") - .field("type", "double") - .endObject() - .startObject("predicted_value") - .field("type", "double") - .endObject() - .endObject() - .endObject() - ); - BulkRequest bulkRequest = new BulkRequest(indexName).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 1.0, "predicted_value", 1.0)) // #0 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 1.0, "predicted_value", 0.9)) // #1 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 2.0, "predicted_value", 2.0)) // #2 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 1.5, "predicted_value", 1.4)) // #3 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 1.2, "predicted_value", 1.3)) // #4 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 1.7, "predicted_value", 2.0)) // #5 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 2.1, "predicted_value", 2.1)) // #6 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 2.5, "predicted_value", 2.7)) // #7 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 0.8, "predicted_value", 1.0)) // #8 - .add(new IndexRequest().source(XContentType.JSON, "actual_value", 2.5, "predicted_value", 2.4)); // #9 - RestHighLevelClient client = highLevelClient(); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - client.bulk(bulkRequest, RequestOptions.DEFAULT); - { - // tag::evaluate-data-frame-evaluation-regression - Evaluation evaluation = - new org.elasticsearch.client.ml.dataframe.evaluation.regression.Regression( // <1> - "actual_value", // <2> - "predicted_value", // <3> - // Evaluation metrics // <4> - new MeanSquaredErrorMetric(), // <5> - new MeanSquaredLogarithmicErrorMetric(1.0), // <6> - new HuberMetric(1.0), // <7> - new RSquaredMetric()); // <8> - // end::evaluate-data-frame-evaluation-regression - - EvaluateDataFrameRequest request = new EvaluateDataFrameRequest(indexName, null, evaluation); - EvaluateDataFrameResponse response = client.machineLearning().evaluateDataFrame(request, RequestOptions.DEFAULT); - - // tag::evaluate-data-frame-results-regression - MeanSquaredErrorMetric.Result meanSquaredErrorResult = response.getMetricByName(MeanSquaredErrorMetric.NAME); // <1> - double meanSquaredError = meanSquaredErrorResult.getValue(); // <2> - - MeanSquaredLogarithmicErrorMetric.Result meanSquaredLogarithmicErrorResult = - response.getMetricByName(MeanSquaredLogarithmicErrorMetric.NAME); // <3> - double meanSquaredLogarithmicError = meanSquaredLogarithmicErrorResult.getValue(); // <4> - - HuberMetric.Result huberResult = response.getMetricByName(HuberMetric.NAME); // <5> - double huber = huberResult.getValue(); // <6> - - RSquaredMetric.Result rSquaredResult = response.getMetricByName(RSquaredMetric.NAME); // <7> - double rSquared = rSquaredResult.getValue(); // <8> - // end::evaluate-data-frame-results-regression - - assertThat(meanSquaredError, closeTo(0.021, 1e-3)); - assertThat(meanSquaredLogarithmicError, closeTo(0.003, 1e-3)); - assertThat(huber, closeTo(0.01, 1e-3)); - assertThat(rSquared, closeTo(0.941, 1e-3)); - } - } - - public void testExplainDataFrameAnalytics() throws Exception { - createIndex("explain-df-test-source-index"); - BulkRequest bulkRequest = new BulkRequest("explain-df-test-source-index").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - for (int i = 0; i < 10; ++i) { - bulkRequest.add(new IndexRequest().source(XContentType.JSON, "timestamp", 123456789L, "total", 10L)); - } - RestHighLevelClient client = highLevelClient(); - client.bulk(bulkRequest, RequestOptions.DEFAULT); - { - // tag::explain-data-frame-analytics-id-request - ExplainDataFrameAnalyticsRequest request = new ExplainDataFrameAnalyticsRequest("existing_job_id"); // <1> - // end::explain-data-frame-analytics-id-request - - // tag::explain-data-frame-analytics-config-request - DataFrameAnalyticsConfig config = DataFrameAnalyticsConfig.builder() - .setSource(DataFrameAnalyticsSource.builder().setIndex("explain-df-test-source-index").build()) - .setAnalysis(org.elasticsearch.client.ml.dataframe.OutlierDetection.createDefault()) - .build(); - request = new ExplainDataFrameAnalyticsRequest(config); // <1> - // end::explain-data-frame-analytics-config-request - - // tag::explain-data-frame-analytics-execute - ExplainDataFrameAnalyticsResponse response = client.machineLearning().explainDataFrameAnalytics(request, - RequestOptions.DEFAULT); - // end::explain-data-frame-analytics-execute - - // tag::explain-data-frame-analytics-response - List fieldSelection = response.getFieldSelection(); // <1> - MemoryEstimation memoryEstimation = response.getMemoryEstimation(); // <2> - // end::explain-data-frame-analytics-response - - assertThat(fieldSelection.size(), equalTo(2)); - assertThat(fieldSelection.stream().map(FieldSelection::getName).collect(Collectors.toList()), contains("timestamp", "total")); - - ByteSizeValue expectedMemoryWithoutDisk = memoryEstimation.getExpectedMemoryWithoutDisk(); // <1> - ByteSizeValue expectedMemoryWithDisk = memoryEstimation.getExpectedMemoryWithDisk(); // <2> - - // We are pretty liberal here as this test does not aim at verifying concrete numbers but rather end-to-end user workflow. - ByteSizeValue lowerBound = new ByteSizeValue(1, ByteSizeUnit.KB); - ByteSizeValue upperBound = new ByteSizeValue(1, ByteSizeUnit.GB); - assertThat(expectedMemoryWithoutDisk, allOf(greaterThan(lowerBound), lessThan(upperBound))); - assertThat(expectedMemoryWithDisk, allOf(greaterThan(lowerBound), lessThan(upperBound))); - } - { - DataFrameAnalyticsConfig config = DataFrameAnalyticsConfig.builder() - .setSource(DataFrameAnalyticsSource.builder().setIndex("explain-df-test-source-index").build()) - .setAnalysis(org.elasticsearch.client.ml.dataframe.OutlierDetection.createDefault()) - .build(); - ExplainDataFrameAnalyticsRequest request = new ExplainDataFrameAnalyticsRequest(config); - // tag::explain-data-frame-analytics-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(ExplainDataFrameAnalyticsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::explain-data-frame-analytics-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::explain-data-frame-analytics-execute-async - client.machineLearning().explainDataFrameAnalyticsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::explain-data-frame-analytics-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetTrainedModels() throws Exception { - putTrainedModel("my-trained-model"); - RestHighLevelClient client = highLevelClient(); - { - // tag::get-trained-models-request - GetTrainedModelsRequest request = new GetTrainedModelsRequest("my-trained-model") // <1> - .setPageParams(new PageParams(0, 1)) // <2> - .includeDefinition() // <3> - .includeTotalFeatureImportance() // <4> - .includeFeatureImportanceBaseline() // <5> - .setDecompressDefinition(false) // <6> - .setAllowNoMatch(true) // <7> - .setTags("regression") // <8> - .setExcludeGenerated(false); // <9> - // end::get-trained-models-request - request.setTags((List) null); - - // tag::get-trained-models-execute - GetTrainedModelsResponse response = client.machineLearning().getTrainedModels(request, RequestOptions.DEFAULT); - // end::get-trained-models-execute - - // tag::get-trained-models-response - List models = response.getTrainedModels(); - // end::get-trained-models-response - - assertThat(models, hasSize(1)); - } - { - GetTrainedModelsRequest request = new GetTrainedModelsRequest("my-trained-model"); - - // tag::get-trained-models-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(GetTrainedModelsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-trained-models-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-trained-models-execute-async - client.machineLearning().getTrainedModelsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-trained-models-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPutTrainedModel() throws Exception { - TrainedModelDefinition definition = TrainedModelDefinitionTests.createRandomBuilder(TargetType.REGRESSION).build(); - // tag::put-trained-model-config - TrainedModelConfig trainedModelConfig = TrainedModelConfig.builder() - .setDefinition(definition) // <1> - .setCompressedDefinition(InferenceToXContentCompressor.deflate(definition)) // <2> - .setModelId("my-new-trained-model") // <3> - .setModelType(TrainedModelType.TREE_ENSEMBLE) // <4> - .setInput(new TrainedModelInput("col1", "col2", "col3", "col4")) // <5> - .setDescription("test model") // <6> - .setMetadata(new HashMap<>()) // <7> - .setTags("my_regression_models") // <8> - .setInferenceConfig(new RegressionConfig("value", 0)) // <9> - .build(); - // end::put-trained-model-config - - trainedModelConfig = TrainedModelConfig.builder() - .setDefinition(definition) - .setInferenceConfig(new RegressionConfig(null, null)) - .setModelId("my-new-trained-model") - .setInput(new TrainedModelInput("col1", "col2", "col3", "col4")) - .setDescription("test model") - .setMetadata(new HashMap<>()) - .setTags("my_regression_models") - .build(); - - RestHighLevelClient client = highLevelClient(); - { - // tag::put-trained-model-request - PutTrainedModelRequest request = new PutTrainedModelRequest(trainedModelConfig); // <1> - // end::put-trained-model-request - - // tag::put-trained-model-execute - PutTrainedModelResponse response = client.machineLearning().putTrainedModel(request, RequestOptions.DEFAULT); - // end::put-trained-model-execute - - // tag::put-trained-model-response - TrainedModelConfig model = response.getResponse(); - // end::put-trained-model-response - - assertThat(model.getModelId(), equalTo(trainedModelConfig.getModelId())); - highLevelClient().machineLearning() - .deleteTrainedModel(new DeleteTrainedModelRequest("my-new-trained-model"), RequestOptions.DEFAULT); - } - { - PutTrainedModelRequest request = new PutTrainedModelRequest(trainedModelConfig); - - // tag::put-trained-model-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(PutTrainedModelResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-trained-model-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-trained-model-execute-async - client.machineLearning().putTrainedModelAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-trained-model-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - highLevelClient().machineLearning() - .deleteTrainedModel(new DeleteTrainedModelRequest("my-new-trained-model"), RequestOptions.DEFAULT); - } - } - - public void testPutTrainedModelAlias() throws Exception { - putTrainedModel("my-trained-model-with-alias"); - RestHighLevelClient client = highLevelClient(); - { - // tag::put-trained-model-alias-request - PutTrainedModelAliasRequest request = new PutTrainedModelAliasRequest( - "my-alias", // <1> - "my-trained-model-with-alias", // <2> - false // <3> - ); - // end::put-trained-model-alias-request - - // tag::put-trained-model-alias-execute - AcknowledgedResponse response = - client.machineLearning().putTrainedModelAlias(request, RequestOptions.DEFAULT); - // end::put-trained-model-alias-execute - - // tag::put-trained-model-alias-response - boolean acknowledged = response.isAcknowledged(); - // end::put-trained-model-alias-response - - assertThat(acknowledged, is(true)); - } - { - PutTrainedModelAliasRequest request = new PutTrainedModelAliasRequest("my-second-alias", "my-trained-model-with-alias", false); - // tag::put-trained-model-alias-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-trained-model-alias-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-trained-model-alias-execute-async - client.machineLearning() - .putTrainedModelAliasAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-trained-model-alias-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteTrainedModelAlias() throws Exception { - putTrainedModel("my-trained-model-with-delete-alias"); - RestHighLevelClient client = highLevelClient(); - { - client.machineLearning() - .putTrainedModelAlias( - new PutTrainedModelAliasRequest("my-alias-to-delete", "my-trained-model-with-delete-alias", false), - RequestOptions.DEFAULT - ); - - // tag::delete-trained-model-alias-request - DeleteTrainedModelAliasRequest request = new DeleteTrainedModelAliasRequest( - "my-alias-to-delete", // <1> - "my-trained-model-with-delete-alias" // <2> - ); - // end::delete-trained-model-alias-request - - // tag::delete-trained-model-alias-execute - AcknowledgedResponse response = - client.machineLearning().deleteTrainedModelAlias(request, RequestOptions.DEFAULT); - // end::delete-trained-model-alias-execute - - // tag::delete-trained-model-alias-response - boolean acknowledged = response.isAcknowledged(); - // end::delete-trained-model-alias-response - - assertThat(acknowledged, is(true)); - } - { - client.machineLearning() - .putTrainedModelAlias( - new PutTrainedModelAliasRequest("my-alias-to-delete", "my-trained-model-with-delete-alias", false), - RequestOptions.DEFAULT - ); - - DeleteTrainedModelAliasRequest request = new DeleteTrainedModelAliasRequest( - "my-alias-to-delete", - "my-trained-model-with-delete-alias" - ); - // tag::delete-trained-model-alias-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-trained-model-alias-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-trained-model-alias-execute-async - client.machineLearning() - .deleteTrainedModelAliasAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-trained-model-alias-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetTrainedModelsStats() throws Exception { - putTrainedModel("my-trained-model"); - RestHighLevelClient client = highLevelClient(); - { - // tag::get-trained-models-stats-request - GetTrainedModelsStatsRequest request = - new GetTrainedModelsStatsRequest("my-trained-model") // <1> - .setPageParams(new PageParams(0, 1)) // <2> - .setAllowNoMatch(true); // <3> - // end::get-trained-models-stats-request - - // tag::get-trained-models-stats-execute - GetTrainedModelsStatsResponse response = - client.machineLearning().getTrainedModelsStats(request, RequestOptions.DEFAULT); - // end::get-trained-models-stats-execute - - // tag::get-trained-models-stats-response - List models = response.getTrainedModelStats(); - // end::get-trained-models-stats-response - - assertThat(models, hasSize(1)); - } - { - GetTrainedModelsStatsRequest request = new GetTrainedModelsStatsRequest("my-trained-model"); - - // tag::get-trained-models-stats-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(GetTrainedModelsStatsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-trained-models-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-trained-models-stats-execute-async - client.machineLearning() - .getTrainedModelsStatsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-trained-models-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteTrainedModel() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - putTrainedModel("my-trained-model"); - // tag::delete-trained-models-request - DeleteTrainedModelRequest request = new DeleteTrainedModelRequest("my-trained-model"); // <1> - // end::delete-trained-models-request - - // tag::delete-trained-models-execute - AcknowledgedResponse response = client.machineLearning().deleteTrainedModel(request, RequestOptions.DEFAULT); - // end::delete-trained-models-execute - - // tag::delete-trained-models-response - boolean deleted = response.isAcknowledged(); - // end::delete-trained-models-response - - assertThat(deleted, is(true)); - } - { - putTrainedModel("my-trained-model"); - DeleteTrainedModelRequest request = new DeleteTrainedModelRequest("my-trained-model"); - - // tag::delete-trained-models-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-trained-models-execute-listener - - // Replace the empty listener by a blocking listener in test - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-trained-models-execute-async - client.machineLearning().deleteTrainedModelAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-trained-models-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testCreateFilter() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // tag::put-filter-config - MlFilter.Builder filterBuilder = MlFilter.builder("my_safe_domains") // <1> - .setDescription("A list of safe domains") // <2> - .setItems("*.google.com", "wikipedia.org"); // <3> - // end::put-filter-config - - // tag::put-filter-request - PutFilterRequest request = new PutFilterRequest(filterBuilder.build()); // <1> - // end::put-filter-request - - // tag::put-filter-execute - PutFilterResponse response = client.machineLearning().putFilter(request, RequestOptions.DEFAULT); - // end::put-filter-execute - - // tag::put-filter-response - MlFilter createdFilter = response.getResponse(); // <1> - // end::put-filter-response - assertThat(createdFilter.getId(), equalTo("my_safe_domains")); - } - { - MlFilter.Builder filterBuilder = MlFilter.builder("safe_domains_async") - .setDescription("A list of safe domains") - .setItems("*.google.com", "wikipedia.org"); - - PutFilterRequest request = new PutFilterRequest(filterBuilder.build()); - // tag::put-filter-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutFilterResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-filter-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-filter-execute-async - client.machineLearning().putFilterAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-filter-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetFilters() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - String filterId = "get-filter-doc-test"; - MlFilter.Builder filterBuilder = MlFilter.builder(filterId).setDescription("test").setItems("*.google.com", "wikipedia.org"); - - client.machineLearning().putFilter(new PutFilterRequest(filterBuilder.build()), RequestOptions.DEFAULT); - - { - // tag::get-filters-request - GetFiltersRequest request = new GetFiltersRequest(); // <1> - // end::get-filters-request - - // tag::get-filters-filter-id - request.setFilterId("get-filter-doc-test"); // <1> - // end::get-filters-filter-id - - // tag::get-filters-page-params - request.setFrom(100); // <1> - request.setSize(200); // <2> - // end::get-filters-page-params - - request.setFrom(null); - request.setSize(null); - - // tag::get-filters-execute - GetFiltersResponse response = client.machineLearning().getFilter(request, RequestOptions.DEFAULT); - // end::get-filters-execute - - // tag::get-filters-response - long count = response.count(); // <1> - List filters = response.filters(); // <2> - // end::get-filters-response - assertEquals(1, filters.size()); - } - { - GetFiltersRequest request = new GetFiltersRequest(); - request.setFilterId(filterId); - - // tag::get-filters-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetFiltersResponse getfiltersResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-filters-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-filters-execute-async - client.machineLearning().getFilterAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-filters-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testUpdateFilter() throws IOException, InterruptedException { - RestHighLevelClient client = highLevelClient(); - String filterId = "update-filter-doc-test"; - MlFilter.Builder filterBuilder = MlFilter.builder(filterId).setDescription("test").setItems("*.google.com", "wikipedia.org"); - - client.machineLearning().putFilter(new PutFilterRequest(filterBuilder.build()), RequestOptions.DEFAULT); - - { - // tag::update-filter-request - UpdateFilterRequest request = new UpdateFilterRequest(filterId); // <1> - // end::update-filter-request - - // tag::update-filter-description - request.setDescription("my new description"); // <1> - // end::update-filter-description - - // tag::update-filter-add-items - request.setAddItems(Arrays.asList("*.bing.com", "*.elastic.co")); // <1> - // end::update-filter-add-items - - // tag::update-filter-remove-items - request.setRemoveItems(Arrays.asList("*.google.com")); // <1> - // end::update-filter-remove-items - - // tag::update-filter-execute - PutFilterResponse response = client.machineLearning().updateFilter(request, RequestOptions.DEFAULT); - // end::update-filter-execute - - // tag::update-filter-response - MlFilter updatedFilter = response.getResponse(); // <1> - // end::update-filter-response - assertEquals(request.getDescription(), updatedFilter.getDescription()); - } - { - UpdateFilterRequest request = new UpdateFilterRequest(filterId); - - // tag::update-filter-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutFilterResponse putFilterResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-filter-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-filter-execute-async - client.machineLearning().updateFilterAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::update-filter-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteFilter() throws Exception { - RestHighLevelClient client = highLevelClient(); - String filterId = createFilter(client); - - { - // tag::delete-filter-request - DeleteFilterRequest request = new DeleteFilterRequest(filterId); // <1> - // end::delete-filter-request - - // tag::delete-filter-execute - AcknowledgedResponse response = client.machineLearning().deleteFilter(request, RequestOptions.DEFAULT); - // end::delete-filter-execute - - // tag::delete-filter-response - boolean isAcknowledged = response.isAcknowledged(); // <1> - // end::delete-filter-response - assertTrue(isAcknowledged); - } - filterId = createFilter(client); - { - DeleteFilterRequest request = new DeleteFilterRequest(filterId); - // tag::delete-filter-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-filter-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-filter-execute-async - client.machineLearning().deleteFilterAsync(request, RequestOptions.DEFAULT, listener); //<1> - // end::delete-filter-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetMlInfo() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::get-ml-info-request - MlInfoRequest request = new MlInfoRequest(); // <1> - // end::get-ml-info-request - - // tag::get-ml-info-execute - MlInfoResponse response = client.machineLearning() - .getMlInfo(request, RequestOptions.DEFAULT); - // end::get-ml-info-execute - - // tag::get-ml-info-response - final Map info = response.getInfo();// <1> - // end::get-ml-info-response - assertTrue(info.containsKey("defaults")); - assertTrue(info.containsKey("limits")); - } - { - MlInfoRequest request = new MlInfoRequest(); - - // tag::get-ml-info-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(MlInfoResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-ml-info-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-ml-info-execute-async - client.machineLearning() - .getMlInfoAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-ml-info-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSetUpgradeMode() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // tag::set-upgrade-mode-request - SetUpgradeModeRequest request = new SetUpgradeModeRequest(true); // <1> - request.setTimeout(TimeValue.timeValueMinutes(10)); // <2> - // end::set-upgrade-mode-request - - // Set to false so that the cluster setting does not have to be unset at the end of the test. - request.setEnabled(false); - - // tag::set-upgrade-mode-execute - AcknowledgedResponse acknowledgedResponse = client.machineLearning().setUpgradeMode(request, RequestOptions.DEFAULT); - // end::set-upgrade-mode-execute - - // tag::set-upgrade-mode-response - boolean acknowledged = acknowledgedResponse.isAcknowledged(); // <1> - // end::set-upgrade-mode-response - assertThat(acknowledged, is(true)); - } - { - SetUpgradeModeRequest request = new SetUpgradeModeRequest(false); - - // tag::set-upgrade-mode-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse acknowledgedResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::set-upgrade-mode-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::set-upgrade-mode-execute-async - client.machineLearning() - .setUpgradeModeAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::set-upgrade-mode-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - } - } - - public void testEstimateModelMemory() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - // tag::estimate-model-memory-request - Detector.Builder detectorBuilder = new Detector.Builder() - .setFunction("count") - .setPartitionFieldName("status"); - AnalysisConfig.Builder analysisConfigBuilder = - new AnalysisConfig.Builder(Collections.singletonList(detectorBuilder.build())) - .setBucketSpan(TimeValue.timeValueMinutes(10)) - .setInfluencers(Collections.singletonList("src_ip")); - EstimateModelMemoryRequest request = new EstimateModelMemoryRequest(analysisConfigBuilder.build()); // <1> - request.setOverallCardinality(Collections.singletonMap("status", 50L)); // <2> - request.setMaxBucketCardinality(Collections.singletonMap("src_ip", 30L)); // <3> - // end::estimate-model-memory-request - - // tag::estimate-model-memory-execute - EstimateModelMemoryResponse estimateModelMemoryResponse = - client.machineLearning().estimateModelMemory(request, RequestOptions.DEFAULT); - // end::estimate-model-memory-execute - - // tag::estimate-model-memory-response - ByteSizeValue modelMemoryEstimate = estimateModelMemoryResponse.getModelMemoryEstimate(); // <1> - long estimateInBytes = modelMemoryEstimate.getBytes(); - // end::estimate-model-memory-response - assertThat(estimateInBytes, greaterThan(10000000L)); - } - { - AnalysisConfig analysisConfig = AnalysisConfig.builder( - Collections.singletonList(Detector.builder().setFunction("count").build()) - ).build(); - EstimateModelMemoryRequest request = new EstimateModelMemoryRequest(analysisConfig); - - // tag::estimate-model-memory-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(EstimateModelMemoryResponse estimateModelMemoryResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::estimate-model-memory-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::estimate-model-memory-execute-async - client.machineLearning() - .estimateModelMemoryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::estimate-model-memory-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - private String createFilter(RestHighLevelClient client) throws IOException { - MlFilter.Builder filterBuilder = MlFilter.builder("my_safe_domains") - .setDescription("A list of safe domains") - .setItems("*.google.com", "wikipedia.org"); - PutFilterRequest putFilterRequest = new PutFilterRequest(filterBuilder.build()); - PutFilterResponse putFilterResponse = client.machineLearning().putFilter(putFilterRequest, RequestOptions.DEFAULT); - MlFilter createdFilter = putFilterResponse.getResponse(); - assertThat(createdFilter.getId(), equalTo("my_safe_domains")); - return createdFilter.getId(); - } - - private void createIndex(String indexName) throws IOException { - CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName); - createIndexRequest.mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("timestamp") - .field("type", "date") - .endObject() - .startObject("total") - .field("type", "long") - .endObject() - .endObject() - .endObject() - ); - highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT); - } - - private DataFrameAnalyticsState getAnalyticsState(String configId) throws IOException { - GetDataFrameAnalyticsStatsResponse statsResponse = highLevelClient().machineLearning() - .getDataFrameAnalyticsStats(new GetDataFrameAnalyticsStatsRequest(configId), RequestOptions.DEFAULT); - assertThat(statsResponse.getAnalyticsStats(), hasSize(1)); - DataFrameAnalyticsStats stats = statsResponse.getAnalyticsStats().get(0); - return stats.getState(); - } - - private void putTrainedModel(String modelId) throws IOException { - TrainedModelDefinition definition = TrainedModelDefinitionTests.createRandomBuilder(TargetType.REGRESSION).build(); - TrainedModelConfig trainedModelConfig = TrainedModelConfig.builder() - .setDefinition(definition) - .setModelId(modelId) - .setInferenceConfig(new RegressionConfig("value", 0)) - .setInput(new TrainedModelInput(Arrays.asList("col1", "col2", "col3", "col4"))) - .setDescription("test model") - .build(); - highLevelClient().machineLearning().putTrainedModel(new PutTrainedModelRequest(trainedModelConfig), RequestOptions.DEFAULT); - } - - @Override - protected NamedXContentRegistry xContentRegistry() { - return new NamedXContentRegistry(new MlInferenceNamedXContentProvider().getNamedXContentParsers()); - } - - private static final DataFrameAnalyticsConfig DF_ANALYTICS_CONFIG = DataFrameAnalyticsConfig.builder() - .setId("my-analytics-config") - .setSource(DataFrameAnalyticsSource.builder().setIndex("put-test-source-index").build()) - .setDest(DataFrameAnalyticsDest.builder().setIndex("put-test-dest-index").build()) - .setAnalysis(org.elasticsearch.client.ml.dataframe.OutlierDetection.createDefault()) - .build(); -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java deleted file mode 100644 index 9ca78f522115..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java +++ /dev/null @@ -1,672 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; -import org.elasticsearch.action.bulk.BulkRequest; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.support.WriteRequest; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.RollupClient; -import org.elasticsearch.client.core.AcknowledgedResponse; -import org.elasticsearch.client.rollup.DeleteRollupJobRequest; -import org.elasticsearch.client.rollup.GetRollupCapsRequest; -import org.elasticsearch.client.rollup.GetRollupCapsResponse; -import org.elasticsearch.client.rollup.GetRollupIndexCapsRequest; -import org.elasticsearch.client.rollup.GetRollupIndexCapsResponse; -import org.elasticsearch.client.rollup.GetRollupJobRequest; -import org.elasticsearch.client.rollup.GetRollupJobResponse; -import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper; -import org.elasticsearch.client.rollup.GetRollupJobResponse.RollupIndexerJobStats; -import org.elasticsearch.client.rollup.GetRollupJobResponse.RollupJobStatus; -import org.elasticsearch.client.rollup.PutRollupJobRequest; -import org.elasticsearch.client.rollup.RollableIndexCaps; -import org.elasticsearch.client.rollup.RollupJobCaps; -import org.elasticsearch.client.rollup.StartRollupJobRequest; -import org.elasticsearch.client.rollup.StartRollupJobResponse; -import org.elasticsearch.client.rollup.StopRollupJobRequest; -import org.elasticsearch.client.rollup.StopRollupJobResponse; -import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig; -import org.elasticsearch.client.rollup.job.config.GroupConfig; -import org.elasticsearch.client.rollup.job.config.HistogramGroupConfig; -import org.elasticsearch.client.rollup.job.config.MetricConfig; -import org.elasticsearch.client.rollup.job.config.RollupJobConfig; -import org.elasticsearch.client.rollup.job.config.TermsGroupConfig; -import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; -import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.junit.Before; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.oneOf; - -@SuppressWarnings("removal") -public class RollupDocumentationIT extends ESRestHighLevelClientTestCase { - - @Before - public void setUpDocs() throws IOException { - final BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - for (int i = 0; i < 50; i++) { - final IndexRequest indexRequest = new IndexRequest("docs"); - indexRequest.source( - jsonBuilder().startObject() - .field("timestamp", String.format(Locale.ROOT, "2018-01-01T00:%02d:00Z", i)) - .field("hostname", 0) - .field("datacenter", 0) - .field("temperature", i) - .field("voltage", 0) - .field("load", 0) - .field("net_in", 0) - .field("net_out", 0) - .endObject() - ); - bulkRequest.add(indexRequest); - } - BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT); - assertEquals(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - - RefreshResponse refreshResponse = highLevelClient().indices().refresh(new RefreshRequest("docs"), RequestOptions.DEFAULT); - assertEquals(0, refreshResponse.getFailedShards()); - } - - public void testCreateRollupJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - final String indexPattern = "docs"; - final String rollupIndex = "rollup"; - final String cron = "*/1 * * * * ?"; - final int pageSize = 100; - final TimeValue timeout = null; - - //tag::x-pack-rollup-put-rollup-job-group-config - DateHistogramGroupConfig dateHistogram = - new DateHistogramGroupConfig("timestamp", DateHistogramInterval.HOUR, new DateHistogramInterval("7d"), "UTC"); // <1> - TermsGroupConfig terms = new TermsGroupConfig("hostname", "datacenter"); // <2> - HistogramGroupConfig histogram = new HistogramGroupConfig(5L, "load", "net_in", "net_out"); // <3> - - GroupConfig groups = new GroupConfig(dateHistogram, histogram, terms); // <4> - //end::x-pack-rollup-put-rollup-job-group-config - - //tag::x-pack-rollup-put-rollup-job-metrics-config - List metrics = new ArrayList<>(); // <1> - metrics.add(new MetricConfig("temperature", Arrays.asList("min", "max", "sum"))); // <2> - metrics.add(new MetricConfig("voltage", Arrays.asList("avg", "value_count"))); // <3> - //end::x-pack-rollup-put-rollup-job-metrics-config - { - String id = "job_1"; - - //tag::x-pack-rollup-put-rollup-job-config - RollupJobConfig config = new RollupJobConfig(id, // <1> - indexPattern, // <2> - rollupIndex, // <3> - cron, // <4> - pageSize, // <5> - groups, // <6> - metrics, // <7> - timeout); // <8> - //end::x-pack-rollup-put-rollup-job-config - - //tag::x-pack-rollup-put-rollup-job-request - PutRollupJobRequest request = new PutRollupJobRequest(config); // <1> - //end::x-pack-rollup-put-rollup-job-request - - //tag::x-pack-rollup-put-rollup-job-execute - AcknowledgedResponse response = client.rollup().putRollupJob(request, RequestOptions.DEFAULT); - //end::x-pack-rollup-put-rollup-job-execute - - //tag::x-pack-rollup-put-rollup-job-response - boolean acknowledged = response.isAcknowledged(); // <1> - //end::x-pack-rollup-put-rollup-job-response - assertTrue(acknowledged); - } - { - String id = "job_2"; - RollupJobConfig config = new RollupJobConfig(id, indexPattern, rollupIndex, cron, pageSize, groups, metrics, timeout); - PutRollupJobRequest request = new PutRollupJobRequest(config); - // tag::x-pack-rollup-put-rollup-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-rollup-put-rollup-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-rollup-put-rollup-job-execute-async - client.rollup().putRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-rollup-put-rollup-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testGetRollupJob() throws Exception { - testCreateRollupJob(); - RestHighLevelClient client = highLevelClient(); - - // tag::x-pack-rollup-get-rollup-job-request - GetRollupJobRequest getAll = new GetRollupJobRequest(); // <1> - GetRollupJobRequest getJob = new GetRollupJobRequest("job_1"); // <2> - // end::x-pack-rollup-get-rollup-job-request - - // tag::x-pack-rollup-get-rollup-job-execute - GetRollupJobResponse response = client.rollup().getRollupJob(getJob, RequestOptions.DEFAULT); - // end::x-pack-rollup-get-rollup-job-execute - - // tag::x-pack-rollup-get-rollup-job-response - assertThat(response.getJobs(), hasSize(1)); - JobWrapper job = response.getJobs().get(0); // <1> - RollupJobConfig config = job.getJob(); - RollupJobStatus status = job.getStatus(); - RollupIndexerJobStats stats = job.getStats(); - // end::x-pack-rollup-get-rollup-job-response - assertNotNull(config); - assertNotNull(status); - assertNotNull(status); - - // tag::x-pack-rollup-get-rollup-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetRollupJobResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-rollup-get-rollup-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-rollup-get-rollup-job-execute-async - client.rollup().getRollupJobAsync(getJob, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-rollup-get-rollup-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testStartRollupJob() throws Exception { - testCreateRollupJob(); - RestHighLevelClient client = highLevelClient(); - String id = "job_1"; - // tag::rollup-start-job-request - StartRollupJobRequest request = new StartRollupJobRequest(id); // <1> - // end::rollup-start-job-request - try { - // tag::rollup-start-job-execute - RollupClient rc = client.rollup(); - StartRollupJobResponse response = rc.startRollupJob(request, RequestOptions.DEFAULT); - // end::rollup-start-job-execute - // tag::rollup-start-job-response - response.isAcknowledged(); // <1> - // end::rollup-start-job-response - } catch (Exception e) { - // Swallow any exception, this test does not test actually cancelling. - } - // stop job to prevent spamming exceptions on next start request - StopRollupJobRequest stopRequest = new StopRollupJobRequest(id); - stopRequest.waitForCompletion(); - stopRequest.timeout(TimeValue.timeValueSeconds(10)); - - StopRollupJobResponse response = client.rollup().stopRollupJob(stopRequest, RequestOptions.DEFAULT); - assertTrue(response.isAcknowledged()); - - // tag::rollup-start-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StartRollupJobResponse response) { - // <1> - } - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::rollup-start-job-execute-listener - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - // tag::rollup-start-job-execute-async - RollupClient rc = client.rollup(); - rc.startRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::rollup-start-job-execute-async - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // stop job so it can correctly be deleted by the test teardown - response = rc.stopRollupJob(stopRequest, RequestOptions.DEFAULT); - assertTrue(response.isAcknowledged()); - } - - @SuppressWarnings("unused") - public void testStopRollupJob() throws Exception { - testCreateRollupJob(); - RestHighLevelClient client = highLevelClient(); - - String id = "job_1"; - // tag::rollup-stop-job-request - StopRollupJobRequest request = new StopRollupJobRequest(id); // <1> - request.waitForCompletion(true); // <2> - request.timeout(TimeValue.timeValueSeconds(10)); // <3> - // end::rollup-stop-job-request - - try { - // tag::rollup-stop-job-execute - RollupClient rc = client.rollup(); - StopRollupJobResponse response = rc.stopRollupJob(request, RequestOptions.DEFAULT); - // end::rollup-stop-job-execute - - // tag::rollup-stop-job-response - response.isAcknowledged(); // <1> - // end::rollup-stop-job-response - } catch (Exception e) { - // Swallow any exception, this test does not test actually cancelling. - } - - // tag::rollup-stop-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StopRollupJobResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::rollup-stop-job-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::rollup-stop-job-execute-async - RollupClient rc = client.rollup(); - rc.stopRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::rollup-stop-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testSearch() throws Exception { - // Setup a rollup index to query - testCreateRollupJob(); - - RestHighLevelClient client = highLevelClient(); - - // tag::search-request - SearchRequest request = new SearchRequest(); - request.source(new SearchSourceBuilder() - .size(0) - .aggregation(new MaxAggregationBuilder("max_temperature") - .field("temperature"))); - // end::search-request - - // tag::search-execute - SearchResponse response = - client.rollup().search(request, RequestOptions.DEFAULT); - // end::search-execute - - // tag::search-response - NumericMetricsAggregation.SingleValue maxTemperature = - response.getAggregations().get("max_temperature"); - assertThat(maxTemperature.value(), closeTo(49.0, .00001)); - // end::search-response - - ActionListener listener; - // tag::search-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(SearchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::search-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::search-execute-async - client.rollup().searchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::search-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testGetRollupCaps() throws Exception { - RestHighLevelClient client = highLevelClient(); - - DateHistogramGroupConfig dateHistogram = new DateHistogramGroupConfig.FixedInterval( - "timestamp", - DateHistogramInterval.HOUR, - new DateHistogramInterval("7d"), - "UTC" - ); // <1> - TermsGroupConfig terms = new TermsGroupConfig("hostname", "datacenter"); - HistogramGroupConfig histogram = new HistogramGroupConfig(5L, "load", "net_in", "net_out"); - GroupConfig groups = new GroupConfig(dateHistogram, histogram, terms); - List metrics = new ArrayList<>(); // <1> - metrics.add(new MetricConfig("temperature", Arrays.asList("min", "max", "sum"))); - metrics.add(new MetricConfig("voltage", Arrays.asList("avg", "value_count"))); - - //tag::x-pack-rollup-get-rollup-caps-setup - final String indexPattern = "docs"; - final String rollupIndexName = "rollup"; - final String cron = "*/1 * * * * ?"; - final int pageSize = 100; - final TimeValue timeout = null; - - String id = "job_1"; - RollupJobConfig config = new RollupJobConfig(id, indexPattern, rollupIndexName, cron, - pageSize, groups, metrics, timeout); - - PutRollupJobRequest request = new PutRollupJobRequest(config); - AcknowledgedResponse response = client.rollup().putRollupJob(request, RequestOptions.DEFAULT); - - boolean acknowledged = response.isAcknowledged(); - //end::x-pack-rollup-get-rollup-caps-setup - assertTrue(acknowledged); - - ClusterHealthRequest healthRequest = new ClusterHealthRequest(config.getRollupIndex()).waitForYellowStatus(); - ClusterHealthResponse healthResponse = client.cluster().health(healthRequest, RequestOptions.DEFAULT); - assertFalse(healthResponse.isTimedOut()); - assertThat(healthResponse.getStatus(), oneOf(ClusterHealthStatus.YELLOW, ClusterHealthStatus.GREEN)); - - // Now that the job is created, we should have a rollup index with metadata. - // We can test out the caps API now. - - //tag::x-pack-rollup-get-rollup-caps-request - GetRollupCapsRequest getRollupCapsRequest = new GetRollupCapsRequest("docs"); - //end::x-pack-rollup-get-rollup-caps-request - - //tag::x-pack-rollup-get-rollup-caps-execute - GetRollupCapsResponse capsResponse = client.rollup().getRollupCapabilities(getRollupCapsRequest, RequestOptions.DEFAULT); - //end::x-pack-rollup-get-rollup-caps-execute - - //tag::x-pack-rollup-get-rollup-caps-response - Map rolledPatterns = capsResponse.getJobs(); - - RollableIndexCaps docsPattern = rolledPatterns.get("docs"); - - // indexName will be "docs" in this case... the index pattern that we rolled up - String indexName = docsPattern.getIndexName(); - - // Each index pattern can have multiple jobs that rolled it up, so `getJobCaps()` - // returns a list of jobs that rolled up the pattern - List rollupJobs = docsPattern.getJobCaps(); - RollupJobCaps jobCaps = rollupJobs.get(0); - - // jobID is the identifier we used when we created the job (e.g. `job1`) - String jobID = jobCaps.getJobID(); - - // rollupIndex is the location that the job stored it's rollup docs (e.g. `rollup`) - String rollupIndex = jobCaps.getRollupIndex(); - - // indexPattern is the same as the indexName that we retrieved earlier, redundant info - assert jobCaps.getIndexPattern().equals(indexName); - - // Finally, fieldCaps are the capabilities of individual fields in the config - // The key is the field name, and the value is a RollupFieldCaps object which - // provides more info. - Map fieldCaps = jobCaps.getFieldCaps(); - - // If we retrieve the "timestamp" field, it returns a list of maps. Each list - // item represents a different aggregation that can be run against the "timestamp" - // field, and any additional details specific to that agg (interval, etc) - List> timestampCaps = fieldCaps.get("timestamp").getAggs(); - logger.error(timestampCaps.get(0).toString()); - assert timestampCaps.get(0).toString().equals("{agg=date_histogram, fixed_interval=1h, delay=7d, time_zone=UTC}"); - - // In contrast to the timestamp field, the temperature field has multiple aggs configured - List> temperatureCaps = fieldCaps.get("temperature").getAggs(); - assert temperatureCaps.toString().equals("[{agg=min}, {agg=max}, {agg=sum}]"); - //end::x-pack-rollup-get-rollup-caps-response - - assertThat(indexName, equalTo("docs")); - assertThat(jobID, equalTo("job_1")); - assertThat(rollupIndex, equalTo("rollup")); - assertThat(fieldCaps.size(), equalTo(8)); - - // tag::x-pack-rollup-get-rollup-caps-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetRollupCapsResponse response) { - - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-rollup-get-rollup-caps-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-rollup-get-rollup-caps-execute-async - client.rollup().getRollupCapabilitiesAsync(getRollupCapsRequest, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-rollup-get-rollup-caps-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testGetRollupIndexCaps() throws Exception { - RestHighLevelClient client = highLevelClient(); - - DateHistogramGroupConfig dateHistogram = new DateHistogramGroupConfig.FixedInterval( - "timestamp", - DateHistogramInterval.HOUR, - new DateHistogramInterval("7d"), - "UTC" - ); // <1> - TermsGroupConfig terms = new TermsGroupConfig("hostname", "datacenter"); - HistogramGroupConfig histogram = new HistogramGroupConfig(5L, "load", "net_in", "net_out"); - GroupConfig groups = new GroupConfig(dateHistogram, histogram, terms); - List metrics = new ArrayList<>(); // <1> - metrics.add(new MetricConfig("temperature", Arrays.asList("min", "max", "sum"))); - metrics.add(new MetricConfig("voltage", Arrays.asList("avg", "value_count"))); - - //tag::x-pack-rollup-get-rollup-index-caps-setup - final String indexPattern = "docs"; - final String rollupIndexName = "rollup"; - final String cron = "*/1 * * * * ?"; - final int pageSize = 100; - final TimeValue timeout = null; - - String id = "job_1"; - RollupJobConfig config = new RollupJobConfig(id, indexPattern, rollupIndexName, cron, - pageSize, groups, metrics, timeout); - - PutRollupJobRequest request = new PutRollupJobRequest(config); - AcknowledgedResponse response = client.rollup().putRollupJob(request, RequestOptions.DEFAULT); - - boolean acknowledged = response.isAcknowledged(); - //end::x-pack-rollup-get-rollup-index-caps-setup - assertTrue(acknowledged); - - ClusterHealthRequest healthRequest = new ClusterHealthRequest(config.getRollupIndex()).waitForYellowStatus(); - ClusterHealthResponse healthResponse = client.cluster().health(healthRequest, RequestOptions.DEFAULT); - assertFalse(healthResponse.isTimedOut()); - assertThat(healthResponse.getStatus(), oneOf(ClusterHealthStatus.YELLOW, ClusterHealthStatus.GREEN)); - - // Now that the job is created, we should have a rollup index with metadata. - // We can test out the caps API now. - - //tag::x-pack-rollup-get-rollup-index-caps-request - GetRollupIndexCapsRequest getRollupIndexCapsRequest = new GetRollupIndexCapsRequest("rollup"); - //end::x-pack-rollup-get-rollup-index-caps-request - - //tag::x-pack-rollup-get-rollup-index-caps-execute - GetRollupIndexCapsResponse capsResponse = client.rollup() - .getRollupIndexCapabilities(getRollupIndexCapsRequest, RequestOptions.DEFAULT); - //end::x-pack-rollup-get-rollup-index-caps-execute - - //tag::x-pack-rollup-get-rollup-index-caps-response - Map rolledPatterns = capsResponse.getJobs(); - - RollableIndexCaps docsPattern = rolledPatterns.get("rollup"); - - // indexName will be "rollup", the target index we requested - String indexName = docsPattern.getIndexName(); - - // Each index pattern can have multiple jobs that rolled it up, so `getJobCaps()` - // returns a list of jobs that rolled up the pattern - List rollupJobs = docsPattern.getJobCaps(); - RollupJobCaps jobCaps = rollupJobs.get(0); - - // jobID is the identifier we used when we created the job (e.g. `job1`) - String jobID = jobCaps.getJobID(); - - // rollupIndex is the location that the job stored it's rollup docs (e.g. `rollup`) - String rollupIndex = jobCaps.getRollupIndex(); - - // Finally, fieldCaps are the capabilities of individual fields in the config - // The key is the field name, and the value is a RollupFieldCaps object which - // provides more info. - Map fieldCaps = jobCaps.getFieldCaps(); - - // If we retrieve the "timestamp" field, it returns a list of maps. Each list - // item represents a different aggregation that can be run against the "timestamp" - // field, and any additional details specific to that agg (interval, etc) - List> timestampCaps = fieldCaps.get("timestamp").getAggs(); - logger.error(timestampCaps.get(0).toString()); - assert timestampCaps.get(0).toString().equals("{agg=date_histogram, fixed_interval=1h, delay=7d, time_zone=UTC}"); - - // In contrast to the timestamp field, the temperature field has multiple aggs configured - List> temperatureCaps = fieldCaps.get("temperature").getAggs(); - assert temperatureCaps.toString().equals("[{agg=min}, {agg=max}, {agg=sum}]"); - //end::x-pack-rollup-get-rollup-index-caps-response - - assertThat(indexName, equalTo("rollup")); - assertThat(jobID, equalTo("job_1")); - assertThat(rollupIndex, equalTo("rollup")); - assertThat(fieldCaps.size(), equalTo(8)); - - // tag::x-pack-rollup-get-rollup-index-caps-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetRollupIndexCapsResponse response) { - - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-rollup-get-rollup-index-caps-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-rollup-get-rollup-index-caps-execute-async - client.rollup().getRollupIndexCapabilitiesAsync(getRollupIndexCapsRequest, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-rollup-get-rollup-index-caps-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testDeleteRollupJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - String id = "job_2"; - - // tag::rollup-delete-job-request - DeleteRollupJobRequest request = new DeleteRollupJobRequest(id); // <1> - // end::rollup-delete-job-request - try { - // tag::rollup-delete-job-execute - AcknowledgedResponse response = client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); - // end::rollup-delete-job-execute - - // tag::rollup-delete-job-response - response.isAcknowledged(); // <1> - // end::rollup-delete-job-response - } catch (Exception e) { - // Swallow any exception, this test does not test actually cancelling. - } - - // tag::rollup-delete-job-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - boolean acknowledged = response.isAcknowledged(); // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::rollup-delete-job-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::rollup-delete-job-execute-async - client.rollup().deleteRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::rollup-delete-job-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } -} 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 deleted file mode 100644 index eff8060f7881..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java +++ /dev/null @@ -1,1559 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.apache.lucene.search.Explanation; -import org.apache.lucene.search.TotalHits; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.bulk.BulkRequest; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.explain.ExplainRequest; -import org.elasticsearch.action.explain.ExplainResponse; -import org.elasticsearch.action.fieldcaps.FieldCapabilities; -import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; -import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.search.ClearScrollRequest; -import org.elasticsearch.action.search.ClearScrollResponse; -import org.elasticsearch.action.search.ClosePointInTimeRequest; -import org.elasticsearch.action.search.MultiSearchRequest; -import org.elasticsearch.action.search.MultiSearchResponse; -import org.elasticsearch.action.search.OpenPointInTimeRequest; -import org.elasticsearch.action.search.OpenPointInTimeResponse; -import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchScrollRequest; -import org.elasticsearch.action.search.ShardSearchFailure; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.WriteRequest; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.CountRequest; -import org.elasticsearch.client.core.CountResponse; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.CreateIndexResponse; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.document.DocumentField; -import org.elasticsearch.common.text.Text; -import org.elasticsearch.common.unit.Fuzziness; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.get.GetResult; -import org.elasticsearch.index.query.MatchQueryBuilder; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.rankeval.EvalQueryQuality; -import org.elasticsearch.index.rankeval.EvaluationMetric; -import org.elasticsearch.index.rankeval.MetricDetail; -import org.elasticsearch.index.rankeval.PrecisionAtK; -import org.elasticsearch.index.rankeval.RankEvalRequest; -import org.elasticsearch.index.rankeval.RankEvalResponse; -import org.elasticsearch.index.rankeval.RankEvalSpec; -import org.elasticsearch.index.rankeval.RatedDocument; -import org.elasticsearch.index.rankeval.RatedRequest; -import org.elasticsearch.index.rankeval.RatedSearchHit; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.script.ScriptType; -import org.elasticsearch.script.mustache.MultiSearchTemplateRequest; -import org.elasticsearch.script.mustache.MultiSearchTemplateResponse; -import org.elasticsearch.script.mustache.MultiSearchTemplateResponse.Item; -import org.elasticsearch.script.mustache.SearchTemplateRequest; -import org.elasticsearch.script.mustache.SearchTemplateResponse; -import org.elasticsearch.search.Scroll; -import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHits; -import org.elasticsearch.search.aggregations.Aggregation; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.Aggregations; -import org.elasticsearch.search.aggregations.bucket.range.Range; -import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; -import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.Avg; -import org.elasticsearch.search.builder.PointInTimeBuilder; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.fetch.subphase.FetchSourceContext; -import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; -import org.elasticsearch.search.fetch.subphase.highlight.HighlightField; -import org.elasticsearch.search.profile.ProfileResult; -import org.elasticsearch.search.profile.SearchProfileShardResult; -import org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult; -import org.elasticsearch.search.profile.query.CollectorResult; -import org.elasticsearch.search.profile.query.QueryProfileShardResult; -import org.elasticsearch.search.sort.FieldSortBuilder; -import org.elasticsearch.search.sort.ScoreSortBuilder; -import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.search.suggest.Suggest; -import org.elasticsearch.search.suggest.SuggestBuilder; -import org.elasticsearch.search.suggest.SuggestBuilders; -import org.elasticsearch.search.suggest.SuggestionBuilder; -import org.elasticsearch.search.suggest.term.TermSuggestion; -import org.elasticsearch.xcontent.XContentFactory; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; - -/** - * Documentation for search APIs in the high level java client. - * Code wrapped in {@code tag} and {@code end} tags is included in the docs. - */ -@SuppressWarnings("removal") -public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { - - @SuppressWarnings({ "unused", "unchecked" }) - public void testSearch() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - { - // tag::search-request-basic - SearchRequest searchRequest = new SearchRequest(); // <1> - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); // <2> - searchSourceBuilder.query(QueryBuilders.matchAllQuery()); // <3> - searchRequest.source(searchSourceBuilder); // <4> - // end::search-request-basic - } - { - // tag::search-request-indices - SearchRequest searchRequest = new SearchRequest("posts"); // <1> - // end::search-request-indices - // tag::search-request-routing - searchRequest.routing("routing"); // <1> - // end::search-request-routing - // tag::search-request-indicesOptions - searchRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::search-request-indicesOptions - // tag::search-request-preference - searchRequest.preference("_local"); // <1> - // end::search-request-preference - assertNotNull(client.search(searchRequest, IGNORE_THROTTLED_WARNING)); - } - { - // tag::search-source-basics - SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); // <1> - sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy")); // <2> - sourceBuilder.from(0); // <3> - sourceBuilder.size(5); // <4> - sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS)); // <5> - // end::search-source-basics - - // tag::search-source-sorting - sourceBuilder.sort(new ScoreSortBuilder().order(SortOrder.DESC)); // <1> - sourceBuilder.sort(new FieldSortBuilder("id").order(SortOrder.ASC)); // <2> - // end::search-source-sorting - - // tag::search-source-filtering-off - sourceBuilder.fetchSource(false); - // end::search-source-filtering-off - // tag::search-source-filtering-includes - String[] includeFields = new String[] {"title", "innerObject.*"}; - String[] excludeFields = new String[] {"user"}; - sourceBuilder.fetchSource(includeFields, excludeFields); - // end::search-source-filtering-includes - sourceBuilder.fetchSource(true); - - // tag::search-source-setter - SearchRequest searchRequest = new SearchRequest(); - searchRequest.indices("posts"); - searchRequest.source(sourceBuilder); - // end::search-source-setter - - // tag::search-execute - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - // end::search-execute - - // tag::search-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(SearchResponse searchResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::search-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::search-execute-async - client.searchAsync(searchRequest, RequestOptions.DEFAULT, listener); // <1> - // end::search-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // tag::search-response-1 - RestStatus status = searchResponse.status(); - TimeValue took = searchResponse.getTook(); - Boolean terminatedEarly = searchResponse.isTerminatedEarly(); - boolean timedOut = searchResponse.isTimedOut(); - // end::search-response-1 - - // tag::search-response-2 - int totalShards = searchResponse.getTotalShards(); - int successfulShards = searchResponse.getSuccessfulShards(); - int failedShards = searchResponse.getFailedShards(); - for (ShardSearchFailure failure : searchResponse.getShardFailures()) { - // failures should be handled here - } - // end::search-response-2 - assertNotNull(searchResponse); - - // tag::search-hits-get - SearchHits hits = searchResponse.getHits(); - // end::search-hits-get - // tag::search-hits-info - TotalHits totalHits = hits.getTotalHits(); - // the total number of hits, must be interpreted in the context of totalHits.relation - long numHits = totalHits.value; - // whether the number of hits is accurate (EQUAL_TO) or a lower bound of the total (GREATER_THAN_OR_EQUAL_TO) - TotalHits.Relation relation = totalHits.relation; - float maxScore = hits.getMaxScore(); - // end::search-hits-info - // tag::search-hits-singleHit - SearchHit[] searchHits = hits.getHits(); - for (SearchHit hit : searchHits) { - // do something with the SearchHit - } - // end::search-hits-singleHit - for (SearchHit hit : searchHits) { - // tag::search-hits-singleHit-properties - String index = hit.getIndex(); - String id = hit.getId(); - float score = hit.getScore(); - // end::search-hits-singleHit-properties - // tag::search-hits-singleHit-source - String sourceAsString = hit.getSourceAsString(); - Map sourceAsMap = hit.getSourceAsMap(); - String documentTitle = (String) sourceAsMap.get("title"); - List users = (List) sourceAsMap.get("user"); - Map innerObject = - (Map) sourceAsMap.get("innerObject"); - // end::search-hits-singleHit-source - } - assertEquals(3, numHits); - assertEquals(TotalHits.Relation.EQUAL_TO, relation); - assertNotNull(hits.getHits()[0].getSourceAsString()); - assertNotNull(hits.getHits()[0].getSourceAsMap().get("title")); - assertNotNull(hits.getHits()[0].getSourceAsMap().get("innerObject")); - assertNull(hits.getHits()[0].getSourceAsMap().get("user")); - } - } - - @SuppressWarnings("unused") - public void testBuildingSearchQueries() { - RestHighLevelClient client = highLevelClient(); - { - // tag::search-query-builder-ctor - MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("user", "kimchy"); // <1> - // end::search-query-builder-ctor - // tag::search-query-builder-options - matchQueryBuilder.fuzziness(Fuzziness.AUTO); // <1> - matchQueryBuilder.prefixLength(3); // <2> - matchQueryBuilder.maxExpansions(10); // <3> - // end::search-query-builder-options - } - { - // tag::search-query-builders - QueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("user", "kimchy") - .fuzziness(Fuzziness.AUTO) - .prefixLength(3) - .maxExpansions(10); - // end::search-query-builders - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - // tag::search-query-setter - searchSourceBuilder.query(matchQueryBuilder); - // end::search-query-setter - } - } - - @SuppressWarnings({ "unused" }) - public void testSearchRequestAggregations() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("posts").id("1").source(XContentType.JSON, "company", "Elastic", "age", 20)); - request.add(new IndexRequest("posts").id("2").source(XContentType.JSON, "company", "Elastic", "age", 30)); - request.add(new IndexRequest("posts").id("3").source(XContentType.JSON, "company", "Elastic", "age", 40)); - request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - } - { - SearchRequest searchRequest = new SearchRequest(); - // tag::search-request-aggregations - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - TermsAggregationBuilder aggregation = AggregationBuilders.terms("by_company") - .field("company.keyword"); - aggregation.subAggregation(AggregationBuilders.avg("average_age") - .field("age")); - searchSourceBuilder.aggregation(aggregation); - // end::search-request-aggregations - searchSourceBuilder.query(QueryBuilders.matchAllQuery()); - searchRequest.source(searchSourceBuilder); - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - { - // tag::search-request-aggregations-get - Aggregations aggregations = searchResponse.getAggregations(); - Terms byCompanyAggregation = aggregations.get("by_company"); // <1> - Bucket elasticBucket = byCompanyAggregation.getBucketByKey("Elastic"); // <2> - Avg averageAge = elasticBucket.getAggregations().get("average_age"); // <3> - double avg = averageAge.getValue(); - // end::search-request-aggregations-get - - try { - // tag::search-request-aggregations-get-wrongCast - Range range = aggregations.get("by_company"); // <1> - // end::search-request-aggregations-get-wrongCast - } catch (ClassCastException ex) { - String message = ex.getMessage(); - assertThat(message, containsString("org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms")); - assertThat(message, containsString("org.elasticsearch.search.aggregations.bucket.range.Range")); - } - assertEquals(3, elasticBucket.getDocCount()); - assertEquals(30, avg, 0.0); - } - Aggregations aggregations = searchResponse.getAggregations(); - { - // tag::search-request-aggregations-asMap - Map aggregationMap = aggregations.getAsMap(); - Terms companyAggregation = (Terms) aggregationMap.get("by_company"); - // end::search-request-aggregations-asMap - } - { - // tag::search-request-aggregations-asList - List aggregationList = aggregations.asList(); - // end::search-request-aggregations-asList - } - { - // tag::search-request-aggregations-iterator - for (Aggregation agg : aggregations) { - String type = agg.getType(); - if (type.equals(TermsAggregationBuilder.NAME)) { - Bucket elasticBucket = ((Terms) agg).getBucketByKey("Elastic"); - long numberOfDocs = elasticBucket.getDocCount(); - } - } - // end::search-request-aggregations-iterator - } - } - } - - @SuppressWarnings({ "unused", "rawtypes" }) - public void testSearchRequestSuggestions() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("posts").id("1").source(XContentType.JSON, "user", "kimchy")); - request.add(new IndexRequest("posts").id("2").source(XContentType.JSON, "user", "javanna")); - request.add(new IndexRequest("posts").id("3").source(XContentType.JSON, "user", "tlrx")); - request.add(new IndexRequest("posts").id("4").source(XContentType.JSON, "user", "cbuescher")); - request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - } - { - SearchRequest searchRequest = new SearchRequest(); - // tag::search-request-suggestion - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - SuggestionBuilder termSuggestionBuilder = - SuggestBuilders.termSuggestion("user").text("kmichy"); // <1> - SuggestBuilder suggestBuilder = new SuggestBuilder(); - suggestBuilder.addSuggestion("suggest_user", termSuggestionBuilder); // <2> - searchSourceBuilder.suggest(suggestBuilder); - // end::search-request-suggestion - searchRequest.source(searchSourceBuilder); - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - { - // tag::search-request-suggestion-get - Suggest suggest = searchResponse.getSuggest(); // <1> - TermSuggestion termSuggestion = suggest.getSuggestion("suggest_user"); // <2> - for (TermSuggestion.Entry entry : termSuggestion.getEntries()) { // <3> - for (TermSuggestion.Entry.Option option : entry) { // <4> - String suggestText = option.getText().string(); - } - } - // end::search-request-suggestion-get - assertEquals(1, termSuggestion.getEntries().size()); - assertEquals(1, termSuggestion.getEntries().get(0).getOptions().size()); - assertEquals("kimchy", termSuggestion.getEntries().get(0).getOptions().get(0).getText().string()); - } - } - } - - @SuppressWarnings("unused") - public void testSearchRequestHighlighting() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - BulkRequest request = new BulkRequest(); - request.add( - new IndexRequest("posts").id("1") - .source( - XContentType.JSON, - "title", - "In which order are my Elasticsearch queries executed?", - "user", - Arrays.asList("kimchy", "luca"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - request.add( - new IndexRequest("posts").id("2") - .source( - XContentType.JSON, - "title", - "Current status and upcoming changes in Elasticsearch", - "user", - Arrays.asList("kimchy", "christoph"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - request.add( - new IndexRequest("posts").id("3") - .source( - XContentType.JSON, - "title", - "The Future of Federated Search in Elasticsearch", - "user", - Arrays.asList("kimchy", "tanguy"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - } - { - SearchRequest searchRequest = new SearchRequest(); - // tag::search-request-highlighting - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - HighlightBuilder highlightBuilder = new HighlightBuilder(); // <1> - HighlightBuilder.Field highlightTitle = - new HighlightBuilder.Field("title"); // <2> - highlightTitle.highlighterType("unified"); // <3> - highlightBuilder.field(highlightTitle); // <4> - HighlightBuilder.Field highlightUser = new HighlightBuilder.Field("user"); - highlightBuilder.field(highlightUser); - searchSourceBuilder.highlighter(highlightBuilder); - // end::search-request-highlighting - searchSourceBuilder.query( - QueryBuilders.boolQuery().should(matchQuery("title", "Elasticsearch")).should(matchQuery("user", "kimchy")) - ); - searchRequest.source(searchSourceBuilder); - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - { - // tag::search-request-highlighting-get - SearchHits hits = searchResponse.getHits(); - for (SearchHit hit : hits.getHits()) { - Map highlightFields = hit.getHighlightFields(); - HighlightField highlight = highlightFields.get("title"); // <1> - Text[] fragments = highlight.fragments(); // <2> - String fragmentString = fragments[0].string(); - } - // end::search-request-highlighting-get - hits = searchResponse.getHits(); - for (SearchHit hit : hits.getHits()) { - Map highlightFields = hit.getHighlightFields(); - HighlightField highlight = highlightFields.get("title"); - Text[] fragments = highlight.fragments(); - assertEquals(1, fragments.length); - assertThat(fragments[0].string(), containsString("Elasticsearch")); - highlight = highlightFields.get("user"); - fragments = highlight.fragments(); - assertEquals(1, fragments.length); - assertThat(fragments[0].string(), containsString("kimchy")); - } - } - - } - } - - @SuppressWarnings("unused") - public void testSearchRequestProfiling() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - IndexRequest request = new IndexRequest("posts").id("1").source(XContentType.JSON, "tags", "elasticsearch", "comments", 123); - request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); - IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT); - assertSame(RestStatus.CREATED, indexResponse.status()); - } - { - SearchRequest searchRequest = new SearchRequest(); - // tag::search-request-profiling - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - searchSourceBuilder.profile(true); - // end::search-request-profiling - searchSourceBuilder.query(QueryBuilders.termQuery("tags", "elasticsearch")); - searchSourceBuilder.aggregation(AggregationBuilders.histogram("by_comments").field("comments").interval(100)); - searchRequest.source(searchSourceBuilder); - - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - // tag::search-request-profiling-get - Map profilingResults = - searchResponse.getProfileResults(); // <1> - for (Map.Entry profilingResult : profilingResults.entrySet()) { // <2> - String key = profilingResult.getKey(); // <3> - SearchProfileShardResult profileShardResult = profilingResult.getValue(); // <4> - } - // end::search-request-profiling-get - - SearchProfileShardResult profileShardResult = profilingResults.values().iterator().next(); - assertNotNull(profileShardResult); - - // tag::search-request-profiling-queries - List queryProfileShardResults = - profileShardResult.getQueryProfileResults(); // <1> - for (QueryProfileShardResult queryProfileResult : queryProfileShardResults) { // <2> - - } - // end::search-request-profiling-queries - assertThat(queryProfileShardResults.size(), equalTo(1)); - - for (QueryProfileShardResult queryProfileResult : queryProfileShardResults) { - // tag::search-request-profiling-queries-results - for (ProfileResult profileResult : queryProfileResult.getQueryResults()) { // <1> - String queryName = profileResult.getQueryName(); // <2> - long queryTimeInMillis = profileResult.getTime(); // <3> - List profiledChildren = profileResult.getProfiledChildren(); // <4> - } - // end::search-request-profiling-queries-results - - // tag::search-request-profiling-queries-collectors - CollectorResult collectorResult = queryProfileResult.getCollectorResult(); // <1> - String collectorName = collectorResult.getName(); // <2> - Long collectorTimeInMillis = collectorResult.getTime(); // <3> - List profiledChildren = collectorResult.getProfiledChildren(); // <4> - // end::search-request-profiling-queries-collectors - } - - // tag::search-request-profiling-aggs - AggregationProfileShardResult aggsProfileResults = - profileShardResult.getAggregationProfileResults(); // <1> - for (ProfileResult profileResult : aggsProfileResults.getProfileResults()) { // <2> - String aggName = profileResult.getQueryName(); // <3> - long aggTimeInMillis = profileResult.getTime(); // <4> - List profiledChildren = profileResult.getProfiledChildren(); // <5> - } - // end::search-request-profiling-aggs - assertThat(aggsProfileResults.getProfileResults().size(), equalTo(1)); - } - } - - public void testScroll() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - BulkRequest request = new BulkRequest(); - request.add( - new IndexRequest("posts").id("1") - .source(XContentType.JSON, "title", "In which order are my Elasticsearch queries executed?") - ); - request.add( - new IndexRequest("posts").id("2").source(XContentType.JSON, "title", "Current status and upcoming changes in Elasticsearch") - ); - request.add( - new IndexRequest("posts").id("3").source(XContentType.JSON, "title", "The Future of Federated Search in Elasticsearch") - ); - request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - } - { - int size = 1; - // tag::search-scroll-init - SearchRequest searchRequest = new SearchRequest("posts"); - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - searchSourceBuilder.query(matchQuery("title", "Elasticsearch")); - searchSourceBuilder.size(size); // <1> - searchRequest.source(searchSourceBuilder); - searchRequest.scroll(TimeValue.timeValueMinutes(1L)); // <2> - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - String scrollId = searchResponse.getScrollId(); // <3> - SearchHits hits = searchResponse.getHits(); // <4> - // end::search-scroll-init - assertEquals(3, hits.getTotalHits().value); - assertEquals(1, hits.getHits().length); - assertNotNull(scrollId); - - // tag::search-scroll2 - SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <1> - scrollRequest.scroll(TimeValue.timeValueSeconds(30)); - SearchResponse searchScrollResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT); - scrollId = searchScrollResponse.getScrollId(); // <2> - hits = searchScrollResponse.getHits(); // <3> - assertEquals(3, hits.getTotalHits().value); - assertEquals(1, hits.getHits().length); - assertNotNull(scrollId); - // end::search-scroll2 - - ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); - clearScrollRequest.addScrollId(scrollId); - ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT); - assertTrue(clearScrollResponse.isSucceeded()); - } - { - SearchRequest searchRequest = new SearchRequest(); - searchRequest.scroll("60s"); - - SearchResponse initialSearchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - String scrollId = initialSearchResponse.getScrollId(); - - SearchScrollRequest scrollRequest = new SearchScrollRequest(); - scrollRequest.scrollId(scrollId); - - // tag::scroll-request-arguments - scrollRequest.scroll(TimeValue.timeValueSeconds(60L)); // <1> - scrollRequest.scroll("60s"); // <2> - // end::scroll-request-arguments - - // tag::search-scroll-execute-sync - SearchResponse searchResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT); - // end::search-scroll-execute-sync - - assertEquals(0, searchResponse.getFailedShards()); - assertEquals(3L, searchResponse.getHits().getTotalHits().value); - - // tag::search-scroll-execute-listener - ActionListener scrollListener = - new ActionListener() { - @Override - public void onResponse(SearchResponse searchResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::search-scroll-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - scrollListener = new LatchedActionListener<>(scrollListener, latch); - - // tag::search-scroll-execute-async - client.scrollAsync(scrollRequest, RequestOptions.DEFAULT, scrollListener); // <1> - // end::search-scroll-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // tag::clear-scroll-request - ClearScrollRequest request = new ClearScrollRequest(); // <1> - request.addScrollId(scrollId); // <2> - // end::clear-scroll-request - - // tag::clear-scroll-add-scroll-id - request.addScrollId(scrollId); - // end::clear-scroll-add-scroll-id - - List scrollIds = Collections.singletonList(scrollId); - - // tag::clear-scroll-add-scroll-ids - request.setScrollIds(scrollIds); - // end::clear-scroll-add-scroll-ids - - // tag::clear-scroll-execute - ClearScrollResponse response = client.clearScroll(request, RequestOptions.DEFAULT); - // end::clear-scroll-execute - - // tag::clear-scroll-response - boolean success = response.isSucceeded(); // <1> - int released = response.getNumFreed(); // <2> - // end::clear-scroll-response - assertTrue(success); - assertThat(released, greaterThan(0)); - - // tag::clear-scroll-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ClearScrollResponse clearScrollResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::clear-scroll-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch clearScrollLatch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, clearScrollLatch); - - // tag::clear-scroll-execute-async - client.clearScrollAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clear-scroll-execute-async - - assertTrue(clearScrollLatch.await(30L, TimeUnit.SECONDS)); - } - { - // tag::search-scroll-example - final Scroll scroll = new Scroll(TimeValue.timeValueMinutes(1L)); - SearchRequest searchRequest = new SearchRequest("posts"); - searchRequest.scroll(scroll); - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - searchSourceBuilder.query(matchQuery("title", "Elasticsearch")); - searchRequest.source(searchSourceBuilder); - - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); // <1> - String scrollId = searchResponse.getScrollId(); - SearchHit[] searchHits = searchResponse.getHits().getHits(); - - while (searchHits != null && searchHits.length > 0) { // <2> - // <3> - SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <4> - scrollRequest.scroll(scroll); - searchResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT); - scrollId = searchResponse.getScrollId(); - searchHits = searchResponse.getHits().getHits(); - } - - ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); // <5> - clearScrollRequest.addScrollId(scrollId); - ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT); - boolean succeeded = clearScrollResponse.isSucceeded(); - // end::search-scroll-example - assertTrue(succeeded); - } - } - - public void testPointInTime() throws Exception { - RestHighLevelClient client = highLevelClient(); - BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("posts").id("1").source(XContentType.JSON, "lang", "Java")); - request.add(new IndexRequest("posts").id("2").source(XContentType.JSON, "lang", "Python")); - request.add(new IndexRequest("posts").id("3").source(XContentType.JSON, "lang", "Go")); - request.add(new IndexRequest("posts").id("4").source(XContentType.JSON, "lang", "Rust")); - request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - - // tag::open-point-in-time - OpenPointInTimeRequest openRequest = new OpenPointInTimeRequest("posts"); // <1> - openRequest.keepAlive(TimeValue.timeValueMinutes(30)); // <2> - OpenPointInTimeResponse openResponse = client.openPointInTime(openRequest, RequestOptions.DEFAULT); - String pitId = openResponse.getPointInTimeId(); // <3> - // end::open-point-in-time - assertNotNull(pitId); - - // tag::search-point-in-time - SearchRequest searchRequest = new SearchRequest(); - final PointInTimeBuilder pointInTimeBuilder = new PointInTimeBuilder(pitId); // <1> - pointInTimeBuilder.setKeepAlive("2m"); // <2> - searchRequest.source(new SearchSourceBuilder().pointInTimeBuilder(pointInTimeBuilder)); // <3> - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - // 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); - boolean succeeded = closeResponse.isSucceeded(); - // end::close-point-in-time - assertTrue(succeeded); - - // Open a point in time with optional arguments - { - openRequest = new OpenPointInTimeRequest("posts").keepAlive(TimeValue.timeValueMinutes(10)); - // tag::open-point-in-time-indices-option - openRequest.indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED); // <1> - // end::open-point-in-time-indices-option - - // tag::open-point-in-time-routing - openRequest.routing("routing"); // <1> - // end::open-point-in-time-routing - - // tag::open-point-in-time-preference - openRequest.preference("_local"); // <1> - // end::open-point-in-time-preference - - openResponse = client.openPointInTime(openRequest, IGNORE_THROTTLED_WARNING); - pitId = openResponse.getPointInTimeId(); - client.closePointInTime(new ClosePointInTimeRequest(pitId), RequestOptions.DEFAULT); - } - } - - public void testSearchTemplateWithInlineScript() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - - // tag::search-template-request-inline - SearchTemplateRequest request = new SearchTemplateRequest(); - request.setRequest(new SearchRequest("posts")); // <1> - - request.setScriptType(ScriptType.INLINE); - request.setScript( // <2> - """ - { - "query": { "match": { "{{field}}": "{{value}}" } }, - "size": "{{size}}" - }"""); - - Map scriptParams = new HashMap<>(); - scriptParams.put("field", "title"); - scriptParams.put("value", "elasticsearch"); - scriptParams.put("size", 5); - request.setScriptParams(scriptParams); // <3> - // end::search-template-request-inline - - // tag::search-template-response - SearchTemplateResponse response = client.searchTemplate(request, RequestOptions.DEFAULT); - SearchResponse searchResponse = response.getResponse(); - // end::search-template-response - - assertNotNull(searchResponse); - assertTrue(searchResponse.getHits().getTotalHits().value > 0); - - // tag::render-search-template-request - request.setSimulate(true); // <1> - // end::render-search-template-request - - // tag::render-search-template-response - SearchTemplateResponse renderResponse = client.searchTemplate(request, RequestOptions.DEFAULT); - BytesReference source = renderResponse.getSource(); // <1> - // end::render-search-template-response - - assertNotNull(source); - assertEquals( - ("{ \"size\" : \"5\", \"query\": { \"match\" : { \"title\" : \"elasticsearch\" } }}").replaceAll("\\s+", ""), - source.utf8ToString() - ); - } - - public void testSearchTemplateWithStoredScript() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - RestClient restClient = client(); - - registerQueryScript(restClient); - - // tag::search-template-request-stored - SearchTemplateRequest request = new SearchTemplateRequest(); - request.setRequest(new SearchRequest("posts")); - - request.setScriptType(ScriptType.STORED); - request.setScript("title_search"); - - Map params = new HashMap<>(); - params.put("field", "title"); - params.put("value", "elasticsearch"); - params.put("size", 5); - request.setScriptParams(params); - // end::search-template-request-stored - - // tag::search-template-request-options - request.setExplain(true); - request.setProfile(true); - // end::search-template-request-options - - // tag::search-template-execute - SearchTemplateResponse response = client.searchTemplate(request, RequestOptions.DEFAULT); - // end::search-template-execute - - SearchResponse searchResponse = response.getResponse(); - assertNotNull(searchResponse); - assertTrue(searchResponse.getHits().getTotalHits().value > 0); - - // tag::search-template-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(SearchTemplateResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::search-template-execute-listener - - // Replace the empty listener by a blocking listener for tests. - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::search-template-execute-async - client.searchTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::search-template-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - @SuppressWarnings("unused") - public void testMultiSearchTemplateWithInlineScript() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - - // tag::multi-search-template-request-inline - String [] searchTerms = {"elasticsearch", "logstash", "kibana"}; - - MultiSearchTemplateRequest multiRequest = new MultiSearchTemplateRequest(); // <1> - for (String searchTerm : searchTerms) { - SearchTemplateRequest request = new SearchTemplateRequest(); // <2> - request.setRequest(new SearchRequest("posts")); - - request.setScriptType(ScriptType.INLINE); - request.setScript( - """ - { - "query": { "match" : { "{{field}}" : "{{value}}" } }, - "size" : "{{size}}" - }"""); - - Map scriptParams = new HashMap<>(); - scriptParams.put("field", "title"); - scriptParams.put("value", searchTerm); - scriptParams.put("size", 5); - request.setScriptParams(scriptParams); - - multiRequest.add(request); // <3> - } - // end::multi-search-template-request-inline - - // tag::multi-search-template-request-sync - MultiSearchTemplateResponse multiResponse = client.msearchTemplate(multiRequest, RequestOptions.DEFAULT); - // end::multi-search-template-request-sync - - // tag::multi-search-template-response - for (Item item : multiResponse.getResponses()) { // <1> - if (item.isFailure()) { - String error = item.getFailureMessage(); // <2> - } else { - SearchTemplateResponse searchTemplateResponse = item.getResponse(); // <3> - SearchResponse searchResponse = searchTemplateResponse.getResponse(); - searchResponse.getHits(); - } - } - // end::multi-search-template-response - - assertNotNull(multiResponse); - assertEquals(searchTerms.length, multiResponse.getResponses().length); - assertNotNull(multiResponse.getResponses()[0]); - SearchResponse searchResponse = multiResponse.getResponses()[0].getResponse().getResponse(); - assertTrue(searchResponse.getHits().getTotalHits().value > 0); - - } - - public void testMultiSearchTemplateWithStoredScript() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - RestClient restClient = client(); - - registerQueryScript(restClient); - - // tag::multi-search-template-request-stored - MultiSearchTemplateRequest multiRequest = new MultiSearchTemplateRequest(); - - String [] searchTerms = {"elasticsearch", "logstash", "kibana"}; - for (String searchTerm : searchTerms) { - - SearchTemplateRequest request = new SearchTemplateRequest(); - request.setRequest(new SearchRequest("posts")); - - request.setScriptType(ScriptType.STORED); - request.setScript("title_search"); - - Map params = new HashMap<>(); - params.put("field", "title"); - params.put("value", searchTerm); - params.put("size", 5); - request.setScriptParams(params); - multiRequest.add(request); - } - // end::multi-search-template-request-stored - - // tag::multi-search-template-execute - MultiSearchTemplateResponse multiResponse = client.msearchTemplate(multiRequest, RequestOptions.DEFAULT); - // end::multi-search-template-execute - - assertNotNull(multiResponse); - assertEquals(searchTerms.length, multiResponse.getResponses().length); - assertNotNull(multiResponse.getResponses()[0]); - SearchResponse searchResponse = multiResponse.getResponses()[0].getResponse().getResponse(); - assertTrue(searchResponse.getHits().getTotalHits().value > 0); - - // tag::multi-search-template-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(MultiSearchTemplateResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::multi-search-template-execute-listener - - // Replace the empty listener by a blocking listener for tests. - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::multi-search-template-execute-async - client.msearchTemplateAsync(multiRequest, RequestOptions.DEFAULT, listener); - // end::multi-search-template-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - protected void registerQueryScript(RestClient restClient) throws IOException { - // tag::register-script - Request scriptRequest = new Request("POST", "_scripts/title_search"); - scriptRequest.setJsonEntity(""" - { - "script": { - "lang": "mustache", - "source": { - "query": { "match": { "{{field}}": "{{value}}" } }, - "size": "{{size}}" - } - } - }"""); - Response scriptResponse = restClient.performRequest(scriptRequest); - // end::register-script - assertEquals(RestStatus.OK.getStatus(), scriptResponse.getStatusLine().getStatusCode()); - } - - public void testExplain() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - - // tag::explain-request - ExplainRequest request = new ExplainRequest("contributors", "1"); - request.query(QueryBuilders.termQuery("user", "tanguy")); - // end::explain-request - - // tag::explain-request-routing - request.routing("routing"); // <1> - // end::explain-request-routing - - // tag::explain-request-preference - request.preference("_local"); // <1> - // end::explain-request-preference - - // tag::explain-request-source - request.fetchSourceContext(new FetchSourceContext(true, new String[]{"user"}, null)); // <1> - // end::explain-request-source - - // tag::explain-request-stored-field - request.storedFields(new String[]{"user"}); // <1> - // end::explain-request-stored-field - - // tag::explain-execute - ExplainResponse response = client.explain(request, RequestOptions.DEFAULT); - // end::explain-execute - - // tag::explain-response - String index = response.getIndex(); // <1> - String id = response.getId(); // <2> - boolean exists = response.isExists(); // <3> - boolean match = response.isMatch(); // <4> - boolean hasExplanation = response.hasExplanation(); // <5> - Explanation explanation = response.getExplanation(); // <6> - GetResult getResult = response.getGetResult(); // <7> - // end::explain-response - assertThat(index, equalTo("contributors")); - assertThat(id, equalTo("1")); - assertTrue(exists); - assertTrue(match); - assertTrue(hasExplanation); - assertNotNull(explanation); - assertNotNull(getResult); - - // tag::get-result - Map source = getResult.getSource(); // <1> - Map fields = getResult.getFields(); // <2> - // end::get-result - assertThat(source, equalTo(Collections.singletonMap("user", "tanguy"))); - assertThat(fields.get("user").getValue(), equalTo("tanguy")); - - // tag::explain-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ExplainResponse explainResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::explain-execute-listener - - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::explain-execute-async - client.explainAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::explain-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testFieldCaps() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - - // tag::field-caps-request - FieldCapabilitiesRequest request = new FieldCapabilitiesRequest() - .fields("user") - .indices("posts", "authors", "contributors"); - // end::field-caps-request - - // tag::field-caps-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::field-caps-request-indicesOptions - - RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; - // tag::field-caps-execute - FieldCapabilitiesResponse response = client.fieldCaps(request, requestOptions); - // end::field-caps-execute - - // tag::field-caps-response - Map userResponse = response.getField("user"); // <1> - FieldCapabilities textCapabilities = userResponse.get("keyword"); - - boolean isSearchable = textCapabilities.isSearchable(); - boolean isAggregatable = textCapabilities.isAggregatable(); - - String[] indices = textCapabilities.indices(); // <2> - String[] nonSearchableIndices = textCapabilities.nonSearchableIndices(); // <3> - String[] nonAggregatableIndices = textCapabilities.nonAggregatableIndices();//<4> - // end::field-caps-response - - assertThat(userResponse.keySet(), containsInAnyOrder("keyword", "text")); - - assertTrue(isSearchable); - assertFalse(isAggregatable); - - assertArrayEquals(indices, new String[] { "authors", "contributors" }); - assertNull(nonSearchableIndices); - assertArrayEquals(nonAggregatableIndices, new String[] { "authors" }); - - // tag::field-caps-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(FieldCapabilitiesResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::field-caps-execute-listener - - // Replace the empty listener by a blocking listener for tests. - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::field-caps-execute-async - client.fieldCapsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::field-caps-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testRankEval() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - { - // tag::rank-eval-request-basic - EvaluationMetric metric = new PrecisionAtK(); // <1> - List ratedDocs = new ArrayList<>(); - ratedDocs.add(new RatedDocument("posts", "1", 1)); // <2> - SearchSourceBuilder searchQuery = new SearchSourceBuilder(); - searchQuery.query(QueryBuilders.matchQuery("user", "kimchy"));// <3> - RatedRequest ratedRequest = // <4> - new RatedRequest("kimchy_query", ratedDocs, searchQuery); - List ratedRequests = Arrays.asList(ratedRequest); - RankEvalSpec specification = - new RankEvalSpec(ratedRequests, metric); // <5> - RankEvalRequest request = // <6> - new RankEvalRequest(specification, new String[] { "posts" }); - // end::rank-eval-request-basic - - // tag::rank-eval-execute - RankEvalResponse response = client.rankEval(request, RequestOptions.DEFAULT); - // end::rank-eval-execute - - // tag::rank-eval-response - double evaluationResult = response.getMetricScore(); // <1> - assertEquals(1.0 / 3.0, evaluationResult, 0.0); - Map partialResults = - response.getPartialResults(); - EvalQueryQuality evalQuality = - partialResults.get("kimchy_query"); // <2> - assertEquals("kimchy_query", evalQuality.getId()); - double qualityLevel = evalQuality.metricScore(); // <3> - assertEquals(1.0 / 3.0, qualityLevel, 0.0); - List hitsAndRatings = evalQuality.getHitsAndRatings(); - RatedSearchHit ratedSearchHit = hitsAndRatings.get(2); - assertEquals("3", ratedSearchHit.getSearchHit().getId()); // <4> - assertFalse(ratedSearchHit.getRating().isPresent()); // <5> - MetricDetail metricDetails = evalQuality.getMetricDetails(); - String metricName = metricDetails.getMetricName(); - assertEquals(PrecisionAtK.NAME, metricName); // <6> - PrecisionAtK.Detail detail = (PrecisionAtK.Detail) metricDetails; - assertEquals(1, detail.getRelevantRetrieved()); // <7> - assertEquals(3, detail.getRetrieved()); - // end::rank-eval-response - - // tag::rank-eval-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(RankEvalResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::rank-eval-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::rank-eval-execute-async - client.rankEvalAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::rank-eval-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testMultiSearch() throws Exception { - indexSearchTestData(); - RestHighLevelClient client = highLevelClient(); - { - // tag::multi-search-request-basic - MultiSearchRequest request = new MultiSearchRequest(); // <1> - SearchRequest firstSearchRequest = new SearchRequest(); // <2> - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - searchSourceBuilder.query(QueryBuilders.matchQuery("user", "kimchy")); - firstSearchRequest.source(searchSourceBuilder); - request.add(firstSearchRequest); // <3> - SearchRequest secondSearchRequest = new SearchRequest(); // <4> - searchSourceBuilder = new SearchSourceBuilder(); - searchSourceBuilder.query(QueryBuilders.matchQuery("user", "luca")); - secondSearchRequest.source(searchSourceBuilder); - request.add(secondSearchRequest); - // end::multi-search-request-basic - // tag::multi-search-execute - MultiSearchResponse response = client.msearch(request, RequestOptions.DEFAULT); - // end::multi-search-execute - // tag::multi-search-response - MultiSearchResponse.Item firstResponse = response.getResponses()[0]; // <1> - assertNull(firstResponse.getFailure()); // <2> - SearchResponse searchResponse = firstResponse.getResponse(); // <3> - assertEquals(4, searchResponse.getHits().getTotalHits().value); - MultiSearchResponse.Item secondResponse = response.getResponses()[1]; // <4> - assertNull(secondResponse.getFailure()); - searchResponse = secondResponse.getResponse(); - assertEquals(1, searchResponse.getHits().getTotalHits().value); - // end::multi-search-response - - // tag::multi-search-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(MultiSearchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::multi-search-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::multi-search-execute-async - client.msearchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::multi-search-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - private void indexSearchTestData() throws IOException { - CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("id") - .field("type", "keyword") - .endObject() - .startObject("user") - .field("type", "keyword") - .field("doc_values", "false") - .endObject() - .endObject() - .endObject() - ); - CreateIndexResponse authorsResponse = highLevelClient().indices().create(authorsRequest, RequestOptions.DEFAULT); - assertTrue(authorsResponse.isAcknowledged()); - - CreateIndexRequest reviewersRequest = new CreateIndexRequest("contributors").mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("id") - .field("type", "keyword") - .endObject() - .startObject("user") - .field("type", "keyword") - .field("store", "true") - .endObject() - .endObject() - .endObject() - ); - CreateIndexResponse reviewersResponse = highLevelClient().indices().create(reviewersRequest, RequestOptions.DEFAULT); - assertTrue(reviewersResponse.isAcknowledged()); - - BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.add( - new IndexRequest("posts").id("1") - .source( - XContentType.JSON, - "id", - 1, - "title", - "In which order are my Elasticsearch queries executed?", - "user", - Arrays.asList("kimchy", "luca"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - bulkRequest.add( - new IndexRequest("posts").id("2") - .source( - XContentType.JSON, - "id", - 2, - "title", - "Current status and upcoming changes in Elasticsearch", - "user", - Arrays.asList("kimchy", "christoph"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - bulkRequest.add( - new IndexRequest("posts").id("3") - .source( - XContentType.JSON, - "id", - 3, - "title", - "The Future of Federated Search in Elasticsearch", - "user", - Arrays.asList("kimchy", "tanguy"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - - bulkRequest.add(new IndexRequest("authors").id("1").source(XContentType.JSON, "id", 1, "user", "kimchy")); - bulkRequest.add(new IndexRequest("contributors").id("1").source(XContentType.JSON, "id", 1, "user", "tanguy")); - - bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - } - - @SuppressWarnings({ "unused", "unchecked" }) - public void testCount() throws Exception { - indexCountTestData(); - RestHighLevelClient client = highLevelClient(); - { - // tag::count-request-basic - CountRequest countRequest = new CountRequest(); // <1> - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); // <2> - searchSourceBuilder.query(QueryBuilders.matchAllQuery()); // <3> - countRequest.source(searchSourceBuilder); // <4> - // end::count-request-basic - } - { - // tag::count-request-args - CountRequest countRequest = new CountRequest("blog") // <1> - .routing("routing") // <2> - .indicesOptions(IndicesOptions.lenientExpandOpen()) // <3> - .preference("_local"); // <4> - // end::count-request-args - assertNotNull(client.count(countRequest, IGNORE_THROTTLED_WARNING)); - } - { - // tag::count-source-basics - SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); // <1> - sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy")); // <2> - // end::count-source-basics - - // tag::count-source-setter - CountRequest countRequest = new CountRequest(); - countRequest.indices("blog", "author"); - countRequest.source(sourceBuilder); - // end::count-source-setter - - // tag::count-execute - CountResponse countResponse = client - .count(countRequest, RequestOptions.DEFAULT); - // end::count-execute - - // tag::count-execute-listener - ActionListener listener = - new ActionListener() { - - @Override - public void onResponse(CountResponse countResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::count-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::count-execute-async - client.countAsync(countRequest, RequestOptions.DEFAULT, listener); // <1> - // end::count-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - // tag::count-response-1 - long count = countResponse.getCount(); - RestStatus status = countResponse.status(); - Boolean terminatedEarly = countResponse.isTerminatedEarly(); - // end::count-response-1 - - // tag::count-response-2 - int totalShards = countResponse.getTotalShards(); - int skippedShards = countResponse.getSkippedShards(); - int successfulShards = countResponse.getSuccessfulShards(); - int failedShards = countResponse.getFailedShards(); - for (ShardSearchFailure failure : countResponse.getShardFailures()) { - // failures should be handled here - } - // end::count-response-2 - assertNotNull(countResponse); - assertEquals(4, countResponse.getCount()); - } - } - - private static void indexCountTestData() throws IOException { - CreateIndexRequest authorsRequest = new CreateIndexRequest("author").mapping( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject("user") - .field("type", "keyword") - .field("doc_values", "false") - .endObject() - .endObject() - .endObject() - ); - CreateIndexResponse authorsResponse = highLevelClient().indices().create(authorsRequest, RequestOptions.DEFAULT); - assertTrue(authorsResponse.isAcknowledged()); - - BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.add( - new IndexRequest("blog").id("1") - .source( - XContentType.JSON, - "title", - "Doubling Down on Open?", - "user", - Collections.singletonList("kimchy"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - bulkRequest.add( - new IndexRequest("blog").id("2") - .source( - XContentType.JSON, - "title", - "Swiftype Joins Forces with Elastic", - "user", - Arrays.asList("kimchy", "matt"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - bulkRequest.add( - new IndexRequest("blog").id("3") - .source( - XContentType.JSON, - "title", - "On Net Neutrality", - "user", - Arrays.asList("tyler", "kimchy"), - "innerObject", - Collections.singletonMap("key", "value") - ) - ); - - bulkRequest.add(new IndexRequest("author").id("1").source(XContentType.JSON, "user", "kimchy")); - - bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT); - assertSame(RestStatus.OK, bulkResponse.status()); - assertFalse(bulkResponse.hasFailures()); - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchableSnapshotsDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchableSnapshotsDocumentationIT.java deleted file mode 100644 index 30e80e38beff..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchableSnapshotsDocumentationIT.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.support.WriteRequest; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.CreateIndexResponse; -import org.elasticsearch.client.searchable_snapshots.CachesStatsRequest; -import org.elasticsearch.client.searchable_snapshots.CachesStatsResponse; -import org.elasticsearch.client.searchable_snapshots.CachesStatsResponse.NodeCachesStats; -import org.elasticsearch.client.searchable_snapshots.MountSnapshotRequest; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.repositories.fs.FsRepository; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.snapshots.RestoreInfo; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.is; - -@SuppressWarnings("removal") -public class SearchableSnapshotsDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testMountSnapshot() throws IOException, InterruptedException { - final RestHighLevelClient client = highLevelClient(); - { - final CreateIndexRequest request = new CreateIndexRequest("index"); - final CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); - assertTrue(response.isAcknowledged()); - } - - { - final IndexRequest request = new IndexRequest("index").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{}", XContentType.JSON); - final IndexResponse response = client.index(request, RequestOptions.DEFAULT); - assertThat(response.status(), is(RestStatus.CREATED)); - } - - { - final PutRepositoryRequest request = new PutRepositoryRequest("repository"); - request.settings("{\"location\": \".\"}", XContentType.JSON); - request.type(FsRepository.TYPE); - final AcknowledgedResponse response = client.snapshot().createRepository(request, RequestOptions.DEFAULT); - assertTrue(response.isAcknowledged()); - } - - { - final CreateSnapshotRequest request = new CreateSnapshotRequest("repository", "snapshot").waitForCompletion(true); - final CreateSnapshotResponse response = client.snapshot().create(request, RequestOptions.DEFAULT); - assertThat(response.getSnapshotInfo().status(), is(RestStatus.OK)); - } - - // tag::searchable-snapshots-mount-snapshot-request - final MountSnapshotRequest request = new MountSnapshotRequest( - "repository", // <1> - "snapshot", // <2> - "index" // <3> - ); - request.masterTimeout(TimeValue.timeValueSeconds(30)); // <4> - request.waitForCompletion(true); // <5> - request.storage(MountSnapshotRequest.Storage.FULL_COPY); // <6> - request.renamedIndex("renamed_index"); // <7> - final Settings indexSettings = Settings.builder() - .put("index.number_of_replicas", 0) - .build(); - request.indexSettings(indexSettings); // <8> - request.ignoredIndexSettings( - new String[]{"index.refresh_interval"}); // <9> - // end::searchable-snapshots-mount-snapshot-request - - // tag::searchable-snapshots-mount-snapshot-execute - final RestoreSnapshotResponse response = client - .searchableSnapshots() - .mountSnapshot(request, RequestOptions.DEFAULT); - // end::searchable-snapshots-mount-snapshot-execute - - // tag::searchable-snapshots-mount-snapshot-response - final RestoreInfo restoreInfo = response.getRestoreInfo(); // <1> - // end::searchable-snapshots-mount-snapshot-response - - // tag::searchable-snapshots-mount-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - - @Override - public void onResponse( - final RestoreSnapshotResponse response) { // <1> - final RestoreInfo restoreInfo = response.getRestoreInfo(); - } - - @Override - public void onFailure(final Exception e) { - // <2> - } - - }; - // end::searchable-snapshots-mount-snapshot-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::searchable-snapshots-mount-snapshot-execute-async - client.searchableSnapshots().mountSnapshotAsync( - request, - RequestOptions.DEFAULT, - listener // <1> - ); - // end::searchable-snapshots-mount-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testCachesStatsSnapshot() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - // tag::searchable-snapshots-caches-stats-request - CachesStatsRequest request = new CachesStatsRequest(); // <1> - request = new CachesStatsRequest( // <2> - "eerrtBMtQEisohZzxBLUSw", - "klksqQSSzASDqDMLQ" - ); - // end::searchable-snapshots-caches-stats-request - - // tag::searchable-snapshots-caches-stats-execute - final CachesStatsResponse response = client - .searchableSnapshots() - .cacheStats(request, RequestOptions.DEFAULT); - // end::searchable-snapshots-caches-stats-execute - - // tag::searchable-snapshots-caches-stats-response - final List nodeCachesStats = - response.getNodeCachesStats(); // <1> - // end::searchable-snapshots-caches-stats-response - - // tag::searchable-snapshots-caches-stats-execute-listener - ActionListener listener = - new ActionListener() { - - @Override - public void onResponse(final CachesStatsResponse response) { - // <1> - } - - @Override - public void onFailure(final Exception e) { - // <2> - } - }; - // end::searchable-snapshots-caches-stats-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::searchable-snapshots-caches-stats-execute-async - client.searchableSnapshots().cacheStatsAsync( - request, - RequestOptions.DEFAULT, - listener // <1> - ); - // end::searchable-snapshots-caches-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java deleted file mode 100644 index e6b103ccdda4..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java +++ /dev/null @@ -1,3175 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.ElasticsearchStatusException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.NodesResponseHeader; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.security.AuthenticateResponse; -import org.elasticsearch.client.security.AuthenticateResponse.RealmInfo; -import org.elasticsearch.client.security.ChangePasswordRequest; -import org.elasticsearch.client.security.ClearApiKeyCacheRequest; -import org.elasticsearch.client.security.ClearPrivilegesCacheRequest; -import org.elasticsearch.client.security.ClearPrivilegesCacheResponse; -import org.elasticsearch.client.security.ClearRealmCacheRequest; -import org.elasticsearch.client.security.ClearRealmCacheResponse; -import org.elasticsearch.client.security.ClearRolesCacheRequest; -import org.elasticsearch.client.security.ClearRolesCacheResponse; -import org.elasticsearch.client.security.ClearSecurityCacheResponse; -import org.elasticsearch.client.security.ClearServiceAccountTokenCacheRequest; -import org.elasticsearch.client.security.CreateApiKeyRequest; -import org.elasticsearch.client.security.CreateApiKeyRequestTests; -import org.elasticsearch.client.security.CreateApiKeyResponse; -import org.elasticsearch.client.security.CreateServiceAccountTokenRequest; -import org.elasticsearch.client.security.CreateServiceAccountTokenResponse; -import org.elasticsearch.client.security.CreateTokenRequest; -import org.elasticsearch.client.security.CreateTokenResponse; -import org.elasticsearch.client.security.DelegatePkiAuthenticationRequest; -import org.elasticsearch.client.security.DelegatePkiAuthenticationResponse; -import org.elasticsearch.client.security.DeletePrivilegesRequest; -import org.elasticsearch.client.security.DeletePrivilegesResponse; -import org.elasticsearch.client.security.DeleteRoleMappingRequest; -import org.elasticsearch.client.security.DeleteRoleMappingResponse; -import org.elasticsearch.client.security.DeleteRoleRequest; -import org.elasticsearch.client.security.DeleteRoleResponse; -import org.elasticsearch.client.security.DeleteServiceAccountTokenRequest; -import org.elasticsearch.client.security.DeleteServiceAccountTokenResponse; -import org.elasticsearch.client.security.DeleteUserRequest; -import org.elasticsearch.client.security.DeleteUserResponse; -import org.elasticsearch.client.security.DisableUserRequest; -import org.elasticsearch.client.security.EnableUserRequest; -import org.elasticsearch.client.security.ExpressionRoleMapping; -import org.elasticsearch.client.security.GetApiKeyRequest; -import org.elasticsearch.client.security.GetApiKeyResponse; -import org.elasticsearch.client.security.GetBuiltinPrivilegesResponse; -import org.elasticsearch.client.security.GetPrivilegesRequest; -import org.elasticsearch.client.security.GetPrivilegesResponse; -import org.elasticsearch.client.security.GetRoleMappingsRequest; -import org.elasticsearch.client.security.GetRoleMappingsResponse; -import org.elasticsearch.client.security.GetRolesRequest; -import org.elasticsearch.client.security.GetRolesResponse; -import org.elasticsearch.client.security.GetServiceAccountCredentialsRequest; -import org.elasticsearch.client.security.GetServiceAccountCredentialsResponse; -import org.elasticsearch.client.security.GetServiceAccountsRequest; -import org.elasticsearch.client.security.GetServiceAccountsResponse; -import org.elasticsearch.client.security.GetSslCertificatesResponse; -import org.elasticsearch.client.security.GetUserPrivilegesResponse; -import org.elasticsearch.client.security.GetUsersRequest; -import org.elasticsearch.client.security.GetUsersResponse; -import org.elasticsearch.client.security.GrantApiKeyRequest; -import org.elasticsearch.client.security.HasPrivilegesRequest; -import org.elasticsearch.client.security.HasPrivilegesResponse; -import org.elasticsearch.client.security.InvalidateApiKeyRequest; -import org.elasticsearch.client.security.InvalidateApiKeyResponse; -import org.elasticsearch.client.security.InvalidateTokenRequest; -import org.elasticsearch.client.security.InvalidateTokenResponse; -import org.elasticsearch.client.security.PutPrivilegesRequest; -import org.elasticsearch.client.security.PutPrivilegesResponse; -import org.elasticsearch.client.security.PutRoleMappingRequest; -import org.elasticsearch.client.security.PutRoleMappingResponse; -import org.elasticsearch.client.security.PutRoleRequest; -import org.elasticsearch.client.security.PutRoleResponse; -import org.elasticsearch.client.security.PutUserRequest; -import org.elasticsearch.client.security.PutUserResponse; -import org.elasticsearch.client.security.QueryApiKeyRequest; -import org.elasticsearch.client.security.QueryApiKeyResponse; -import org.elasticsearch.client.security.RefreshPolicy; -import org.elasticsearch.client.security.TemplateRoleName; -import org.elasticsearch.client.security.support.ApiKey; -import org.elasticsearch.client.security.support.CertificateInfo; -import org.elasticsearch.client.security.support.ServiceAccountInfo; -import org.elasticsearch.client.security.support.ServiceTokenInfo; -import org.elasticsearch.client.security.support.expressiondsl.RoleMapperExpression; -import org.elasticsearch.client.security.support.expressiondsl.expressions.AnyRoleMapperExpression; -import org.elasticsearch.client.security.support.expressiondsl.fields.FieldRoleMapperExpression; -import org.elasticsearch.client.security.user.User; -import org.elasticsearch.client.security.user.privileges.ApplicationPrivilege; -import org.elasticsearch.client.security.user.privileges.ApplicationResourcePrivileges; -import org.elasticsearch.client.security.user.privileges.IndicesPrivileges; -import org.elasticsearch.client.security.user.privileges.Role; -import org.elasticsearch.client.security.user.privileges.Role.ClusterPrivilegeName; -import org.elasticsearch.client.security.user.privileges.Role.IndexPrivilegeName; -import org.elasticsearch.client.security.user.privileges.UserIndicesPrivileges; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.settings.SecureString; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadContext; -import org.elasticsearch.common.util.set.Sets; -import org.elasticsearch.core.CheckedConsumer; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.searchafter.SearchAfterBuilder; -import org.elasticsearch.search.sort.FieldSortBuilder; -import org.elasticsearch.search.sort.SortOrder; -import org.hamcrest.Matchers; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.stream.Collectors; - -import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.PBEKeySpec; - -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.emptyIterable; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.in; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.iterableWithSize; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - -@SuppressWarnings("removal") -public class SecurityDocumentationIT extends ESRestHighLevelClientTestCase { - - @Override - protected Settings restAdminSettings() { - String token = basicAuthHeaderValue("admin_user", new SecureString("admin-password".toCharArray())); - return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build(); - } - - public void testGetUsers() throws Exception { - final RestHighLevelClient client = highLevelClient(); - String[] usernames = new String[] { "user1", "user2", "user3" }; - addUser(client, usernames[0], randomAlphaOfLengthBetween(14, 18)); - addUser(client, usernames[1], randomAlphaOfLengthBetween(14, 18)); - addUser(client, usernames[2], randomAlphaOfLengthBetween(14, 18)); - { - //tag::get-users-request - GetUsersRequest request = new GetUsersRequest(usernames[0]); - //end::get-users-request - //tag::get-users-execute - GetUsersResponse response = client.security().getUsers(request, RequestOptions.DEFAULT); - //end::get-users-execute - //tag::get-users-response - List users = new ArrayList<>(1); - users.addAll(response.getUsers()); - //end::get-users-response - - assertNotNull(response); - assertThat(users.size(), equalTo(1)); - assertThat(users.get(0).getUsername(), is(usernames[0])); - } - - { - //tag::get-users-list-request - GetUsersRequest request = new GetUsersRequest(usernames); - GetUsersResponse response = client.security().getUsers(request, RequestOptions.DEFAULT); - //end::get-users-list-request - - List users = new ArrayList<>(3); - users.addAll(response.getUsers()); - users.sort(Comparator.comparing(User::getUsername)); - assertNotNull(response); - assertThat(users.size(), equalTo(3)); - assertThat(users.get(0).getUsername(), equalTo(usernames[0])); - assertThat(users.get(1).getUsername(), equalTo(usernames[1])); - assertThat(users.get(2).getUsername(), equalTo(usernames[2])); - assertThat(users.size(), equalTo(3)); - } - - { - //tag::get-users-all-request - GetUsersRequest request = new GetUsersRequest(); - GetUsersResponse response = client.security().getUsers(request, RequestOptions.DEFAULT); - //end::get-users-all-request - - List users = new ArrayList<>(3); - users.addAll(response.getUsers()); - assertNotNull(response); - // 10 users are expected to be returned - // test_users (3): user1, user2, user3 - // system_users (6): elastic, beats_system, apm_system, logstash_system, kibana, kibana_system, remote_monitoring_user - logger.info(users); - assertThat(users.size(), equalTo(10)); - } - - { - GetUsersRequest request = new GetUsersRequest(usernames[0]); - ActionListener listener; - - //tag::get-users-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(GetUsersResponse getRolesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::get-users-execute-listener - - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - //tag::get-users-execute-async - client.security().getUsersAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::get-users-execute-async - - final GetUsersResponse response = future.get(30, TimeUnit.SECONDS); - List users = new ArrayList<>(1); - users.addAll(response.getUsers()); - assertNotNull(response); - assertThat(users.size(), equalTo(1)); - assertThat(users.get(0).getUsername(), equalTo(usernames[0])); - } - } - - public void testPutUser() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - //tag::put-user-password-request - char[] password = new char[]{'t', 'e', 's', 't', '-', 'u', 's', 'e', 'r', '-', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd'}; - User user = new User("example", Collections.singletonList("superuser")); - PutUserRequest request = PutUserRequest.withPassword(user, password, true, RefreshPolicy.NONE); - //end::put-user-password-request - - //tag::put-user-execute - PutUserResponse response = client.security().putUser(request, RequestOptions.DEFAULT); - //end::put-user-execute - - //tag::put-user-response - boolean isCreated = response.isCreated(); // <1> - //end::put-user-response - - assertTrue(isCreated); - } - { - byte[] salt = new byte[32]; - // no need for secure random in a test; it could block and would not be reproducible anyway - random().nextBytes(salt); - char[] password = new char[] { 't', 'e', 's', 't', '-', 'u', 's', 'e', 'r', '-', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' }; - User user = new User("example2", Collections.singletonList("superuser")); - - //tag::put-user-hash-request - SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2withHMACSHA512"); - PBEKeySpec keySpec = new PBEKeySpec(password, salt, 10000, 256); - final byte[] pbkdfEncoded = secretKeyFactory.generateSecret(keySpec).getEncoded(); - char[] passwordHash = ("{PBKDF2}10000$" + Base64.getEncoder().encodeToString(salt) - + "$" + Base64.getEncoder().encodeToString(pbkdfEncoded)).toCharArray(); - - PutUserRequest request = PutUserRequest.withPasswordHash(user, passwordHash, true, RefreshPolicy.NONE); - //end::put-user-hash-request - - try { - client.security().putUser(request, RequestOptions.DEFAULT); - } catch (ElasticsearchStatusException e) { - // This is expected to fail as the server will not be using PBKDF2, but that's easiest hasher to support - // in a standard JVM without introducing additional libraries. - assertThat(e.getDetailedMessage(), containsString("PBKDF2")); - } - } - - { - User user = new User("example", Arrays.asList("superuser", "another-role")); - //tag::put-user-update-request - PutUserRequest request = PutUserRequest.updateUser(user, true, RefreshPolicy.NONE); - //end::put-user-update-request - - // tag::put-user-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutUserResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-user-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-user-execute-async - client.security().putUserAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-user-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteUser() throws Exception { - RestHighLevelClient client = highLevelClient(); - addUser(client, "testUser", "testUserPassword"); - - { - // tag::delete-user-request - DeleteUserRequest deleteUserRequest = new DeleteUserRequest( - "testUser"); // <1> - // end::delete-user-request - - // tag::delete-user-execute - DeleteUserResponse deleteUserResponse = client.security().deleteUser(deleteUserRequest, RequestOptions.DEFAULT); - // end::delete-user-execute - - // tag::delete-user-response - boolean found = deleteUserResponse.isAcknowledged(); // <1> - // end::delete-user-response - assertTrue(found); - - // check if deleting the already deleted user again will give us a different response - deleteUserResponse = client.security().deleteUser(deleteUserRequest, RequestOptions.DEFAULT); - assertFalse(deleteUserResponse.isAcknowledged()); - } - - { - DeleteUserRequest deleteUserRequest = new DeleteUserRequest("testUser", RefreshPolicy.IMMEDIATE); - - ActionListener listener; - //tag::delete-user-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(DeleteUserResponse deleteUserResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::delete-user-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - //tag::delete-user-execute-async - client.security().deleteUserAsync(deleteUserRequest, RequestOptions.DEFAULT, listener); // <1> - //end::delete-user-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - private void addUser(RestHighLevelClient client, String userName, String password) throws IOException { - User user = new User(userName, Collections.singletonList(userName)); - PutUserRequest request = PutUserRequest.withPassword(user, password.toCharArray(), true, RefreshPolicy.NONE); - PutUserResponse response = client.security().putUser(request, RequestOptions.DEFAULT); - assertTrue(response.isCreated()); - } - - public void testPutRoleMapping() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - { - // tag::put-role-mapping-execute - final RoleMapperExpression rules = AnyRoleMapperExpression.builder() - .addExpression(FieldRoleMapperExpression.ofUsername("*")) - .addExpression(FieldRoleMapperExpression.ofGroups("cn=admins,dc=example,dc=com")) - .build(); - final PutRoleMappingRequest request = new PutRoleMappingRequest("mapping-example", true, - Collections.singletonList("superuser"), Collections.emptyList(), rules, null, RefreshPolicy.NONE); - final PutRoleMappingResponse response = client.security().putRoleMapping(request, RequestOptions.DEFAULT); - // end::put-role-mapping-execute - // tag::put-role-mapping-response - boolean isCreated = response.isCreated(); // <1> - // end::put-role-mapping-response - assertTrue(isCreated); - } - - { - final RoleMapperExpression rules = AnyRoleMapperExpression.builder() - .addExpression(FieldRoleMapperExpression.ofUsername("*")) - .addExpression(FieldRoleMapperExpression.ofGroups("cn=admins,dc=example,dc=com")) - .build(); - final PutRoleMappingRequest request = new PutRoleMappingRequest( - "mapping-example", - true, - Collections.emptyList(), - Collections.singletonList(new TemplateRoleName("{\"source\":\"{{username}}\"}", TemplateRoleName.Format.STRING)), - rules, - null, - RefreshPolicy.NONE - ); - // tag::put-role-mapping-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutRoleMappingResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-role-mapping-execute-listener - - // avoid unused local warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::put-role-mapping-execute-async - client.security().putRoleMappingAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-role-mapping-execute-async - - assertThat(future.get(), notNullValue()); - assertThat(future.get().isCreated(), is(false)); - } - } - - public void testGetRoleMappings() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - final TemplateRoleName monitoring = new TemplateRoleName("{\"source\":\"monitoring\"}", TemplateRoleName.Format.STRING); - final TemplateRoleName template = new TemplateRoleName("{\"source\":\"{{username}}\"}", TemplateRoleName.Format.STRING); - - final RoleMapperExpression rules1 = AnyRoleMapperExpression.builder() - .addExpression(FieldRoleMapperExpression.ofUsername("*")) - .addExpression(FieldRoleMapperExpression.ofGroups("cn=admins,dc=example,dc=com")) - .build(); - final PutRoleMappingRequest putRoleMappingRequest1 = new PutRoleMappingRequest( - "mapping-example-1", - true, - Collections.emptyList(), - Arrays.asList(monitoring, template), - rules1, - null, - RefreshPolicy.NONE - ); - final PutRoleMappingResponse putRoleMappingResponse1 = client.security() - .putRoleMapping(putRoleMappingRequest1, RequestOptions.DEFAULT); - boolean isCreated1 = putRoleMappingResponse1.isCreated(); - assertTrue(isCreated1); - final RoleMapperExpression rules2 = AnyRoleMapperExpression.builder() - .addExpression(FieldRoleMapperExpression.ofGroups("cn=admins,dc=example,dc=com")) - .build(); - final Map metadata2 = new HashMap<>(); - metadata2.put("k1", "v1"); - final PutRoleMappingRequest putRoleMappingRequest2 = new PutRoleMappingRequest( - "mapping-example-2", - true, - Arrays.asList("superuser"), - Collections.emptyList(), - rules2, - metadata2, - RefreshPolicy.NONE - ); - final PutRoleMappingResponse putRoleMappingResponse2 = client.security() - .putRoleMapping(putRoleMappingRequest2, RequestOptions.DEFAULT); - boolean isCreated2 = putRoleMappingResponse2.isCreated(); - assertTrue(isCreated2); - - { - // tag::get-role-mappings-execute - final GetRoleMappingsRequest request = new GetRoleMappingsRequest("mapping-example-1"); - final GetRoleMappingsResponse response = client.security().getRoleMappings(request, RequestOptions.DEFAULT); - // end::get-role-mappings-execute - // tag::get-role-mappings-response - List mappings = response.getMappings(); - // end::get-role-mappings-response - assertNotNull(mappings); - assertThat(mappings.size(), is(1)); - assertThat(mappings.get(0).isEnabled(), is(true)); - assertThat(mappings.get(0).getName(), is("mapping-example-1")); - assertThat(mappings.get(0).getExpression(), equalTo(rules1)); - assertThat(mappings.get(0).getMetadata(), equalTo(Collections.emptyMap())); - assertThat(mappings.get(0).getRoles(), iterableWithSize(0)); - assertThat(mappings.get(0).getRoleTemplates(), iterableWithSize(2)); - assertThat(mappings.get(0).getRoleTemplates(), containsInAnyOrder(monitoring, template)); - } - - { - // tag::get-role-mappings-list-execute - final GetRoleMappingsRequest request = new GetRoleMappingsRequest("mapping-example-1", "mapping-example-2"); - final GetRoleMappingsResponse response = client.security().getRoleMappings(request, RequestOptions.DEFAULT); - // end::get-role-mappings-list-execute - List mappings = response.getMappings(); - assertNotNull(mappings); - assertThat(mappings.size(), is(2)); - for (ExpressionRoleMapping roleMapping : mappings) { - assertThat(roleMapping.isEnabled(), is(true)); - assertThat(roleMapping.getName(), in(new String[] { "mapping-example-1", "mapping-example-2" })); - if (roleMapping.getName().equals("mapping-example-1")) { - assertThat(roleMapping.getMetadata(), equalTo(Collections.emptyMap())); - assertThat(roleMapping.getExpression(), equalTo(rules1)); - assertThat(roleMapping.getRoles(), emptyIterable()); - assertThat(roleMapping.getRoleTemplates(), contains(monitoring, template)); - } else { - assertThat(roleMapping.getMetadata(), equalTo(metadata2)); - assertThat(roleMapping.getExpression(), equalTo(rules2)); - assertThat(roleMapping.getRoles(), contains("superuser")); - assertThat(roleMapping.getRoleTemplates(), emptyIterable()); - } - } - } - - { - // tag::get-role-mappings-all-execute - final GetRoleMappingsRequest request = new GetRoleMappingsRequest(); - final GetRoleMappingsResponse response = client.security().getRoleMappings(request, RequestOptions.DEFAULT); - // end::get-role-mappings-all-execute - List mappings = response.getMappings(); - assertNotNull(mappings); - assertThat(mappings.size(), is(2)); - for (ExpressionRoleMapping roleMapping : mappings) { - assertThat(roleMapping.isEnabled(), is(true)); - assertThat(roleMapping.getName(), in(new String[] { "mapping-example-1", "mapping-example-2" })); - if (roleMapping.getName().equals("mapping-example-1")) { - assertThat(roleMapping.getMetadata(), equalTo(Collections.emptyMap())); - assertThat(roleMapping.getExpression(), equalTo(rules1)); - assertThat(roleMapping.getRoles(), emptyIterable()); - assertThat(roleMapping.getRoleTemplates(), containsInAnyOrder(monitoring, template)); - } else { - assertThat(roleMapping.getMetadata(), equalTo(metadata2)); - assertThat(roleMapping.getExpression(), equalTo(rules2)); - assertThat(roleMapping.getRoles(), contains("superuser")); - assertThat(roleMapping.getRoleTemplates(), emptyIterable()); - } - } - } - - { - final GetRoleMappingsRequest request = new GetRoleMappingsRequest(); - // tag::get-role-mappings-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetRoleMappingsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-role-mappings-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-role-mappings-execute-async - client.security().getRoleMappingsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-role-mappings-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testEnableUser() throws Exception { - RestHighLevelClient client = highLevelClient(); - char[] password = new char[] { 't', 'e', 's', 't', '-', 'u', 's', 'e', 'r', '-', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' }; - User enable_user = new User("enable_user", Collections.singletonList("superuser")); - PutUserRequest putUserRequest = PutUserRequest.withPassword(enable_user, password, true, RefreshPolicy.IMMEDIATE); - PutUserResponse putUserResponse = client.security().putUser(putUserRequest, RequestOptions.DEFAULT); - assertTrue(putUserResponse.isCreated()); - - { - //tag::enable-user-execute - EnableUserRequest request = new EnableUserRequest("enable_user", RefreshPolicy.NONE); - boolean response = client.security().enableUser(request, RequestOptions.DEFAULT); - //end::enable-user-execute - - assertTrue(response); - } - - { - //tag::enable-user-execute-listener - EnableUserRequest request = new EnableUserRequest("enable_user", RefreshPolicy.NONE); - ActionListener listener = new ActionListener() { - @Override - public void onResponse(Boolean response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::enable-user-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::enable-user-execute-async - client.security().enableUserAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::enable-user-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDisableUser() throws Exception { - RestHighLevelClient client = highLevelClient(); - char[] password = new char[] { 't', 'e', 's', 't', '-', 'u', 's', 'e', 'r', '-', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' }; - User disable_user = new User("disable_user", Collections.singletonList("superuser")); - PutUserRequest putUserRequest = PutUserRequest.withPassword(disable_user, password, true, RefreshPolicy.IMMEDIATE); - PutUserResponse putUserResponse = client.security().putUser(putUserRequest, RequestOptions.DEFAULT); - assertTrue(putUserResponse.isCreated()); - { - //tag::disable-user-execute - DisableUserRequest request = new DisableUserRequest("disable_user", RefreshPolicy.NONE); - boolean response = client.security().disableUser(request, RequestOptions.DEFAULT); - //end::disable-user-execute - - assertTrue(response); - } - - { - //tag::disable-user-execute-listener - DisableUserRequest request = new DisableUserRequest("disable_user", RefreshPolicy.NONE); - ActionListener listener = new ActionListener() { - @Override - public void onResponse(Boolean response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::disable-user-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::disable-user-execute-async - client.security().disableUserAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::disable-user-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetRoles() throws Exception { - final RestHighLevelClient client = highLevelClient(); - addRole("my_role"); - addRole("my_role2"); - addRole("my_role3"); - { - //tag::get-roles-request - GetRolesRequest request = new GetRolesRequest("my_role"); - //end::get-roles-request - //tag::get-roles-execute - GetRolesResponse response = client.security().getRoles(request, RequestOptions.DEFAULT); - //end::get-roles-execute - //tag::get-roles-response - List roles = response.getRoles(); - //end::get-roles-response - - assertNotNull(response); - assertThat(roles.size(), equalTo(1)); - assertThat(roles.get(0).getName(), equalTo("my_role")); - assertThat(roles.get(0).getClusterPrivileges().contains("all"), equalTo(true)); - } - - { - //tag::get-roles-list-request - GetRolesRequest request = new GetRolesRequest("my_role", "my_role2"); - GetRolesResponse response = client.security().getRoles(request, RequestOptions.DEFAULT); - //end::get-roles-list-request - - List roles = response.getRoles(); - assertNotNull(response); - assertThat(roles.size(), equalTo(2)); - assertThat(roles.get(0).getClusterPrivileges().contains("all"), equalTo(true)); - assertThat(roles.get(1).getClusterPrivileges().contains("all"), equalTo(true)); - } - - { - //tag::get-roles-all-request - GetRolesRequest request = new GetRolesRequest(); - GetRolesResponse response = client.security().getRoles(request, RequestOptions.DEFAULT); - //end::get-roles-all-request - - List roles = response.getRoles(); - assertNotNull(response); - // 30 system roles plus the three we created - assertThat(roles.size(), equalTo(30 + 3)); - } - - { - GetRolesRequest request = new GetRolesRequest("my_role"); - ActionListener listener; - - //tag::get-roles-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(GetRolesResponse getRolesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::get-roles-execute-listener - - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - //tag::get-roles-execute-async - client.security().getRolesAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::get-roles-execute-async - - final GetRolesResponse response = future.get(30, TimeUnit.SECONDS); - assertNotNull(response); - assertThat(response.getRoles().size(), equalTo(1)); - assertThat(response.getRoles().get(0).getName(), equalTo("my_role")); - assertThat(response.getRoles().get(0).getClusterPrivileges().contains("all"), equalTo(true)); - } - } - - public void testAuthenticate() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::authenticate-execute - AuthenticateResponse response = client.security().authenticate(RequestOptions.DEFAULT); - //end::authenticate-execute - - //tag::authenticate-response - User user = response.getUser(); // <1> - boolean enabled = response.enabled(); // <2> - final String authenticationRealmName = response.getAuthenticationRealm().getName(); // <3> - final String authenticationRealmType = response.getAuthenticationRealm().getType(); // <4> - final String lookupRealmName = response.getLookupRealm().getName(); // <5> - final String lookupRealmType = response.getLookupRealm().getType(); // <6> - final String authenticationType = response.getAuthenticationType(); // <7> - final Map tokenInfo = response.getToken(); // <8> - //end::authenticate-response - - assertThat(user.getUsername(), is("test_user")); - assertThat(user.getRoles(), contains(new String[] { "admin" })); - assertThat(user.getFullName(), nullValue()); - assertThat(user.getEmail(), nullValue()); - assertThat(user.getMetadata().isEmpty(), is(true)); - assertThat(enabled, is(true)); - assertThat(authenticationRealmName, is("default_file")); - assertThat(authenticationRealmType, is("file")); - assertThat(lookupRealmName, is("default_file")); - assertThat(lookupRealmType, is("file")); - assertThat(authenticationType, is("realm")); - assertThat(tokenInfo, nullValue()); - } - - { - // tag::authenticate-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AuthenticateResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::authenticate-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::authenticate-execute-async - client.security().authenticateAsync(RequestOptions.DEFAULT, listener); // <1> - // end::authenticate-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testHasPrivileges() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::has-privileges-request - HasPrivilegesRequest request = new HasPrivilegesRequest( - Sets.newHashSet("monitor", "manage"), - Sets.newHashSet( - IndicesPrivileges.builder().indices("logstash-2018-10-05").privileges("read", "write") - .allowRestrictedIndices(false).build(), - IndicesPrivileges.builder().indices("logstash-2018-*").privileges("read") - .allowRestrictedIndices(true).build() - ), - null - ); - //end::has-privileges-request - - //tag::has-privileges-execute - HasPrivilegesResponse response = client.security().hasPrivileges(request, RequestOptions.DEFAULT); - //end::has-privileges-execute - - //tag::has-privileges-response - boolean hasMonitor = response.hasClusterPrivilege("monitor"); // <1> - boolean hasWrite = response.hasIndexPrivilege("logstash-2018-10-05", "write"); // <2> - boolean hasRead = response.hasIndexPrivilege("logstash-2018-*", "read"); // <3> - //end::has-privileges-response - - assertThat(response.getUsername(), is("test_user")); - assertThat(response.hasAllRequested(), is(true)); - assertThat(hasMonitor, is(true)); - assertThat(hasWrite, is(true)); - assertThat(hasRead, is(true)); - assertThat(response.getApplicationPrivileges().entrySet(), emptyIterable()); - } - - { - HasPrivilegesRequest request = new HasPrivilegesRequest(Collections.singleton("monitor"), null, null); - - // tag::has-privileges-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(HasPrivilegesResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::has-privileges-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::has-privileges-execute-async - client.security().hasPrivilegesAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::has-privileges-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetUserPrivileges() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-user-privileges-execute - GetUserPrivilegesResponse response = client.security().getUserPrivileges(RequestOptions.DEFAULT); - //end::get-user-privileges-execute - - assertNotNull(response); - //tag::get-user-privileges-response - final Set cluster = response.getClusterPrivileges(); - final Set index = response.getIndicesPrivileges(); - final Set application = response.getApplicationPrivileges(); - final Set runAs = response.getRunAsPrivilege(); - //end::get-user-privileges-response - - assertNotNull(cluster); - assertThat(cluster, contains("all")); - - assertNotNull(index); - assertThat(index.size(), is(1)); - final UserIndicesPrivileges indexPrivilege = index.iterator().next(); - assertThat(indexPrivilege.getIndices(), contains("*")); - assertThat(indexPrivilege.getPrivileges(), contains("all")); - assertThat(indexPrivilege.getFieldSecurity().size(), is(0)); - assertThat(indexPrivilege.getQueries().size(), is(0)); - - assertNotNull(application); - assertThat(application.size(), is(1)); - - assertNotNull(runAs); - assertThat(runAs, contains("*")); - } - - { - //tag::get-user-privileges-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetUserPrivilegesResponse getUserPrivilegesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::get-user-privileges-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-user-privileges-execute-async - client.security().getUserPrivilegesAsync(RequestOptions.DEFAULT, listener); // <1> - // end::get-user-privileges-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testClearRealmCache() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::clear-realm-cache-request - ClearRealmCacheRequest request = new ClearRealmCacheRequest(Collections.emptyList(), Collections.emptyList()); - //end::clear-realm-cache-request - //tag::clear-realm-cache-execute - ClearRealmCacheResponse response = client.security().clearRealmCache(request, RequestOptions.DEFAULT); - //end::clear-realm-cache-execute - - assertNotNull(response); - assertThat(response.getNodes(), not(empty())); - - //tag::clear-realm-cache-response - List nodes = response.getNodes(); // <1> - //end::clear-realm-cache-response - } - { - //tag::clear-realm-cache-execute-listener - ClearRealmCacheRequest request = new ClearRealmCacheRequest(Collections.emptyList(), Collections.emptyList()); - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ClearRealmCacheResponse clearRealmCacheResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::clear-realm-cache-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clear-realm-cache-execute-async - client.security().clearRealmCacheAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clear-realm-cache-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testClearRolesCache() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::clear-roles-cache-request - ClearRolesCacheRequest request = new ClearRolesCacheRequest("my_role"); - //end::clear-roles-cache-request - //tag::clear-roles-cache-execute - ClearRolesCacheResponse response = client.security().clearRolesCache(request, RequestOptions.DEFAULT); - //end::clear-roles-cache-execute - - assertNotNull(response); - assertThat(response.getNodes(), not(empty())); - - //tag::clear-roles-cache-response - List nodes = response.getNodes(); // <1> - //end::clear-roles-cache-response - } - - { - //tag::clear-roles-cache-execute-listener - ClearRolesCacheRequest request = new ClearRolesCacheRequest("my_role"); - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ClearRolesCacheResponse clearRolesCacheResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::clear-roles-cache-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clear-roles-cache-execute-async - client.security().clearRolesCacheAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clear-roles-cache-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testClearPrivilegesCache() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::clear-privileges-cache-request - ClearPrivilegesCacheRequest request = new ClearPrivilegesCacheRequest("my_app"); // <1> - //end::clear-privileges-cache-request - //tag::clear-privileges-cache-execute - ClearPrivilegesCacheResponse response = client.security().clearPrivilegesCache(request, RequestOptions.DEFAULT); - //end::clear-privileges-cache-execute - - assertNotNull(response); - assertThat(response.getNodes(), not(empty())); - - //tag::clear-privileges-cache-response - List nodes = response.getNodes(); // <1> - //end::clear-privileges-cache-response - } - - { - //tag::clear-privileges-cache-execute-listener - ClearPrivilegesCacheRequest request = new ClearPrivilegesCacheRequest("my_app"); - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(ClearPrivilegesCacheResponse clearPrivilegesCacheResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::clear-privileges-cache-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clear-privileges-cache-execute-async - client.security().clearPrivilegesCacheAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clear-privileges-cache-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testClearApiKeyCache() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::clear-api-key-cache-request - ClearApiKeyCacheRequest request = ClearApiKeyCacheRequest.clearById( - "yVGMr3QByxdh1MSaicYx" // <1> - ); - //end::clear-api-key-cache-request - //tag::clear-api-key-cache-execute - ClearSecurityCacheResponse response = client.security().clearApiKeyCache(request, RequestOptions.DEFAULT); - //end::clear-api-key-cache-execute - - assertNotNull(response); - assertThat(response.getNodes(), not(empty())); - - //tag::clear-api-key-cache-response - List nodes = response.getNodes(); // <1> - //end::clear-api-key-cache-response - } - - { - ClearApiKeyCacheRequest request = ClearApiKeyCacheRequest.clearById("yVGMr3QByxdh1MSaicYx"); - //tag::clear-api-key-cache-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(ClearSecurityCacheResponse clearSecurityCacheResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::clear-api-key-cache-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clear-api-key-cache-execute-async - client.security().clearApiKeyCacheAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clear-api-key-cache-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testClearServiceAccountTokenCache() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::clear-service-account-token-cache-request - ClearServiceAccountTokenCacheRequest request = new ClearServiceAccountTokenCacheRequest( - "elastic", // <1> - "fleet-server", // <2> - "token1" // <3> - ); - //end::clear-service-account-token-cache-request - //tag::clear-service-account-token-cache-execute - ClearSecurityCacheResponse response = client.security().clearServiceAccountTokenCache(request, RequestOptions.DEFAULT); - //end::clear-service-account-token-cache-execute - - assertNotNull(response); - assertThat(response.getNodes(), not(empty())); - - //tag::clear-service-account-token-cache-response - List nodes = response.getNodes(); // <1> - //end::clear-service-account-token-cache-response - } - - { - ClearServiceAccountTokenCacheRequest request = new ClearServiceAccountTokenCacheRequest( - "elastic", - "fleet-server", - "token1", - "token2" - ); - //tag::clear-service-account-token-cache-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(ClearSecurityCacheResponse clearSecurityCacheResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::clear-service-account-token-cache-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clear-service-account-token-cache-execute-async - client.security().clearServiceAccountTokenCacheAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clear-service-account-token-cache-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetSslCertificates() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-certificates-execute - GetSslCertificatesResponse response = client.security().getSslCertificates(RequestOptions.DEFAULT); - //end::get-certificates-execute - - assertNotNull(response); - - //tag::get-certificates-response - List certificates = response.getCertificates(); // <1> - //end::get-certificates-response - - assertThat(certificates.size(), Matchers.equalTo(9)); - final Iterator it = certificates.iterator(); - CertificateInfo c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.crt")); - assertThat(c.getFormat(), Matchers.equalTo("PEM")); - assertThat(c.getSerialNumber(), Matchers.equalTo("b8b96c37e332cccb")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("activedir")); - assertThat(c.getSerialNumber(), Matchers.equalTo("580db8ad52bb168a4080e1df122a3f56")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("mykey")); - assertThat(c.getSerialNumber(), Matchers.equalTo("3151a81eec8d4e34c56a8466a8510bcfbe63cc31")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("openldap")); - assertThat(c.getSerialNumber(), Matchers.equalTo("d3850b2b1995ad5f")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("testclient")); - assertThat(c.getSerialNumber(), Matchers.equalTo("b9d497f2924bbe29")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("testnode-client-profile")); - assertThat(c.getSerialNumber(), Matchers.equalTo("c0ea4216e8ff0fd8")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("testnode_dsa")); - assertThat(c.getSerialNumber(), Matchers.equalTo("223c736a")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("testnode_ec")); - assertThat(c.getSerialNumber(), Matchers.equalTo("7268203b")); - c = it.next(); - assertThat(c.getPath(), Matchers.equalTo("testnode.jks")); - assertThat(c.getFormat(), Matchers.equalTo("jks")); - assertThat(c.getAlias(), Matchers.equalTo("testnode_rsa")); - assertThat(c.getSerialNumber(), Matchers.equalTo("b8b96c37e332cccb")); - } - - { - // tag::get-certificates-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetSslCertificatesResponse getSslCertificatesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-certificates-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-certificates-execute-async - client.security().getSslCertificatesAsync(RequestOptions.DEFAULT, listener); // <1> - // end::get-certificates-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testChangePassword() throws Exception { - RestHighLevelClient client = highLevelClient(); - char[] password = new char[] { 't', 'e', 's', 't', '-', 'u', 's', 'e', 'r', '-', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' }; - char[] newPassword = new char[] { - 'n', - 'e', - 'w', - '-', - 't', - 'e', - 's', - 't', - '-', - 'u', - 's', - 'e', - 'r', - '-', - 'p', - 'a', - 's', - 's', - 'w', - 'o', - 'r', - 'd' }; - User user = new User("change_password_user", Collections.singletonList("superuser"), Collections.emptyMap(), null, null); - PutUserRequest putUserRequest = PutUserRequest.withPassword(user, password, true, RefreshPolicy.NONE); - PutUserResponse putUserResponse = client.security().putUser(putUserRequest, RequestOptions.DEFAULT); - assertTrue(putUserResponse.isCreated()); - { - //tag::change-password-execute - ChangePasswordRequest request = new ChangePasswordRequest("change_password_user", newPassword, RefreshPolicy.NONE); - boolean response = client.security().changePassword(request, RequestOptions.DEFAULT); - //end::change-password-execute - - assertTrue(response); - } - { - //tag::change-password-execute-listener - ChangePasswordRequest request = new ChangePasswordRequest("change_password_user", password, RefreshPolicy.NONE); - ActionListener listener = new ActionListener() { - @Override - public void onResponse(Boolean response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::change-password-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - //tag::change-password-execute-async - client.security().changePasswordAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::change-password-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteRoleMapping() throws Exception { - final RestHighLevelClient client = highLevelClient(); - - { - // Create role mappings - final RoleMapperExpression rules = FieldRoleMapperExpression.ofUsername("*"); - final PutRoleMappingRequest request = new PutRoleMappingRequest( - "mapping-example", - true, - Collections.singletonList("superuser"), - Collections.emptyList(), - rules, - null, - RefreshPolicy.NONE - ); - final PutRoleMappingResponse response = client.security().putRoleMapping(request, RequestOptions.DEFAULT); - boolean isCreated = response.isCreated(); - assertTrue(isCreated); - } - - { - // tag::delete-role-mapping-execute - final DeleteRoleMappingRequest request = new DeleteRoleMappingRequest("mapping-example", RefreshPolicy.NONE); - final DeleteRoleMappingResponse response = client.security().deleteRoleMapping(request, RequestOptions.DEFAULT); - // end::delete-role-mapping-execute - // tag::delete-role-mapping-response - boolean isFound = response.isFound(); // <1> - // end::delete-role-mapping-response - - assertTrue(isFound); - } - - { - final DeleteRoleMappingRequest request = new DeleteRoleMappingRequest("mapping-example", RefreshPolicy.NONE); - // tag::delete-role-mapping-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(DeleteRoleMappingResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-role-mapping-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-role-mapping-execute-async - client.security().deleteRoleMappingAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-role-mapping-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteRole() throws Exception { - RestHighLevelClient client = highLevelClient(); - addRole("testrole"); - - { - // tag::delete-role-request - DeleteRoleRequest deleteRoleRequest = new DeleteRoleRequest( - "testrole"); // <1> - // end::delete-role-request - - // tag::delete-role-execute - DeleteRoleResponse deleteRoleResponse = client.security().deleteRole(deleteRoleRequest, RequestOptions.DEFAULT); - // end::delete-role-execute - - // tag::delete-role-response - boolean found = deleteRoleResponse.isFound(); // <1> - // end::delete-role-response - assertTrue(found); - - // check if deleting the already deleted role again will give us a different response - deleteRoleResponse = client.security().deleteRole(deleteRoleRequest, RequestOptions.DEFAULT); - assertFalse(deleteRoleResponse.isFound()); - } - - { - DeleteRoleRequest deleteRoleRequest = new DeleteRoleRequest("testrole"); - - ActionListener listener; - //tag::delete-role-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(DeleteRoleResponse deleteRoleResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::delete-role-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - //tag::delete-role-execute-async - client.security().deleteRoleAsync(deleteRoleRequest, RequestOptions.DEFAULT, listener); // <1> - //end::delete-role-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPutRole() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::put-role-request - final Role role = Role.builder() - .name("testPutRole") - .clusterPrivileges(randomSubsetOf(1, Role.ClusterPrivilegeName.ALL_ARRAY)) - .build(); - final PutRoleRequest request = new PutRoleRequest(role, RefreshPolicy.NONE); - // end::put-role-request - // tag::put-role-execute - final PutRoleResponse response = client.security().putRole(request, RequestOptions.DEFAULT); - // end::put-role-execute - // tag::put-role-response - boolean isCreated = response.isCreated(); // <1> - // end::put-role-response - assertTrue(isCreated); - } - - { - final Role role = Role.builder() - .name("testPutRole") - .clusterPrivileges(randomSubsetOf(1, Role.ClusterPrivilegeName.ALL_ARRAY)) - .build(); - final PutRoleRequest request = new PutRoleRequest(role, RefreshPolicy.NONE); - // tag::put-role-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutRoleResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-role-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::put-role-execute-async - client.security().putRoleAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-role-execute-async - - assertNotNull(future.get(30, TimeUnit.SECONDS)); - assertThat(future.get().isCreated(), is(false)); // false because it has already been created by the sync variant - } - } - - private void addRole(String roleName) throws IOException { - final Role role = Role.builder().name(roleName).clusterPrivileges("all").build(); - final PutRoleRequest request = new PutRoleRequest(role, RefreshPolicy.IMMEDIATE); - highLevelClient().security().putRole(request, RequestOptions.DEFAULT); - } - - public void testCreateToken() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // Setup user - User token_user = new User("token_user", Collections.singletonList("kibana_user")); - PutUserRequest putUserRequest = PutUserRequest.withPassword( - token_user, - "test-user-password".toCharArray(), - true, - RefreshPolicy.IMMEDIATE - ); - PutUserResponse putUserResponse = client.security().putUser(putUserRequest, RequestOptions.DEFAULT); - assertTrue(putUserResponse.isCreated()); - } - { - // tag::create-token-password-request - final char[] password = new char[]{'t', 'e', 's', 't', '-', 'u', 's', 'e', 'r', '-', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd'}; - CreateTokenRequest createTokenRequest = CreateTokenRequest.passwordGrant("token_user", password); - // end::create-token-password-request - - // tag::create-token-execute - CreateTokenResponse createTokenResponse = client.security().createToken(createTokenRequest, RequestOptions.DEFAULT); - // end::create-token-execute - - // tag::create-token-response - String accessToken = createTokenResponse.getAccessToken(); // <1> - String refreshToken = createTokenResponse.getRefreshToken(); // <2> - // end::create-token-response - assertNotNull(accessToken); - assertNotNull(refreshToken); - assertNotNull(createTokenResponse.getExpiresIn()); - - // tag::create-token-refresh-request - createTokenRequest = CreateTokenRequest.refreshTokenGrant(refreshToken); - // end::create-token-refresh-request - - CreateTokenResponse refreshResponse = client.security().createToken(createTokenRequest, RequestOptions.DEFAULT); - assertNotNull(refreshResponse.getAccessToken()); - assertNotNull(refreshResponse.getRefreshToken()); - } - - { - // tag::create-token-client-credentials-request - CreateTokenRequest createTokenRequest = CreateTokenRequest.clientCredentialsGrant(); - // end::create-token-client-credentials-request - - ActionListener listener; - //tag::create-token-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(CreateTokenResponse createTokenResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::create-token-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - //tag::create-token-execute-async - client.security().createTokenAsync(createTokenRequest, RequestOptions.DEFAULT, listener); // <1> - //end::create-token-execute-async - - assertNotNull(future.get(30, TimeUnit.SECONDS)); - assertNotNull(future.get().getAccessToken()); - // "client-credentials" grants aren't refreshable - assertNull(future.get().getRefreshToken()); - } - } - - public void testInvalidateToken() throws Exception { - RestHighLevelClient client = highLevelClient(); - - String accessToken; - String refreshToken; - { - // Setup users - final char[] password = "test-user-password".toCharArray(); - User user = new User("user", Collections.singletonList("kibana_user")); - PutUserRequest putUserRequest = PutUserRequest.withPassword(user, password, true, RefreshPolicy.IMMEDIATE); - PutUserResponse putUserResponse = client.security().putUser(putUserRequest, RequestOptions.DEFAULT); - assertTrue(putUserResponse.isCreated()); - - User this_user = new User("this_user", Collections.singletonList("kibana_user")); - PutUserRequest putThisUserRequest = PutUserRequest.withPassword(this_user, password, true, RefreshPolicy.IMMEDIATE); - PutUserResponse putThisUserResponse = client.security().putUser(putThisUserRequest, RequestOptions.DEFAULT); - assertTrue(putThisUserResponse.isCreated()); - - User that_user = new User("that_user", Collections.singletonList("kibana_user")); - PutUserRequest putThatUserRequest = PutUserRequest.withPassword(that_user, password, true, RefreshPolicy.IMMEDIATE); - PutUserResponse putThatUserResponse = client.security().putUser(putThatUserRequest, RequestOptions.DEFAULT); - assertTrue(putThatUserResponse.isCreated()); - - User other_user = new User("other_user", Collections.singletonList("kibana_user")); - PutUserRequest putOtherUserRequest = PutUserRequest.withPassword(other_user, password, true, RefreshPolicy.IMMEDIATE); - PutUserResponse putOtherUserResponse = client.security().putUser(putOtherUserRequest, RequestOptions.DEFAULT); - assertTrue(putOtherUserResponse.isCreated()); - - User extra_user = new User("extra_user", Collections.singletonList("kibana_user")); - PutUserRequest putExtraUserRequest = PutUserRequest.withPassword(extra_user, password, true, RefreshPolicy.IMMEDIATE); - PutUserResponse putExtraUserResponse = client.security().putUser(putExtraUserRequest, RequestOptions.DEFAULT); - assertTrue(putExtraUserResponse.isCreated()); - - // Create tokens - final CreateTokenRequest createTokenRequest = CreateTokenRequest.passwordGrant("user", password); - final CreateTokenResponse tokenResponse = client.security().createToken(createTokenRequest, RequestOptions.DEFAULT); - accessToken = tokenResponse.getAccessToken(); - refreshToken = tokenResponse.getRefreshToken(); - final CreateTokenRequest createThisTokenRequest = CreateTokenRequest.passwordGrant("this_user", password); - final CreateTokenResponse thisTokenResponse = client.security().createToken(createThisTokenRequest, RequestOptions.DEFAULT); - assertNotNull(thisTokenResponse); - final CreateTokenRequest createThatTokenRequest = CreateTokenRequest.passwordGrant("that_user", password); - final CreateTokenResponse thatTokenResponse = client.security().createToken(createThatTokenRequest, RequestOptions.DEFAULT); - assertNotNull(thatTokenResponse); - final CreateTokenRequest createOtherTokenRequest = CreateTokenRequest.passwordGrant("other_user", password); - final CreateTokenResponse otherTokenResponse = client.security().createToken(createOtherTokenRequest, RequestOptions.DEFAULT); - assertNotNull(otherTokenResponse); - final CreateTokenRequest createExtraTokenRequest = CreateTokenRequest.passwordGrant("extra_user", password); - final CreateTokenResponse extraTokenResponse = client.security().createToken(createExtraTokenRequest, RequestOptions.DEFAULT); - assertNotNull(extraTokenResponse); - } - - { - // tag::invalidate-access-token-request - InvalidateTokenRequest invalidateTokenRequest = InvalidateTokenRequest.accessToken(accessToken); - // end::invalidate-access-token-request - - // tag::invalidate-token-execute - InvalidateTokenResponse invalidateTokenResponse = - client.security().invalidateToken(invalidateTokenRequest, RequestOptions.DEFAULT); - // end::invalidate-token-execute - - // tag::invalidate-token-response - final List errors = invalidateTokenResponse.getErrors(); - final int invalidatedTokens = invalidateTokenResponse.getInvalidatedTokens(); - final int previouslyInvalidatedTokens = invalidateTokenResponse.getPreviouslyInvalidatedTokens(); - // end::invalidate-token-response - assertTrue(errors.isEmpty()); - assertThat(invalidatedTokens, equalTo(1)); - assertThat(previouslyInvalidatedTokens, equalTo(0)); - } - - { - // tag::invalidate-refresh-token-request - InvalidateTokenRequest invalidateTokenRequest = InvalidateTokenRequest.refreshToken(refreshToken); - // end::invalidate-refresh-token-request - InvalidateTokenResponse invalidateTokenResponse = client.security() - .invalidateToken(invalidateTokenRequest, RequestOptions.DEFAULT); - assertTrue(invalidateTokenResponse.getErrors().isEmpty()); - assertThat(invalidateTokenResponse.getInvalidatedTokens(), equalTo(1)); - assertThat(invalidateTokenResponse.getPreviouslyInvalidatedTokens(), equalTo(0)); - } - - { - // tag::invalidate-user-tokens-request - InvalidateTokenRequest invalidateTokenRequest = InvalidateTokenRequest.userTokens("other_user"); - // end::invalidate-user-tokens-request - InvalidateTokenResponse invalidateTokenResponse = client.security() - .invalidateToken(invalidateTokenRequest, RequestOptions.DEFAULT); - assertTrue(invalidateTokenResponse.getErrors().isEmpty()); - // We have one refresh and one access token for that user - assertThat(invalidateTokenResponse.getInvalidatedTokens(), equalTo(2)); - assertThat(invalidateTokenResponse.getPreviouslyInvalidatedTokens(), equalTo(0)); - } - - { - // tag::invalidate-user-realm-tokens-request - InvalidateTokenRequest invalidateTokenRequest = new InvalidateTokenRequest(null, null, "default_native", "extra_user"); - // end::invalidate-user-realm-tokens-request - InvalidateTokenResponse invalidateTokenResponse = client.security() - .invalidateToken(invalidateTokenRequest, RequestOptions.DEFAULT); - assertTrue(invalidateTokenResponse.getErrors().isEmpty()); - // We have one refresh and one access token for that user in this realm - assertThat(invalidateTokenResponse.getInvalidatedTokens(), equalTo(2)); - assertThat(invalidateTokenResponse.getPreviouslyInvalidatedTokens(), equalTo(0)); - } - - { - // tag::invalidate-realm-tokens-request - InvalidateTokenRequest invalidateTokenRequest = InvalidateTokenRequest.realmTokens("default_native"); - // end::invalidate-realm-tokens-request - - ActionListener listener; - //tag::invalidate-token-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(InvalidateTokenResponse invalidateTokenResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::invalidate-token-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - //tag::invalidate-token-execute-async - client.security().invalidateTokenAsync(invalidateTokenRequest, RequestOptions.DEFAULT, listener); // <1> - //end::invalidate-token-execute-async - - final InvalidateTokenResponse response = future.get(30, TimeUnit.SECONDS); - assertNotNull(response); - assertTrue(response.getErrors().isEmpty()); - // We still have 4 tokens ( 2 access_tokens and 2 refresh_tokens ) for the default_native realm - assertThat(response.getInvalidatedTokens(), equalTo(4)); - assertThat(response.getPreviouslyInvalidatedTokens(), equalTo(0)); - } - } - - public void testGetBuiltinPrivileges() throws Exception { - final RestHighLevelClient client = highLevelClient(); - { - //tag::get-builtin-privileges-execute - GetBuiltinPrivilegesResponse response = client.security().getBuiltinPrivileges(RequestOptions.DEFAULT); - //end::get-builtin-privileges-execute - - assertNotNull(response); - //tag::get-builtin-privileges-response - final Set cluster = response.getClusterPrivileges(); - final Set index = response.getIndexPrivileges(); - //end::get-builtin-privileges-response - - assertThat(cluster, hasItem("all")); - assertThat(cluster, hasItem("manage")); - assertThat(cluster, hasItem("monitor")); - assertThat(cluster, hasItem("manage_security")); - - assertThat(index, hasItem("all")); - assertThat(index, hasItem("manage")); - assertThat(index, hasItem("monitor")); - assertThat(index, hasItem("read")); - assertThat(index, hasItem("write")); - } - { - // tag::get-builtin-privileges-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetBuiltinPrivilegesResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-builtin-privileges-execute-listener - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::get-builtin-privileges-execute-async - client.security().getBuiltinPrivilegesAsync(RequestOptions.DEFAULT, listener); // <1> - // end::get-builtin-privileges-execute-async - - final GetBuiltinPrivilegesResponse response = future.get(30, TimeUnit.SECONDS); - assertNotNull(response); - assertThat(response.getClusterPrivileges(), hasItem("manage_security")); - assertThat(response.getIndexPrivileges(), hasItem("read")); - } - } - - public void testGetPrivileges() throws Exception { - final RestHighLevelClient client = highLevelClient(); - final ApplicationPrivilege readTestappPrivilege = new ApplicationPrivilege( - "testapp", - "read", - Arrays.asList("action:login", "data:read/*"), - null - ); - final Map metadata = new HashMap<>(); - metadata.put("key1", "value1"); - final ApplicationPrivilege writeTestappPrivilege = new ApplicationPrivilege( - "testapp", - "write", - Arrays.asList("action:login", "data:write/*"), - metadata - ); - final ApplicationPrivilege allTestappPrivilege = new ApplicationPrivilege( - "testapp", - "all", - Arrays.asList("action:login", "data:write/*", "manage:*"), - null - ); - final Map metadata2 = new HashMap<>(); - metadata2.put("key2", "value2"); - final ApplicationPrivilege readTestapp2Privilege = new ApplicationPrivilege( - "testapp2", - "read", - Arrays.asList("action:login", "data:read/*"), - metadata2 - ); - final ApplicationPrivilege writeTestapp2Privilege = new ApplicationPrivilege( - "testapp2", - "write", - Arrays.asList("action:login", "data:write/*"), - null - ); - final ApplicationPrivilege allTestapp2Privilege = new ApplicationPrivilege( - "testapp2", - "all", - Arrays.asList("action:login", "data:write/*", "manage:*"), - null - ); - - { - List applicationPrivileges = new ArrayList<>(); - applicationPrivileges.add(readTestappPrivilege); - applicationPrivileges.add(writeTestappPrivilege); - applicationPrivileges.add(allTestappPrivilege); - applicationPrivileges.add(readTestapp2Privilege); - applicationPrivileges.add(writeTestapp2Privilege); - applicationPrivileges.add(allTestapp2Privilege); - PutPrivilegesRequest putPrivilegesRequest = new PutPrivilegesRequest(applicationPrivileges, RefreshPolicy.IMMEDIATE); - PutPrivilegesResponse putPrivilegesResponse = client.security().putPrivileges(putPrivilegesRequest, RequestOptions.DEFAULT); - - assertNotNull(putPrivilegesResponse); - assertThat(putPrivilegesResponse.wasCreated("testapp", "write"), is(true)); - assertThat(putPrivilegesResponse.wasCreated("testapp", "read"), is(true)); - assertThat(putPrivilegesResponse.wasCreated("testapp", "all"), is(true)); - assertThat(putPrivilegesResponse.wasCreated("testapp2", "all"), is(true)); - assertThat(putPrivilegesResponse.wasCreated("testapp2", "write"), is(true)); - assertThat(putPrivilegesResponse.wasCreated("testapp2", "read"), is(true)); - } - - { - //tag::get-privileges-request - GetPrivilegesRequest request = new GetPrivilegesRequest("testapp", "write"); - //end::get-privileges-request - //tag::get-privileges-execute - GetPrivilegesResponse response = client.security().getPrivileges(request, RequestOptions.DEFAULT); - //end::get-privileges-execute - assertNotNull(response); - assertThat(response.getPrivileges().size(), equalTo(1)); - assertThat(response.getPrivileges().contains(writeTestappPrivilege), equalTo(true)); - } - - { - //tag::get-all-application-privileges-request - GetPrivilegesRequest request = GetPrivilegesRequest.getApplicationPrivileges("testapp"); - //end::get-all-application-privileges-request - GetPrivilegesResponse response = client.security().getPrivileges(request, RequestOptions.DEFAULT); - - assertNotNull(response); - assertThat(response.getPrivileges().size(), equalTo(3)); - final GetPrivilegesResponse expectedResponse = new GetPrivilegesResponse( - Arrays.asList(readTestappPrivilege, writeTestappPrivilege, allTestappPrivilege) - ); - assertThat(response, equalTo(expectedResponse)); - //tag::get-privileges-response - Set privileges = response.getPrivileges(); - //end::get-privileges-response - for (ApplicationPrivilege privilege : privileges) { - assertThat(privilege.getApplication(), equalTo("testapp")); - if (privilege.getName().equals("read")) { - assertThat(privilege.getActions(), containsInAnyOrder("action:login", "data:read/*")); - assertThat(privilege.getMetadata().isEmpty(), equalTo(true)); - } else if (privilege.getName().equals("write")) { - assertThat(privilege.getActions(), containsInAnyOrder("action:login", "data:write/*")); - assertThat(privilege.getMetadata().isEmpty(), equalTo(false)); - assertThat(privilege.getMetadata().get("key1"), equalTo("value1")); - } else if (privilege.getName().equals("all")) { - assertThat(privilege.getActions(), containsInAnyOrder("action:login", "data:write/*", "manage:*")); - assertThat(privilege.getMetadata().isEmpty(), equalTo(true)); - } - } - } - - { - //tag::get-all-privileges-request - GetPrivilegesRequest request = GetPrivilegesRequest.getAllPrivileges(); - //end::get-all-privileges-request - GetPrivilegesResponse response = client.security().getPrivileges(request, RequestOptions.DEFAULT); - - assertNotNull(response); - assertThat(response.getPrivileges().size(), equalTo(6)); - final GetPrivilegesResponse exptectedResponse = new GetPrivilegesResponse( - Arrays.asList( - readTestappPrivilege, - writeTestappPrivilege, - allTestappPrivilege, - readTestapp2Privilege, - writeTestapp2Privilege, - allTestapp2Privilege - ) - ); - assertThat(response, equalTo(exptectedResponse)); - } - - { - GetPrivilegesRequest request = new GetPrivilegesRequest("testapp", "read"); - //tag::get-privileges-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetPrivilegesResponse getPrivilegesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::get-privileges-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - //tag::get-privileges-execute-async - client.security().getPrivilegesAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::get-privileges-execute-async - - final GetPrivilegesResponse response = future.get(30, TimeUnit.SECONDS); - assertNotNull(response); - assertThat(response.getPrivileges().size(), equalTo(1)); - assertThat(response.getPrivileges().contains(readTestappPrivilege), equalTo(true)); - } - } - - public void testPutPrivileges() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::put-privileges-request - final List privileges = new ArrayList<>(); - privileges.add(ApplicationPrivilege.builder() - .application("app01") - .privilege("all") - .actions(List.of("action:login")) - .metadata(Collections.singletonMap("k1", "v1")) - .build()); - privileges.add(ApplicationPrivilege.builder() - .application("app01") - .privilege("write") - .actions(List.of("action:write")) - .build()); - final PutPrivilegesRequest putPrivilegesRequest = new PutPrivilegesRequest(privileges, RefreshPolicy.IMMEDIATE); - // end::put-privileges-request - - // tag::put-privileges-execute - final PutPrivilegesResponse putPrivilegesResponse = client.security().putPrivileges(putPrivilegesRequest, - RequestOptions.DEFAULT); - // end::put-privileges-execute - - final String applicationName = "app01"; - final String privilegeName = "all"; - // tag::put-privileges-response - final boolean status = putPrivilegesResponse.wasCreated(applicationName, privilegeName); // <1> - // end::put-privileges-response - assertThat(status, is(true)); - } - - { - final List privileges = new ArrayList<>(); - privileges.add( - ApplicationPrivilege.builder() - .application("app01") - .privilege("all") - .actions(List.of("action:login")) - .metadata(Collections.singletonMap("k1", "v1")) - .build() - ); - final PutPrivilegesRequest putPrivilegesRequest = new PutPrivilegesRequest(privileges, RefreshPolicy.IMMEDIATE); - - // tag::put-privileges-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutPrivilegesResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-privileges-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - //tag::put-privileges-execute-async - client.security().putPrivilegesAsync(putPrivilegesRequest, RequestOptions.DEFAULT, listener); // <1> - //end::put-privileges-execute-async - - assertNotNull(future.get(30, TimeUnit.SECONDS)); - assertThat(future.get().wasCreated("app01", "all"), is(false)); - } - } - - public void testDeletePrivilege() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - List applicationPrivileges = new ArrayList<>(); - applicationPrivileges.add( - ApplicationPrivilege.builder().application("testapp").privilege("read").actions("action:login", "data:read/*").build() - ); - applicationPrivileges.add( - ApplicationPrivilege.builder().application("testapp").privilege("write").actions("action:login", "data:write/*").build() - ); - applicationPrivileges.add( - ApplicationPrivilege.builder().application("testapp").privilege("all").actions("action:login", "data:write/*").build() - ); - PutPrivilegesRequest putPrivilegesRequest = new PutPrivilegesRequest(applicationPrivileges, RefreshPolicy.IMMEDIATE); - PutPrivilegesResponse putPrivilegesResponse = client.security().putPrivileges(putPrivilegesRequest, RequestOptions.DEFAULT); - - assertNotNull(putPrivilegesResponse); - assertThat(putPrivilegesResponse.wasCreated("testapp", "write"), is(true)); - assertThat(putPrivilegesResponse.wasCreated("testapp", "read"), is(true)); - assertThat(putPrivilegesResponse.wasCreated("testapp", "all"), is(true)); - } - { - // tag::delete-privileges-request - DeletePrivilegesRequest request = new DeletePrivilegesRequest( - "testapp", // <1> - "read", "write"); // <2> - // end::delete-privileges-request - - // tag::delete-privileges-execute - DeletePrivilegesResponse response = client.security().deletePrivileges(request, RequestOptions.DEFAULT); - // end::delete-privileges-execute - - // tag::delete-privileges-response - String application = response.getApplication(); // <1> - boolean found = response.isFound("read"); // <2> - // end::delete-privileges-response - assertThat(application, equalTo("testapp")); - assertTrue(response.isFound("write")); - assertTrue(found); - - // check if deleting the already deleted privileges again will give us a different response - response = client.security().deletePrivileges(request, RequestOptions.DEFAULT); - assertFalse(response.isFound("write")); - } - { - DeletePrivilegesRequest deletePrivilegesRequest = new DeletePrivilegesRequest("testapp", "all"); - - ActionListener listener; - //tag::delete-privileges-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(DeletePrivilegesResponse deletePrivilegesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::delete-privileges-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - //tag::delete-privileges-execute-async - client.security().deletePrivilegesAsync(deletePrivilegesRequest, RequestOptions.DEFAULT, listener); // <1> - //end::delete-privileges-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testCreateApiKey() throws Exception { - RestHighLevelClient client = highLevelClient(); - - List roles = Collections.singletonList( - Role.builder() - .name("r1") - .clusterPrivileges(ClusterPrivilegeName.ALL) - .indicesPrivileges(IndicesPrivileges.builder().indices("ind-x").privileges(IndexPrivilegeName.ALL).build()) - .build() - ); - final TimeValue expiration = TimeValue.timeValueHours(24); - final RefreshPolicy refreshPolicy = randomFrom(RefreshPolicy.values()); - final Map metadata = CreateApiKeyRequestTests.randomMetadata(); - { - final String name = randomAlphaOfLength(5); - // tag::create-api-key-request - CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest(name, roles, expiration, refreshPolicy, metadata); - // end::create-api-key-request - - // tag::create-api-key-execute - CreateApiKeyResponse createApiKeyResponse = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - // end::create-api-key-execute - - // tag::create-api-key-response - SecureString encoded = createApiKeyResponse.getEncoded(); // <1> - Instant apiKeyExpiration = createApiKeyResponse.getExpiration(); // <2> - // end::create-api-key-response - assertThat(createApiKeyResponse.getName(), equalTo(name)); - assertNotNull(encoded); - assertNotNull(apiKeyExpiration); - } - - { - final String name = randomAlphaOfLength(5); - CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest(name, roles, expiration, refreshPolicy, metadata); - - ActionListener listener; - // tag::create-api-key-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(CreateApiKeyResponse createApiKeyResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::create-api-key-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::create-api-key-execute-async - client.security().createApiKeyAsync(createApiKeyRequest, RequestOptions.DEFAULT, listener); // <1> - // end::create-api-key-execute-async - - assertNotNull(future.get(30, TimeUnit.SECONDS)); - assertThat(future.get().getName(), equalTo(name)); - assertNotNull(future.get().getKey()); - assertNotNull(future.get().getEncoded()); - assertNotNull(future.get().getExpiration()); - } - } - - public void testGrantApiKey() throws Exception { - RestHighLevelClient client = highLevelClient(); - - final String username = "grant_apikey_user"; - final String passwordString = randomAlphaOfLengthBetween(14, 18); - final char[] password = passwordString.toCharArray(); - - addUser(client, username, passwordString); - - List roles = Collections.singletonList( - Role.builder() - .name("r1") - .clusterPrivileges(ClusterPrivilegeName.ALL) - .indicesPrivileges(IndicesPrivileges.builder().indices("ind-x").privileges(IndexPrivilegeName.ALL).build()) - .build() - ); - - final Instant start = Instant.now(); - final Map metadata = CreateApiKeyRequestTests.randomMetadata(); - CheckedConsumer apiKeyVerifier = (created) -> { - final GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyId(created.getId(), false); - final GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - assertThat(getApiKeyResponse.getApiKeyInfos(), iterableWithSize(1)); - final ApiKey apiKeyInfo = getApiKeyResponse.getApiKeyInfos().get(0); - assertThat(apiKeyInfo.getUsername(), equalTo(username)); - assertThat(apiKeyInfo.getId(), equalTo(created.getId())); - assertThat(apiKeyInfo.getName(), equalTo(created.getName())); - assertThat(apiKeyInfo.getExpiration(), equalTo(created.getExpiration())); - assertThat(apiKeyInfo.isInvalidated(), equalTo(false)); - assertThat(apiKeyInfo.getCreation(), greaterThanOrEqualTo(start)); - assertThat(apiKeyInfo.getCreation(), lessThanOrEqualTo(Instant.now())); - if (metadata == null) { - assertThat(apiKeyInfo.getMetadata(), equalTo(Map.of())); - } else { - assertThat(apiKeyInfo.getMetadata(), equalTo(metadata)); - } - }; - - final TimeValue expiration = TimeValue.timeValueHours(24); - final RefreshPolicy refreshPolicy = randomFrom(RefreshPolicy.values()); - { - final String name = randomAlphaOfLength(5); - // tag::grant-api-key-request - CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest(name, roles, expiration, refreshPolicy, metadata); - GrantApiKeyRequest.Grant grant = GrantApiKeyRequest.Grant.passwordGrant(username, password); - GrantApiKeyRequest grantApiKeyRequest = new GrantApiKeyRequest(grant, createApiKeyRequest); - // end::grant-api-key-request - - // tag::grant-api-key-execute - CreateApiKeyResponse apiKeyResponse = client.security().grantApiKey(grantApiKeyRequest, RequestOptions.DEFAULT); - // end::grant-api-key-execute - - // tag::grant-api-key-response - SecureString encoded = apiKeyResponse.getEncoded(); // <1> - Instant apiKeyExpiration = apiKeyResponse.getExpiration(); // <2> - // end::grant-api-key-response - assertThat(apiKeyResponse.getName(), equalTo(name)); - assertNotNull(encoded); - assertNotNull(apiKeyExpiration); - - apiKeyVerifier.accept(apiKeyResponse); - } - - { - final String name = randomAlphaOfLength(5); - final CreateTokenRequest tokenRequest = CreateTokenRequest.passwordGrant(username, password); - final CreateTokenResponse token = client.security().createToken(tokenRequest, RequestOptions.DEFAULT); - - CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest(name, roles, expiration, refreshPolicy, metadata); - GrantApiKeyRequest.Grant grant = GrantApiKeyRequest.Grant.accessTokenGrant(token.getAccessToken()); - GrantApiKeyRequest grantApiKeyRequest = new GrantApiKeyRequest(grant, createApiKeyRequest); - - ActionListener listener; - // tag::grant-api-key-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(CreateApiKeyResponse createApiKeyResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::grant-api-key-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::grant-api-key-execute-async - client.security().grantApiKeyAsync(grantApiKeyRequest, RequestOptions.DEFAULT, listener); // <1> - // end::grant-api-key-execute-async - - assertNotNull(future.get(30, TimeUnit.SECONDS)); - assertThat(future.get().getName(), equalTo(name)); - assertNotNull(future.get().getKey()); - assertNotNull(future.get().getEncoded()); - assertNotNull(future.get().getExpiration()); - - apiKeyVerifier.accept(future.get()); - } - } - - public void testGetApiKey() throws Exception { - RestHighLevelClient client = highLevelClient(); - - List roles = Collections.singletonList( - Role.builder() - .name("r1") - .clusterPrivileges(ClusterPrivilegeName.ALL) - .indicesPrivileges(IndicesPrivileges.builder().indices("ind-x").privileges(IndexPrivilegeName.ALL).build()) - .build() - ); - final TimeValue expiration = TimeValue.timeValueHours(24); - final RefreshPolicy refreshPolicy = randomFrom(RefreshPolicy.values()); - final Map metadata = CreateApiKeyRequestTests.randomMetadata(); - // Create API Keys - CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest("k1", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse1 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse1.getName(), equalTo("k1")); - assertNotNull(createApiKeyResponse1.getKey()); - assertNotNull(createApiKeyResponse1.getEncoded()); - - final ApiKey expectedApiKeyInfo = new ApiKey( - createApiKeyResponse1.getName(), - createApiKeyResponse1.getId(), - Instant.now(), - Instant.now().plusMillis(expiration.getMillis()), - false, - "test_user", - "default_file", - metadata - ); - { - // tag::get-api-key-id-request - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyId(createApiKeyResponse1.getId(), false); - // end::get-api-key-id-request - - // tag::get-api-key-execute - GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - // end::get-api-key-execute - - assertThat(getApiKeyResponse.getApiKeyInfos(), is(notNullValue())); - assertThat(getApiKeyResponse.getApiKeyInfos().size(), is(1)); - verifyApiKey(getApiKeyResponse.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - - { - // tag::get-api-key-name-request - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyName(createApiKeyResponse1.getName(), false); - // end::get-api-key-name-request - - GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - - assertThat(getApiKeyResponse.getApiKeyInfos(), is(notNullValue())); - assertThat(getApiKeyResponse.getApiKeyInfos().size(), is(1)); - verifyApiKey(getApiKeyResponse.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - - { - // tag::get-realm-api-keys-request - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmName("default_file"); - // end::get-realm-api-keys-request - - GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - - assertThat(getApiKeyResponse.getApiKeyInfos(), is(notNullValue())); - assertThat(getApiKeyResponse.getApiKeyInfos().size(), is(1)); - verifyApiKey(getApiKeyResponse.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - - { - // tag::get-user-api-keys-request - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingUserName("test_user"); - // end::get-user-api-keys-request - - GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - - assertThat(getApiKeyResponse.getApiKeyInfos(), is(notNullValue())); - assertThat(getApiKeyResponse.getApiKeyInfos().size(), is(1)); - verifyApiKey(getApiKeyResponse.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - - { - // tag::get-api-keys-owned-by-authenticated-user-request - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.forOwnedApiKeys(); - // end::get-api-keys-owned-by-authenticated-user-request - - GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - - assertThat(getApiKeyResponse.getApiKeyInfos(), is(notNullValue())); - assertThat(getApiKeyResponse.getApiKeyInfos().size(), is(1)); - verifyApiKey(getApiKeyResponse.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - - { - // tag::get-all-api-keys-request - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.forAllApiKeys(); - // end::get-all-api-keys-request - - GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - - assertThat(getApiKeyResponse.getApiKeyInfos(), is(notNullValue())); - assertThat(getApiKeyResponse.getApiKeyInfos().size(), is(1)); - verifyApiKey(getApiKeyResponse.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - - { - // tag::get-user-realm-api-keys-request - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmAndUserName("default_file", "test_user"); - // end::get-user-realm-api-keys-request - - // tag::get-api-key-response - GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT); - // end::get-api-key-response - - assertThat(getApiKeyResponse.getApiKeyInfos(), is(notNullValue())); - assertThat(getApiKeyResponse.getApiKeyInfos().size(), is(1)); - verifyApiKey(getApiKeyResponse.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - - { - GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyId(createApiKeyResponse1.getId(), false); - - ActionListener listener; - // tag::get-api-key-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(GetApiKeyResponse getApiKeyResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-api-key-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::get-api-key-execute-async - client.security().getApiKeyAsync(getApiKeyRequest, RequestOptions.DEFAULT, listener); // <1> - // end::get-api-key-execute-async - - final GetApiKeyResponse response = future.get(30, TimeUnit.SECONDS); - assertNotNull(response); - - assertThat(response.getApiKeyInfos(), is(notNullValue())); - assertThat(response.getApiKeyInfos().size(), is(1)); - verifyApiKey(response.getApiKeyInfos().get(0), expectedApiKeyInfo); - } - } - - private void verifyApiKey(final ApiKey actual, final ApiKey expected) { - assertThat(actual.getId(), is(expected.getId())); - assertThat(actual.getName(), is(expected.getName())); - assertThat(actual.getUsername(), is(expected.getUsername())); - assertThat(actual.getRealm(), is(expected.getRealm())); - assertThat(actual.isInvalidated(), is(expected.isInvalidated())); - assertThat(actual.getExpiration(), is(greaterThan(Instant.now()))); - if (expected.getMetadata() == null) { - assertThat(actual.getMetadata(), equalTo(Map.of())); - } else { - assertThat(actual.getMetadata(), equalTo(expected.getMetadata())); - } - } - - public void testInvalidateApiKey() throws Exception { - RestHighLevelClient client = highLevelClient(); - - List roles = Collections.singletonList( - Role.builder() - .name("r1") - .clusterPrivileges(ClusterPrivilegeName.ALL) - .indicesPrivileges(IndicesPrivileges.builder().indices("ind-x").privileges(IndexPrivilegeName.ALL).build()) - .build() - ); - final TimeValue expiration = TimeValue.timeValueHours(24); - final RefreshPolicy refreshPolicy = randomFrom(RefreshPolicy.values()); - final Map metadata = CreateApiKeyRequestTests.randomMetadata(); - // Create API Keys - CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest("k1", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse1 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse1.getName(), equalTo("k1")); - assertNotNull(createApiKeyResponse1.getKey()); - assertNotNull(createApiKeyResponse1.getEncoded()); - - { - // tag::invalidate-api-key-id-request - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.usingApiKeyId(createApiKeyResponse1.getId(), false); - // end::invalidate-api-key-id-request - - // tag::invalidate-api-key-execute - InvalidateApiKeyResponse invalidateApiKeyResponse = client.security().invalidateApiKey(invalidateApiKeyRequest, - RequestOptions.DEFAULT); - // end::invalidate-api-key-execute - - final List errors = invalidateApiKeyResponse.getErrors(); - final List invalidatedApiKeyIds = invalidateApiKeyResponse.getInvalidatedApiKeys(); - final List previouslyInvalidatedApiKeyIds = invalidateApiKeyResponse.getPreviouslyInvalidatedApiKeys(); - - assertTrue(errors.isEmpty()); - List expectedInvalidatedApiKeyIds = Arrays.asList(createApiKeyResponse1.getId()); - assertThat(invalidatedApiKeyIds, containsInAnyOrder(expectedInvalidatedApiKeyIds.toArray(Strings.EMPTY_ARRAY))); - assertThat(previouslyInvalidatedApiKeyIds.size(), equalTo(0)); - } - - { - // tag::invalidate-api-key-ids-request - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.usingApiKeyIds( - Arrays.asList("kI3QZHYBnpSXoDRq1XzR", "ko3SZHYBnpSXoDRqk3zm"), false); - // end::invalidate-api-key-ids-request - - InvalidateApiKeyResponse invalidateApiKeyResponse = client.security() - .invalidateApiKey(invalidateApiKeyRequest, RequestOptions.DEFAULT); - - final List errors = invalidateApiKeyResponse.getErrors(); - final List invalidatedApiKeyIds = invalidateApiKeyResponse.getInvalidatedApiKeys(); - final List previouslyInvalidatedApiKeyIds = invalidateApiKeyResponse.getPreviouslyInvalidatedApiKeys(); - - assertTrue(errors.isEmpty()); - assertThat(invalidatedApiKeyIds.size(), equalTo(0)); - assertThat(previouslyInvalidatedApiKeyIds.size(), equalTo(0)); - } - - { - createApiKeyRequest = new CreateApiKeyRequest("k2", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse2 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse2.getName(), equalTo("k2")); - assertNotNull(createApiKeyResponse2.getKey()); - assertNotNull(createApiKeyResponse2.getEncoded()); - - // tag::invalidate-api-key-name-request - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.usingApiKeyName(createApiKeyResponse2.getName(), - false); - // end::invalidate-api-key-name-request - - InvalidateApiKeyResponse invalidateApiKeyResponse = client.security() - .invalidateApiKey(invalidateApiKeyRequest, RequestOptions.DEFAULT); - - final List errors = invalidateApiKeyResponse.getErrors(); - final List invalidatedApiKeyIds = invalidateApiKeyResponse.getInvalidatedApiKeys(); - final List previouslyInvalidatedApiKeyIds = invalidateApiKeyResponse.getPreviouslyInvalidatedApiKeys(); - - assertTrue(errors.isEmpty()); - List expectedInvalidatedApiKeyIds = Arrays.asList(createApiKeyResponse2.getId()); - assertThat(invalidatedApiKeyIds, containsInAnyOrder(expectedInvalidatedApiKeyIds.toArray(Strings.EMPTY_ARRAY))); - assertThat(previouslyInvalidatedApiKeyIds.size(), equalTo(0)); - } - - { - createApiKeyRequest = new CreateApiKeyRequest("k3", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse3 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse3.getName(), equalTo("k3")); - assertNotNull(createApiKeyResponse3.getKey()); - assertNotNull(createApiKeyResponse3.getEncoded()); - - // tag::invalidate-realm-api-keys-request - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.usingRealmName("default_file"); - // end::invalidate-realm-api-keys-request - - InvalidateApiKeyResponse invalidateApiKeyResponse = client.security() - .invalidateApiKey(invalidateApiKeyRequest, RequestOptions.DEFAULT); - - final List errors = invalidateApiKeyResponse.getErrors(); - final List invalidatedApiKeyIds = invalidateApiKeyResponse.getInvalidatedApiKeys(); - final List previouslyInvalidatedApiKeyIds = invalidateApiKeyResponse.getPreviouslyInvalidatedApiKeys(); - - assertTrue(errors.isEmpty()); - List expectedInvalidatedApiKeyIds = Arrays.asList(createApiKeyResponse3.getId()); - assertThat(invalidatedApiKeyIds, containsInAnyOrder(expectedInvalidatedApiKeyIds.toArray(Strings.EMPTY_ARRAY))); - assertThat(previouslyInvalidatedApiKeyIds.size(), equalTo(0)); - } - - { - createApiKeyRequest = new CreateApiKeyRequest("k4", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse4 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse4.getName(), equalTo("k4")); - assertNotNull(createApiKeyResponse4.getKey()); - assertNotNull(createApiKeyResponse4.getEncoded()); - - // tag::invalidate-user-api-keys-request - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.usingUserName("test_user"); - // end::invalidate-user-api-keys-request - - InvalidateApiKeyResponse invalidateApiKeyResponse = client.security() - .invalidateApiKey(invalidateApiKeyRequest, RequestOptions.DEFAULT); - - final List errors = invalidateApiKeyResponse.getErrors(); - final List invalidatedApiKeyIds = invalidateApiKeyResponse.getInvalidatedApiKeys(); - final List previouslyInvalidatedApiKeyIds = invalidateApiKeyResponse.getPreviouslyInvalidatedApiKeys(); - - assertTrue(errors.isEmpty()); - List expectedInvalidatedApiKeyIds = Arrays.asList(createApiKeyResponse4.getId()); - assertThat(invalidatedApiKeyIds, containsInAnyOrder(expectedInvalidatedApiKeyIds.toArray(Strings.EMPTY_ARRAY))); - assertThat(previouslyInvalidatedApiKeyIds.size(), equalTo(0)); - } - - { - createApiKeyRequest = new CreateApiKeyRequest("k5", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse5 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse5.getName(), equalTo("k5")); - assertNotNull(createApiKeyResponse5.getKey()); - assertNotNull(createApiKeyResponse5.getEncoded()); - - // tag::invalidate-user-realm-api-keys-request - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.usingRealmAndUserName("default_file", "test_user"); - // end::invalidate-user-realm-api-keys-request - - // tag::invalidate-api-key-response - InvalidateApiKeyResponse invalidateApiKeyResponse = client.security().invalidateApiKey(invalidateApiKeyRequest, - RequestOptions.DEFAULT); - // end::invalidate-api-key-response - - final List errors = invalidateApiKeyResponse.getErrors(); - final List invalidatedApiKeyIds = invalidateApiKeyResponse.getInvalidatedApiKeys(); - final List previouslyInvalidatedApiKeyIds = invalidateApiKeyResponse.getPreviouslyInvalidatedApiKeys(); - - assertTrue(errors.isEmpty()); - List expectedInvalidatedApiKeyIds = Arrays.asList(createApiKeyResponse5.getId()); - assertThat(invalidatedApiKeyIds, containsInAnyOrder(expectedInvalidatedApiKeyIds.toArray(Strings.EMPTY_ARRAY))); - assertThat(previouslyInvalidatedApiKeyIds.size(), equalTo(0)); - } - - { - createApiKeyRequest = new CreateApiKeyRequest("k6", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse6 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse6.getName(), equalTo("k6")); - assertNotNull(createApiKeyResponse6.getKey()); - assertNotNull(createApiKeyResponse6.getEncoded()); - - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.usingApiKeyId(createApiKeyResponse6.getId(), false); - - ActionListener listener; - // tag::invalidate-api-key-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(InvalidateApiKeyResponse invalidateApiKeyResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::invalidate-api-key-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::invalidate-api-key-execute-async - client.security().invalidateApiKeyAsync(invalidateApiKeyRequest, RequestOptions.DEFAULT, listener); // <1> - // end::invalidate-api-key-execute-async - - final InvalidateApiKeyResponse response = future.get(30, TimeUnit.SECONDS); - assertNotNull(response); - final List invalidatedApiKeyIds = response.getInvalidatedApiKeys(); - List expectedInvalidatedApiKeyIds = Arrays.asList(createApiKeyResponse6.getId()); - assertTrue(response.getErrors().isEmpty()); - assertThat(invalidatedApiKeyIds, containsInAnyOrder(expectedInvalidatedApiKeyIds.toArray(Strings.EMPTY_ARRAY))); - assertThat(response.getPreviouslyInvalidatedApiKeys().size(), equalTo(0)); - } - - { - createApiKeyRequest = new CreateApiKeyRequest("k7", roles, expiration, refreshPolicy, metadata); - CreateApiKeyResponse createApiKeyResponse7 = client.security().createApiKey(createApiKeyRequest, RequestOptions.DEFAULT); - assertThat(createApiKeyResponse7.getName(), equalTo("k7")); - assertNotNull(createApiKeyResponse7.getKey()); - assertNotNull(createApiKeyResponse7.getEncoded()); - - // tag::invalidate-api-keys-owned-by-authenticated-user-request - InvalidateApiKeyRequest invalidateApiKeyRequest = InvalidateApiKeyRequest.forOwnedApiKeys(); - // end::invalidate-api-keys-owned-by-authenticated-user-request - - InvalidateApiKeyResponse invalidateApiKeyResponse = client.security() - .invalidateApiKey(invalidateApiKeyRequest, RequestOptions.DEFAULT); - - final List errors = invalidateApiKeyResponse.getErrors(); - final List invalidatedApiKeyIds = invalidateApiKeyResponse.getInvalidatedApiKeys(); - final List previouslyInvalidatedApiKeyIds = invalidateApiKeyResponse.getPreviouslyInvalidatedApiKeys(); - - assertTrue(errors.isEmpty()); - List expectedInvalidatedApiKeyIds = Arrays.asList(createApiKeyResponse7.getId()); - assertThat(invalidatedApiKeyIds, containsInAnyOrder(expectedInvalidatedApiKeyIds.toArray(Strings.EMPTY_ARRAY))); - assertThat(previouslyInvalidatedApiKeyIds.size(), equalTo(0)); - } - - } - - public void testQueryApiKey() throws IOException, ExecutionException, InterruptedException, TimeoutException { - RestHighLevelClient client = highLevelClient(); - final CreateApiKeyRequest createApiKeyRequest1 = new CreateApiKeyRequest( - "key-10000", - List.of(), - randomBoolean() ? TimeValue.timeValueHours(24) : null, - RefreshPolicy.WAIT_UNTIL, - Map.of("environment", "east-production") - ); - final CreateApiKeyResponse createApiKeyResponse1 = client.security().createApiKey(createApiKeyRequest1, RequestOptions.DEFAULT); - final CreateApiKeyRequest createApiKeyRequest2 = new CreateApiKeyRequest( - "key-20000", - List.of(), - randomBoolean() ? TimeValue.timeValueHours(24) : null, - RefreshPolicy.WAIT_UNTIL, - Map.of("environment", "east-staging") - ); - final CreateApiKeyResponse createApiKeyResponse2 = client.security().createApiKey(createApiKeyRequest2, RequestOptions.DEFAULT); - - { - // tag::query-api-key-default-request - QueryApiKeyRequest queryApiKeyRequest = new QueryApiKeyRequest(); - // end::query-api-key-default-request - - // tag::query-api-key-execute - QueryApiKeyResponse queryApiKeyResponse = client.security().queryApiKey(queryApiKeyRequest, RequestOptions.DEFAULT); - // end::query-api-key-execute - - assertThat(queryApiKeyResponse.getTotal(), equalTo(2L)); - assertThat(queryApiKeyResponse.getCount(), equalTo(2)); - assertThat( - queryApiKeyResponse.getApiKeys().stream().map(ApiKey::getName).collect(Collectors.toUnmodifiableSet()), - equalTo(Set.of("key-10000", "key-20000")) - ); - assertThat( - queryApiKeyResponse.getApiKeys().stream().map(ApiKey::getId).collect(Collectors.toUnmodifiableSet()), - equalTo(Set.of(createApiKeyResponse1.getId(), createApiKeyResponse2.getId())) - ); - } - - { - // tag::query-api-key-query-request - QueryApiKeyRequest queryApiKeyRequest = new QueryApiKeyRequest().queryBuilder( - QueryBuilders.boolQuery() - .must(QueryBuilders.prefixQuery("metadata.environment", "east-")) - .mustNot(QueryBuilders.termQuery("name", "key-20000"))); - // end::query-api-key-query-request - - QueryApiKeyResponse queryApiKeyResponse = client.security().queryApiKey(queryApiKeyRequest, RequestOptions.DEFAULT); - assertThat(queryApiKeyResponse.getTotal(), equalTo(1L)); - assertThat(queryApiKeyResponse.getCount(), equalTo(1)); - assertThat(queryApiKeyResponse.getApiKeys().get(0).getName(), equalTo(createApiKeyResponse1.getName())); - assertThat(queryApiKeyResponse.getApiKeys().get(0).getId(), equalTo(createApiKeyResponse1.getId())); - } - - { - // tag::query-api-key-from-size-sort-request - QueryApiKeyRequest queryApiKeyRequest = new QueryApiKeyRequest() - .from(1) - .size(100) - .fieldSortBuilders(List.of(new FieldSortBuilder("name").order(SortOrder.DESC))); - // end::query-api-key-from-size-sort-request - - QueryApiKeyResponse queryApiKeyResponse = client.security().queryApiKey(queryApiKeyRequest, RequestOptions.DEFAULT); - - // tag::query-api-key-from-size-sort-response - final long total = queryApiKeyResponse.getTotal(); // <1> - final int count = queryApiKeyResponse.getCount(); // <2> - final List apiKeys = queryApiKeyResponse.getApiKeys(); // <3> - final Object[] sortValues = apiKeys.get(apiKeys.size()-1).getSortValues(); // <4> - // end::query-api-key-from-size-sort-response - - assertThat(total, equalTo(2L)); - assertThat(count, equalTo(1)); - assertThat(apiKeys.get(0).getName(), equalTo(createApiKeyResponse1.getName())); - assertThat(apiKeys.get(0).getId(), equalTo(createApiKeyResponse1.getId())); - assertThat(sortValues.length, equalTo(1)); - assertThat(sortValues[0], equalTo(createApiKeyResponse1.getName())); - } - - { - // tag::query-api-key-search-after-request - QueryApiKeyRequest queryApiKeyRequest = new QueryApiKeyRequest() - .fieldSortBuilders(List.of(new FieldSortBuilder("name"))) - .searchAfterBuilder(new SearchAfterBuilder().setSortValues(new String[] {"key-10000"})); - // end::query-api-key-search-after-request - - QueryApiKeyResponse queryApiKeyResponse = client.security().queryApiKey(queryApiKeyRequest, RequestOptions.DEFAULT); - assertThat(queryApiKeyResponse.getTotal(), equalTo(2L)); - assertThat(queryApiKeyResponse.getCount(), equalTo(1)); - assertThat(queryApiKeyResponse.getApiKeys().get(0).getName(), equalTo(createApiKeyResponse2.getName())); - assertThat(queryApiKeyResponse.getApiKeys().get(0).getId(), equalTo(createApiKeyResponse2.getId())); - } - - { - QueryApiKeyRequest queryApiKeyRequest = new QueryApiKeyRequest(); - - ActionListener listener; - // tag::query-api-key-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(QueryApiKeyResponse queryApiKeyResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::query-api-key-execute-listener - - // Avoid unused variable warning - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::query-api-key-execute-async - client.security().queryApiKeyAsync(queryApiKeyRequest, RequestOptions.DEFAULT, listener); // <1> - // end::query-api-key-execute-async - - final QueryApiKeyResponse queryApiKeyResponse = future.get(30, TimeUnit.SECONDS); - assertNotNull(queryApiKeyResponse); - - assertThat(queryApiKeyResponse.getTotal(), equalTo(2L)); - assertThat(queryApiKeyResponse.getCount(), equalTo(2)); - assertThat(queryApiKeyResponse.getApiKeys(), is(notNullValue())); - assertThat(queryApiKeyResponse.getApiKeys().size(), is(2)); - assertThat( - queryApiKeyResponse.getApiKeys().stream().map(ApiKey::getName).collect(Collectors.toUnmodifiableSet()), - equalTo(Set.of("key-10000", "key-20000")) - ); - assertThat( - queryApiKeyResponse.getApiKeys().stream().map(ApiKey::getId).collect(Collectors.toUnmodifiableSet()), - equalTo(Set.of(createApiKeyResponse1.getId(), createApiKeyResponse2.getId())) - ); - } - } - - public void testGetServiceAccounts() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - // tag::get-service-accounts-request - final GetServiceAccountsRequest getServiceAccountsRequest = new GetServiceAccountsRequest("elastic", "fleet-server"); - // end::get-service-accounts-request - - // tag::get-service-accounts-execute - final GetServiceAccountsResponse getServiceAccountsResponse = - client.security().getServiceAccounts(getServiceAccountsRequest, RequestOptions.DEFAULT); - // end::get-service-accounts-execute - - // tag::get-service-accounts-response - final ServiceAccountInfo serviceAccountInfo = getServiceAccountsResponse.getServiceAccountInfos().get(0); // <1> - // end::get-service-accounts-response - assertThat(serviceAccountInfo.getPrincipal(), equalTo("elastic/fleet-server")); - } - - { - // tag::get-service-accounts-request-namespace - final GetServiceAccountsRequest getServiceAccountsRequest = new GetServiceAccountsRequest("elastic"); - // end::get-service-accounts-request-namespace - } - - { - // tag::get-service-accounts-request-all - final GetServiceAccountsRequest getServiceAccountsRequest = new GetServiceAccountsRequest(); - // end::get-service-accounts-request-all - } - - { - final GetServiceAccountsRequest getServiceAccountsRequest = new GetServiceAccountsRequest("elastic", "fleet-server"); - - ActionListener listener; - // tag::get-service-accounts-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(GetServiceAccountsResponse getServiceAccountsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-service-accounts-execute-listener - - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::get-service-accounts-execute-async - client.security().getServiceAccountsAsync(getServiceAccountsRequest, RequestOptions.DEFAULT, listener); // <1> - // end::get-service-accounts-execute-async - - assertNotNull(future.actionGet()); - assertThat(future.actionGet().getServiceAccountInfos().size(), equalTo(1)); - assertThat(future.actionGet().getServiceAccountInfos().get(0).getPrincipal(), equalTo("elastic/fleet-server")); - } - } - - public void testCreateServiceAccountToken() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - // tag::create-service-account-token-request - CreateServiceAccountTokenRequest createServiceAccountTokenRequest = - new CreateServiceAccountTokenRequest("elastic", "fleet-server", "my_token_1"); - // end::create-service-account-token-request - - // tag::create-service-account-token-execute - CreateServiceAccountTokenResponse createServiceAccountTokenResponse = - client.security().createServiceAccountToken(createServiceAccountTokenRequest, RequestOptions.DEFAULT); - // end::create-service-account-token-execute - - // tag::create-service-account-token-response - final String tokenName = createServiceAccountTokenResponse.getName(); // <1> - final SecureString tokenValue = createServiceAccountTokenResponse.getValue(); // <2> - // end::create-service-account-token-response - assertThat(createServiceAccountTokenResponse.getName(), equalTo("my_token_1")); - assertNotNull(tokenValue); - } - - { - // tag::create-service-account-token-request-auto-name - CreateServiceAccountTokenRequest createServiceAccountTokenRequest = - new CreateServiceAccountTokenRequest("elastic", "fleet-server"); - // end::create-service-account-token-request-auto-name - - ActionListener listener; - // tag::create-service-account-token-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(CreateServiceAccountTokenResponse createServiceAccountTokenResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::create-service-account-token-execute-listener - - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::create-service-account-token-execute-async - client.security().createServiceAccountTokenAsync(createServiceAccountTokenRequest, RequestOptions.DEFAULT, listener); // <1> - // end::create-service-account-token-execute-async - - assertNotNull(future.actionGet()); - assertNotNull(future.actionGet().getName()); - assertNotNull(future.actionGet().getValue()); - } - } - - public void testDeleteServiceAccountToken() throws IOException { - RestHighLevelClient client = highLevelClient(); - final CreateServiceAccountTokenRequest createServiceAccountTokenRequest = new CreateServiceAccountTokenRequest( - "elastic", - "fleet-server", - "test-token" - ); - client.security().createServiceAccountToken(createServiceAccountTokenRequest, RequestOptions.DEFAULT); - { - // tag::delete-service-account-token-request - DeleteServiceAccountTokenRequest deleteServiceAccountTokenRequest = - new DeleteServiceAccountTokenRequest("elastic", "fleet-server", "test-token"); - // end::delete-service-account-token-request - - // tag::delete-service-account-token-execute - DeleteServiceAccountTokenResponse deleteServiceAccountTokenResponse = - client.security().deleteServiceAccountToken(deleteServiceAccountTokenRequest, RequestOptions.DEFAULT); - // end::delete-service-account-token-execute - - // tag::delete-service-account-token-response - final boolean found = deleteServiceAccountTokenResponse.isAcknowledged(); // <1> - // end::delete-service-account-token-response - assertTrue(deleteServiceAccountTokenResponse.isAcknowledged()); - } - - client.security().createServiceAccountToken(createServiceAccountTokenRequest, RequestOptions.DEFAULT); - { - DeleteServiceAccountTokenRequest deleteServiceAccountTokenRequest = new DeleteServiceAccountTokenRequest( - "elastic", - "fleet-server", - "test-token" - ); - ActionListener listener; - // tag::delete-service-account-token-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(DeleteServiceAccountTokenResponse deleteServiceAccountTokenResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-service-account-token-execute-listener - - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::delete-service-account-token-execute-async - client.security().deleteServiceAccountTokenAsync(deleteServiceAccountTokenRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-service-account-token-execute-async - - assertNotNull(future.actionGet()); - assertTrue(future.actionGet().isAcknowledged()); - } - } - - public void testGetServiceAccountCredentials() throws IOException { - RestHighLevelClient client = highLevelClient(); - final CreateServiceAccountTokenRequest createServiceAccountTokenRequest = new CreateServiceAccountTokenRequest( - "elastic", - "fleet-server", - "token2" - ); - final CreateServiceAccountTokenResponse createServiceAccountTokenResponse = client.security() - .createServiceAccountToken(createServiceAccountTokenRequest, RequestOptions.DEFAULT); - assertThat(createServiceAccountTokenResponse.getName(), equalTo("token2")); - - { - // tag::get-service-account-credentials-request - final GetServiceAccountCredentialsRequest getServiceAccountCredentialsRequest = - new GetServiceAccountCredentialsRequest("elastic", "fleet-server"); - // end::get-service-account-credentials-request - - // tag::get-service-account-credentials-execute - final GetServiceAccountCredentialsResponse getServiceAccountCredentialsResponse = - client.security().getServiceAccountCredentials(getServiceAccountCredentialsRequest, RequestOptions.DEFAULT); - // end::get-service-account-credentials-execute - - // tag::get-service-account-credentials-response - final String principal = getServiceAccountCredentialsResponse.getPrincipal(); // <1> - final List indexTokenInfos = getServiceAccountCredentialsResponse.getIndexTokenInfos(); // <2> - final String tokenName = indexTokenInfos.get(0).getName(); // <3> - final String tokenSource = indexTokenInfos.get(0).getSource(); // <4> - final Collection nodeNames = indexTokenInfos.get(0).getNodeNames(); // <5> - final List fileTokenInfos - = getServiceAccountCredentialsResponse.getNodesResponse().getFileTokenInfos(); // <6> - final NodesResponseHeader fileTokensResponseHeader - = getServiceAccountCredentialsResponse.getNodesResponse().getHeader(); // <7> - final int nSuccessful = fileTokensResponseHeader.getSuccessful(); // <8> - final int nFailed = fileTokensResponseHeader.getFailed(); // <9> - // end::get-service-account-credentials-response - assertThat(principal, equalTo("elastic/fleet-server")); - // Cannot assert exactly one token because there are rare occasions where tests overlap and it will see - // token created from other tests - assertThat(indexTokenInfos.size(), greaterThanOrEqualTo(1)); - assertThat(indexTokenInfos.stream().map(ServiceTokenInfo::getName).collect(Collectors.toSet()), hasItem("token2")); - assertThat(indexTokenInfos.stream().map(ServiceTokenInfo::getSource).collect(Collectors.toSet()), hasItem("index")); - } - - { - final GetServiceAccountCredentialsRequest getServiceAccountCredentialsRequest = new GetServiceAccountCredentialsRequest( - "elastic", - "fleet-server" - ); - - ActionListener listener; - // tag::get-service-account-credentials-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(GetServiceAccountCredentialsResponse getServiceAccountCredentialsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-service-account-credentials-execute-listener - - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - // tag::get-service-account-credentials-execute-async - client.security().getServiceAccountCredentialsAsync( - getServiceAccountCredentialsRequest, RequestOptions.DEFAULT, listener); // <1> - // end::get-service-account-credentials-execute-async - - assertNotNull(future.actionGet()); - assertThat(future.actionGet().getPrincipal(), equalTo("elastic/fleet-server")); - assertThat(future.actionGet().getIndexTokenInfos().size(), greaterThanOrEqualTo(1)); - assertThat( - future.actionGet().getIndexTokenInfos().stream().map(ServiceTokenInfo::getName).collect(Collectors.toSet()), - hasItem("token2") - ); - } - } - - public void testDelegatePkiAuthentication() throws Exception { - final RestHighLevelClient client = highLevelClient(); - X509Certificate clientCertificate = readCertForPkiDelegation("testClient.crt"); - X509Certificate intermediateCA = readCertForPkiDelegation("testIntermediateCA.crt"); - { - //tag::delegate-pki-request - DelegatePkiAuthenticationRequest request = new DelegatePkiAuthenticationRequest( - Arrays.asList(clientCertificate, intermediateCA)); - //end::delegate-pki-request - //tag::delegate-pki-execute - DelegatePkiAuthenticationResponse response = client.security().delegatePkiAuthentication(request, RequestOptions.DEFAULT); - //end::delegate-pki-execute - //tag::delegate-pki-response - String accessToken = response.getAccessToken(); // <1> - //end::delegate-pki-response - - RequestOptions.Builder optionsBuilder = RequestOptions.DEFAULT.toBuilder(); - optionsBuilder.addHeader("Authorization", "Bearer " + accessToken); - AuthenticateResponse resp = client.security().authenticate(optionsBuilder.build()); - User user = resp.getUser(); - assertThat(user, is(notNullValue())); - assertThat(user.getUsername(), is("Elasticsearch Test Client")); - RealmInfo authnRealm = resp.getAuthenticationRealm(); - assertThat(authnRealm, is(notNullValue())); - assertThat(authnRealm.getName(), is("pki1")); - assertThat(authnRealm.getType(), is("pki")); - assertThat(resp.getAuthenticationType(), is("token")); - } - - { - DelegatePkiAuthenticationRequest request = new DelegatePkiAuthenticationRequest( - Arrays.asList(clientCertificate, intermediateCA) - ); - ActionListener listener; - - //tag::delegate-pki-execute-listener - listener = new ActionListener() { - @Override - public void onResponse(DelegatePkiAuthenticationResponse getRolesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::delegate-pki-execute-listener - - assertNotNull(listener); - - // Replace the empty listener by a blocking listener in test - final PlainActionFuture future = new PlainActionFuture<>(); - listener = future; - - //tag::delegate-pki-execute-async - client.security().delegatePkiAuthenticationAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::delegate-pki-execute-async - - final DelegatePkiAuthenticationResponse response = future.get(30, TimeUnit.SECONDS); - String accessToken = response.getAccessToken(); - RequestOptions.Builder optionsBuilder = RequestOptions.DEFAULT.toBuilder(); - optionsBuilder.addHeader("Authorization", "Bearer " + accessToken); - AuthenticateResponse resp = client.security().authenticate(optionsBuilder.build()); - User user = resp.getUser(); - assertThat(user, is(notNullValue())); - assertThat(user.getUsername(), is("Elasticsearch Test Client")); - RealmInfo authnRealm = resp.getAuthenticationRealm(); - assertThat(authnRealm, is(notNullValue())); - assertThat(authnRealm.getName(), is("pki1")); - assertThat(authnRealm.getType(), is("pki")); - assertThat(resp.getAuthenticationType(), is("token")); - } - } - - private X509Certificate readCertForPkiDelegation(String certificateName) throws Exception { - Path path = getDataPath("/org/elasticsearch/client/security/delegate_pki/" + certificateName); - try (InputStream in = Files.newInputStream(path)) { - CertificateFactory factory = CertificateFactory.getInstance("X.509"); - return (X509Certificate) factory.generateCertificate(in); - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SnapshotClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SnapshotClientDocumentationIT.java deleted file mode 100644 index dabf3d97a988..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SnapshotClientDocumentationIT.java +++ /dev/null @@ -1,898 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse; -import org.elasticsearch.action.admin.cluster.snapshots.clone.CloneSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStats; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.cluster.SnapshotsInProgress; -import org.elasticsearch.cluster.metadata.RepositoryMetadata; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.core.Booleans; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.repositories.fs.FsRepository; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.snapshots.RestoreInfo; -import org.elasticsearch.snapshots.SnapshotId; -import org.elasticsearch.snapshots.SnapshotInfo; -import org.elasticsearch.snapshots.SnapshotShardFailure; -import org.elasticsearch.snapshots.SnapshotState; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.equalTo; - -/** - * This class is used to generate the Java Snapshot 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,macros"] - * -------------------------------------------------- - * include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[example] - * -------------------------------------------------- - * - * The column width of the code block is 84. If the code contains a line longer - * than 84, the line will be cut and a horizontal scroll bar will be displayed. - * (the code indentation of the tag is not included in the width) - */ -@SuppressWarnings("removal") -public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase { - - private static final String repositoryName = "test_repository"; - private static final String snapshotName = "test_snapshot"; - private static final String indexName = "test_index"; - - @Override - protected boolean waitForAllSnapshotsWiped() { - return true; - } - - public void testSnapshotCreateRepository() throws IOException { - RestHighLevelClient client = highLevelClient(); - - // tag::create-repository-request - PutRepositoryRequest request = new PutRepositoryRequest(); - // end::create-repository-request - - // tag::create-repository-create-settings - String locationKey = FsRepository.LOCATION_SETTING.getKey(); - String locationValue = "."; - String compressKey = FsRepository.COMPRESS_SETTING.getKey(); - boolean compressValue = true; - - Settings settings = Settings.builder() - .put(locationKey, locationValue) - .put(compressKey, compressValue) - .build(); // <1> - // end::create-repository-create-settings - - // tag::create-repository-request-repository-settings - request.settings(settings); // <1> - // end::create-repository-request-repository-settings - - { - // tag::create-repository-settings-builder - Settings.Builder settingsBuilder = Settings.builder() - .put(locationKey, locationValue) - .put(compressKey, compressValue); - request.settings(settingsBuilder); // <1> - // end::create-repository-settings-builder - } - { - // tag::create-repository-settings-map - Map map = new HashMap<>(); - map.put(locationKey, locationValue); - map.put(compressKey, compressValue); - request.settings(map); // <1> - // end::create-repository-settings-map - } - { - // tag::create-repository-settings-source - request.settings(""" - {"location": ".", "compress": "true"} - """, XContentType.JSON); // <1> - // end::create-repository-settings-source - } - - // tag::create-repository-request-name - request.name(repositoryName); // <1> - // end::create-repository-request-name - // tag::create-repository-request-type - request.type(FsRepository.TYPE); // <1> - // end::create-repository-request-type - - // tag::create-repository-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::create-repository-request-masterTimeout - // tag::create-repository-request-timeout - request.timeout(TimeValue.timeValueMinutes(1)); // <1> - request.timeout("1m"); // <2> - // end::create-repository-request-timeout - // tag::create-repository-request-verify - request.verify(true); // <1> - // end::create-repository-request-verify - - // tag::create-repository-execute - AcknowledgedResponse response = client.snapshot().createRepository(request, RequestOptions.DEFAULT); - // end::create-repository-execute - - // tag::create-repository-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::create-repository-response - assertTrue(acknowledged); - } - - public void testSnapshotCreateRepositoryAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - PutRepositoryRequest request = new PutRepositoryRequest(repositoryName); - - // tag::create-repository-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse putRepositoryResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::create-repository-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::create-repository-execute-async - client.snapshot().createRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::create-repository-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSnapshotGetRepository() throws IOException { - RestHighLevelClient client = highLevelClient(); - - createTestRepositories(); - - // tag::get-repository-request - GetRepositoriesRequest request = new GetRepositoriesRequest(); - // end::get-repository-request - - // tag::get-repository-request-repositories - String [] repositories = new String[] {repositoryName}; - request.repositories(repositories); // <1> - // end::get-repository-request-repositories - // tag::get-repository-request-local - request.local(true); // <1> - // end::get-repository-request-local - // tag::get-repository-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::get-repository-request-masterTimeout - - // tag::get-repository-execute - GetRepositoriesResponse response = client.snapshot().getRepository(request, RequestOptions.DEFAULT); - // end::get-repository-execute - - // tag::get-repository-response - List repositoryMetadataResponse = response.repositories(); - // end::get-repository-response - assertThat(1, equalTo(repositoryMetadataResponse.size())); - assertThat(repositoryName, equalTo(repositoryMetadataResponse.get(0).name())); - } - - public void testSnapshotGetRepositoryAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - GetRepositoriesRequest request = new GetRepositoriesRequest(); - - // tag::get-repository-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetRepositoriesResponse getRepositoriesResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-repository-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-repository-execute-async - client.snapshot().getRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-repository-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testRestoreSnapshot() throws IOException { - RestHighLevelClient client = highLevelClient(); - - createTestRepositories(); - createTestIndex(); - createTestSnapshots(); - - // tag::restore-snapshot-request - RestoreSnapshotRequest request = new RestoreSnapshotRequest(repositoryName, snapshotName); - // end::restore-snapshot-request - // we need to restore as a different index name - - // tag::restore-snapshot-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::restore-snapshot-request-masterTimeout - - // tag::restore-snapshot-request-waitForCompletion - request.waitForCompletion(true); // <1> - // end::restore-snapshot-request-waitForCompletion - - // tag::restore-snapshot-request-partial - request.partial(false); // <1> - // end::restore-snapshot-request-partial - - // tag::restore-snapshot-request-include-global-state - request.includeGlobalState(false); // <1> - // end::restore-snapshot-request-include-global-state - - // tag::restore-snapshot-request-include-aliases - request.includeAliases(false); // <1> - // end::restore-snapshot-request-include-aliases - - // tag::restore-snapshot-request-indices - request.indices("test_index"); // <1> - // end::restore-snapshot-request-indices - - String restoredIndexName = "restored_index"; - // tag::restore-snapshot-request-rename - request.renamePattern("test_(.+)"); // <1> - request.renameReplacement("restored_$1"); // <2> - // end::restore-snapshot-request-rename - - // tag::restore-snapshot-request-index-settings - request.indexSettings( // <1> - Settings.builder() - .put("index.number_of_replicas", 0) - .build()); - - request.ignoreIndexSettings("index.refresh_interval", "index.search.idle.after"); // <2> - request.indicesOptions(new IndicesOptions( // <3> - EnumSet.of(IndicesOptions.Option.IGNORE_UNAVAILABLE), - EnumSet.of(IndicesOptions.WildcardStates.OPEN))); - // end::restore-snapshot-request-index-settings - - // tag::restore-snapshot-execute - RestoreSnapshotResponse response = client.snapshot().restore(request, RequestOptions.DEFAULT); - // end::restore-snapshot-execute - - // tag::restore-snapshot-response - RestoreInfo restoreInfo = response.getRestoreInfo(); - List indices = restoreInfo.indices(); // <1> - // end::restore-snapshot-response - assertEquals(Collections.singletonList(restoredIndexName), indices); - assertEquals(0, restoreInfo.failedShards()); - assertTrue(restoreInfo.successfulShards() > 0); - } - - public void testRestoreSnapshotAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - RestoreSnapshotRequest request = new RestoreSnapshotRequest(); - - // tag::restore-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(RestoreSnapshotResponse restoreSnapshotResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::restore-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::restore-snapshot-execute-async - client.snapshot().restoreAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::restore-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSnapshotDeleteRepository() throws IOException { - RestHighLevelClient client = highLevelClient(); - - createTestRepositories(); - - // tag::delete-repository-request - DeleteRepositoryRequest request = new DeleteRepositoryRequest(repositoryName); - // end::delete-repository-request - - // tag::delete-repository-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::delete-repository-request-masterTimeout - // tag::delete-repository-request-timeout - request.timeout(TimeValue.timeValueMinutes(1)); // <1> - request.timeout("1m"); // <2> - // end::delete-repository-request-timeout - - // tag::delete-repository-execute - AcknowledgedResponse response = client.snapshot().deleteRepository(request, RequestOptions.DEFAULT); - // end::delete-repository-execute - - // tag::delete-repository-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::delete-repository-response - assertTrue(acknowledged); - } - - public void testSnapshotDeleteRepositoryAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - DeleteRepositoryRequest request = new DeleteRepositoryRequest(); - - // tag::delete-repository-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse deleteRepositoryResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-repository-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-repository-execute-async - client.snapshot().deleteRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-repository-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSnapshotVerifyRepository() throws IOException { - RestHighLevelClient client = highLevelClient(); - createTestRepositories(); - - // tag::verify-repository-request - VerifyRepositoryRequest request = new VerifyRepositoryRequest(repositoryName); - // end::verify-repository-request - - // tag::verify-repository-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::verify-repository-request-masterTimeout - // tag::verify-repository-request-timeout - request.timeout(TimeValue.timeValueMinutes(1)); // <1> - request.timeout("1m"); // <2> - // end::verify-repository-request-timeout - - // tag::verify-repository-execute - VerifyRepositoryResponse response = client.snapshot().verifyRepository(request, RequestOptions.DEFAULT); - // end::verify-repository-execute - - // tag::verify-repository-response - List repositoryMetadataResponse = response.getNodes(); - // end::verify-repository-response - assertThat(1, equalTo(repositoryMetadataResponse.size())); - final boolean async = Booleans.parseBoolean(System.getProperty("tests.rest.async", "false")); - if (async) { - assertThat("asyncIntegTest-0", equalTo(repositoryMetadataResponse.get(0).getName())); - } else { - assertThat("integTest-0", equalTo(repositoryMetadataResponse.get(0).getName())); - } - } - - public void testSnapshotVerifyRepositoryAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - VerifyRepositoryRequest request = new VerifyRepositoryRequest(repositoryName); - - // tag::verify-repository-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(VerifyRepositoryResponse verifyRepositoryRestResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::verify-repository-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::verify-repository-execute-async - client.snapshot().verifyRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::verify-repository-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSnapshotCreate() throws IOException { - RestHighLevelClient client = highLevelClient(); - - CreateIndexRequest createIndexRequest = new CreateIndexRequest("test-index0"); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - createIndexRequest = new CreateIndexRequest("test-index1"); - client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - - createTestRepositories(); - - // tag::create-snapshot-request - CreateSnapshotRequest request = new CreateSnapshotRequest(); - // end::create-snapshot-request - - // tag::create-snapshot-request-repositoryName - request.repository(repositoryName); // <1> - // end::create-snapshot-request-repositoryName - // tag::create-snapshot-request-snapshotName - request.snapshot(snapshotName); // <1> - // end::create-snapshot-request-snapshotName - // tag::create-snapshot-request-indices - request.indices("test-index0", "test-index1"); // <1> - // end::create-snapshot-request-indices - // tag::create-snapshot-request-indicesOptions - request.indicesOptions(IndicesOptions.fromOptions(false, false, true, true)); // <1> - // end::create-snapshot-request-indicesOptions - // tag::create-snapshot-request-partial - request.partial(false); // <1> - // end::create-snapshot-request-partial - // tag::create-snapshot-request-includeGlobalState - request.includeGlobalState(true); // <1> - // end::create-snapshot-request-includeGlobalState - - // tag::create-snapshot-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::create-snapshot-request-masterTimeout - // tag::create-snapshot-request-waitForCompletion - request.waitForCompletion(true); // <1> - // end::create-snapshot-request-waitForCompletion - - // tag::create-snapshot-execute - CreateSnapshotResponse response = client.snapshot().create(request, RequestOptions.DEFAULT); - // end::create-snapshot-execute - - // tag::create-snapshot-response - RestStatus status = response.status(); // <1> - // end::create-snapshot-response - - assertEquals(RestStatus.OK, status); - - // tag::create-snapshot-response-snapshot-info - SnapshotInfo snapshotInfo = response.getSnapshotInfo(); // <1> - // end::create-snapshot-response-snapshot-info - - assertNotNull(snapshotInfo); - } - - public void testSnapshotCreateAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - CreateSnapshotRequest request = new CreateSnapshotRequest(repositoryName, snapshotName); - - // tag::create-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(CreateSnapshotResponse createSnapshotResponse) { - // <1> - } - - @Override - public void onFailure(Exception exception) { - // <2> - } - }; - // end::create-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::create-snapshot-execute-async - client.snapshot().createAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::create-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testSnapshotGetSnapshots() throws IOException { - RestHighLevelClient client = highLevelClient(); - - createTestRepositories(); - createTestIndex(); - createTestSnapshots(); - - // tag::get-snapshots-request - GetSnapshotsRequest request = new GetSnapshotsRequest(); - // end::get-snapshots-request - - // tag::get-snapshots-request-repositoryName - request.repositories(repositoryName); // <1> - // end::get-snapshots-request-repositoryName - - // tag::get-snapshots-request-snapshots - String[] snapshots = { snapshotName }; - request.snapshots(snapshots); // <1> - // end::get-snapshots-request-snapshots - - // tag::get-snapshots-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::get-snapshots-request-masterTimeout - - // tag::get-snapshots-request-verbose - request.verbose(true); // <1> - // end::get-snapshots-request-verbose - - // tag::get-snapshots-request-ignore-unavailable - request.ignoreUnavailable(false); // <1> - // end::get-snapshots-request-ignore-unavailable - - // tag::get-snapshots-execute - GetSnapshotsResponse response = client.snapshot().get(request, RequestOptions.DEFAULT); - // end::get-snapshots-execute - - // tag::get-snapshots-response - List snapshotsInfos = response.getSnapshots(); - SnapshotInfo snapshotInfo = snapshotsInfos.get(0); - RestStatus restStatus = snapshotInfo.status(); // <1> - SnapshotId snapshotId = snapshotInfo.snapshotId(); // <2> - SnapshotState snapshotState = snapshotInfo.state(); // <3> - List snapshotShardFailures = snapshotInfo.shardFailures(); // <4> - long startTime = snapshotInfo.startTime(); // <5> - long endTime = snapshotInfo.endTime(); // <6> - // end::get-snapshots-response - assertEquals(1, snapshotsInfos.size()); - } - - public void testSnapshotGetSnapshotsAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - GetSnapshotsRequest request = new GetSnapshotsRequest(repositoryName); - - // tag::get-snapshots-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetSnapshotsResponse getSnapshotsResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-snapshots-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-snapshots-execute-async - client.snapshot().getAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-snapshots-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSnapshotSnapshotsStatus() throws IOException { - RestHighLevelClient client = highLevelClient(); - createTestRepositories(); - createTestIndex(); - createTestSnapshots(); - - // tag::snapshots-status-request - SnapshotsStatusRequest request = new SnapshotsStatusRequest(); - // end::snapshots-status-request - - // tag::snapshots-status-request-repository - request.repository(repositoryName); // <1> - // end::snapshots-status-request-repository - // tag::snapshots-status-request-snapshots - String [] snapshots = new String[] {snapshotName}; - request.snapshots(snapshots); // <1> - // end::snapshots-status-request-snapshots - // tag::snapshots-status-request-ignoreUnavailable - request.ignoreUnavailable(true); // <1> - // end::snapshots-status-request-ignoreUnavailable - // tag::snapshots-status-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::snapshots-status-request-masterTimeout - - // tag::snapshots-status-execute - SnapshotsStatusResponse response = client.snapshot().status(request, RequestOptions.DEFAULT); - // end::snapshots-status-execute - - // tag::snapshots-status-response - List snapshotStatusesResponse = response.getSnapshots(); - SnapshotStatus snapshotStatus = snapshotStatusesResponse.get(0); // <1> - SnapshotsInProgress.State snapshotState = snapshotStatus.getState(); // <2> - SnapshotStats shardStats = snapshotStatus.getIndices().get(indexName).getShards().get(0).getStats(); // <3> - // end::snapshots-status-response - assertThat(snapshotStatusesResponse.size(), equalTo(1)); - assertThat(snapshotStatusesResponse.get(0).getSnapshot().getRepository(), equalTo(SnapshotClientDocumentationIT.repositoryName)); - assertThat(snapshotStatusesResponse.get(0).getSnapshot().getSnapshotId().getName(), equalTo(snapshotName)); - assertThat(snapshotState.completed(), equalTo(true)); - } - - public void testSnapshotSnapshotsStatusAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - SnapshotsStatusRequest request = new SnapshotsStatusRequest(); - - // tag::snapshots-status-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(SnapshotsStatusResponse snapshotsStatusResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::snapshots-status-execute-listener - - // Replace the empty listener with a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::snapshots-status-execute-async - client.snapshot().statusAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::snapshots-status-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testSnapshotDeleteSnapshot() throws IOException { - RestHighLevelClient client = highLevelClient(); - - createTestRepositories(); - createTestIndex(); - createTestSnapshots(); - - // tag::delete-snapshot-request - DeleteSnapshotRequest request = new DeleteSnapshotRequest(repositoryName); - request.snapshots(snapshotName); - // end::delete-snapshot-request - - // tag::delete-snapshot-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::delete-snapshot-request-masterTimeout - - // tag::delete-snapshot-execute - AcknowledgedResponse response = client.snapshot().delete(request, RequestOptions.DEFAULT); - // end::delete-snapshot-execute - - // tag::delete-snapshot-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::delete-snapshot-response - assertTrue(acknowledged); - } - - public void testSnapshotDeleteSnapshotAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - DeleteSnapshotRequest request = new DeleteSnapshotRequest(); - - // tag::delete-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse deleteSnapshotResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-snapshot-execute-async - client.snapshot().deleteAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testCloneSnapshot() throws IOException { - RestHighLevelClient client = highLevelClient(); - - createTestRepositories(); - createTestIndex(); - createTestSnapshots(); - - String sourceSnapshotName = snapshotName; - String targetSnapshotName = snapshotName + "_clone"; - String[] indices = new String[] { indexName }; - - // tag::clone-snapshot-request - CloneSnapshotRequest request = new CloneSnapshotRequest(repositoryName, sourceSnapshotName, targetSnapshotName, indices); - // end::clone-snapshot-request - - // tag::clone-snapshot-request-indices - request.indices("test_index"); // <1> - // end::clone-snapshot-request-indices - - // tag::clone-snapshot-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::clone-snapshot-request-masterTimeout - - // tag::clone-snapshot-request-index-settings - request.indicesOptions(new IndicesOptions( - EnumSet.of(IndicesOptions.Option.IGNORE_UNAVAILABLE), // <1> - EnumSet.of( - IndicesOptions.WildcardStates.OPEN, - IndicesOptions.WildcardStates.CLOSED, - IndicesOptions.WildcardStates.HIDDEN)) - ); - // end::clone-snapshot-request-index-settings - - // tag::clone-snapshot-execute - AcknowledgedResponse response = client.snapshot().clone(request, RequestOptions.DEFAULT); - // end::clone-snapshot-execute - - // tag::clone-snapshot-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::clone-snapshot-response - assertTrue(acknowledged); - } - - public void testCloneSnapshotAsync() throws InterruptedException { - RestHighLevelClient client = highLevelClient(); - { - String targetSnapshot = snapshotName + "_clone"; - CloneSnapshotRequest request = new CloneSnapshotRequest( - repositoryName, - snapshotName, - targetSnapshot, - new String[] { indexName } - ); - - // tag::clone-snapshot-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse acknowledgedResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::clone-snapshot-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::clone-snapshot-execute-async - client.snapshot().cloneAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::clone-snapshot-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - private void createTestRepositories() throws IOException { - PutRepositoryRequest request = new PutRepositoryRequest(repositoryName); - request.type(FsRepository.TYPE); - request.settings("{\"location\": \".\"}", XContentType.JSON); - assertTrue(highLevelClient().snapshot().createRepository(request, RequestOptions.DEFAULT).isAcknowledged()); - } - - private void createTestIndex() throws IOException { - createIndex(indexName, Settings.EMPTY); - } - - private void createTestSnapshots() throws IOException { - Request createSnapshot = new Request("put", String.format(Locale.ROOT, "_snapshot/%s/%s", repositoryName, snapshotName)); - createSnapshot.addParameter("wait_for_completion", "true"); - createSnapshot.setJsonEntity("{\"indices\":\"" + indexName + "\"}"); - Response response = highLevelClient().getLowLevelClient().performRequest(createSnapshot); - // check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead. - assertEquals(200, response.getStatusLine().getStatusCode()); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/StoredScriptsDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/StoredScriptsDocumentationIT.java deleted file mode 100644 index 0b93a5bbf11f..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/StoredScriptsDocumentationIT.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; -import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; -import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse; -import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.script.Script; -import org.elasticsearch.script.StoredScriptSource; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentFactory; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.equalTo; - -/** - * This class is used to generate the Java Stored Scripts 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,macros"] - * -------------------------------------------------- - * include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[example] - * -------------------------------------------------- - * - * The column width of the code block is 84. If the code contains a line longer - * than 84, the line will be cut and a horizontal scroll bar will be displayed. - * (the code indentation of the tag is not included in the width) - */ -@SuppressWarnings("removal") -public class StoredScriptsDocumentationIT extends ESRestHighLevelClientTestCase { - - @SuppressWarnings("unused") - public void testGetStoredScript() throws Exception { - RestHighLevelClient client = highLevelClient(); - - final StoredScriptSource scriptSource = new StoredScriptSource( - "painless", - "Math.log(_score * 2) + params.my_modifier", - Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()) - ); - - putStoredScript("calculate-score", scriptSource); - - { - // tag::get-stored-script-request - GetStoredScriptRequest request = new GetStoredScriptRequest("calculate-score"); // <1> - // end::get-stored-script-request - - // tag::get-stored-script-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueSeconds(50)); // <1> - request.masterNodeTimeout("50s"); // <2> - // end::get-stored-script-request-masterTimeout - - // tag::get-stored-script-execute - GetStoredScriptResponse getResponse = client.getScript(request, RequestOptions.DEFAULT); - // end::get-stored-script-execute - - // tag::get-stored-script-response - StoredScriptSource storedScriptSource = getResponse.getSource(); // <1> - - String lang = storedScriptSource.getLang(); // <2> - String source = storedScriptSource.getSource(); // <3> - Map options = storedScriptSource.getOptions(); // <4> - // end::get-stored-script-response - - assertThat(storedScriptSource, equalTo(scriptSource)); - - // tag::get-stored-script-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetStoredScriptResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-stored-script-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-stored-script-execute-async - client.getScriptAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-stored-script-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - } - - @SuppressWarnings("unused") - public void testDeleteStoredScript() throws Exception { - RestHighLevelClient client = highLevelClient(); - - final StoredScriptSource scriptSource = new StoredScriptSource( - "painless", - "Math.log(_score * 2) + params.my_modifier", - Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()) - ); - - putStoredScript("calculate-score", scriptSource); - - // tag::delete-stored-script-request - DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest("calculate-score"); // <1> - // end::delete-stored-script-request - - // tag::delete-stored-script-request-masterTimeout - deleteRequest.masterNodeTimeout(TimeValue.timeValueSeconds(50)); // <1> - deleteRequest.masterNodeTimeout("50s"); // <2> - // end::delete-stored-script-request-masterTimeout - - // tag::delete-stored-script-request-timeout - deleteRequest.timeout(TimeValue.timeValueSeconds(60)); // <1> - deleteRequest.timeout("60s"); // <2> - // end::delete-stored-script-request-timeout - - // tag::delete-stored-script-execute - AcknowledgedResponse deleteResponse = client.deleteScript(deleteRequest, RequestOptions.DEFAULT); - // end::delete-stored-script-execute - - // tag::delete-stored-script-response - boolean acknowledged = deleteResponse.isAcknowledged();// <1> - // end::delete-stored-script-response - - putStoredScript("calculate-score", scriptSource); - - // tag::delete-stored-script-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-stored-script-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-stored-script-execute-async - client.deleteScriptAsync(deleteRequest, RequestOptions.DEFAULT, listener); // <1> - // end::delete-stored-script-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - public void testPutScript() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::put-stored-script-request - PutStoredScriptRequest request = new PutStoredScriptRequest(); - request.id("id"); // <1> - request.content(new BytesArray(""" - { - "script": { - "lang": "painless", - "source": "Math.log(_score * 2) + params.multiplier" - } - } - """ - ), XContentType.JSON); // <2> - // end::put-stored-script-request - - // tag::put-stored-script-context - request.context("context"); // <1> - // end::put-stored-script-context - - // tag::put-stored-script-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::put-stored-script-timeout - - // tag::put-stored-script-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::put-stored-script-masterTimeout - } - - { - PutStoredScriptRequest request = new PutStoredScriptRequest(); - request.id("id"); - - // tag::put-stored-script-content-painless - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.startObject("script"); - { - builder.field("lang", "painless"); - builder.field("source", "Math.log(_score * 2) + params.multiplier"); - } - builder.endObject(); - } - builder.endObject(); - request.content(BytesReference.bytes(builder), XContentType.JSON); // <1> - // end::put-stored-script-content-painless - - // tag::put-stored-script-execute - AcknowledgedResponse putStoredScriptResponse = client.putScript(request, RequestOptions.DEFAULT); - // end::put-stored-script-execute - - // tag::put-stored-script-response - boolean acknowledged = putStoredScriptResponse.isAcknowledged(); // <1> - // end::put-stored-script-response - - assertTrue(acknowledged); - - // tag::put-stored-script-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-stored-script-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-stored-script-execute-async - client.putScriptAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::put-stored-script-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - PutStoredScriptRequest request = new PutStoredScriptRequest(); - request.id("id"); - - // tag::put-stored-script-content-mustache - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.startObject("script"); - { - builder.field("lang", "mustache"); - builder.field("source", """ - {"query":{"match":{"title":"{{query_string}}"}}}"""); - } - builder.endObject(); - } - builder.endObject(); - request.content(BytesReference.bytes(builder), XContentType.JSON); // <1> - // end::put-stored-script-content-mustache - - client.putScript(request, RequestOptions.DEFAULT); - - Map script = getAsMap("/_scripts/id"); - assertThat(extractValue("script.lang", script), equalTo("mustache")); - assertThat(extractValue("script.source", script), equalTo(""" - {"query":{"match":{"title":"{{query_string}}"}}}""")); - } - } - - private void putStoredScript(String id, StoredScriptSource scriptSource) throws IOException { - PutStoredScriptRequest request = new PutStoredScriptRequest(id, "score", new BytesArray("{}"), XContentType.JSON, scriptSource); - assertAcked(execute(request, highLevelClient()::putScript, highLevelClient()::putScriptAsync)); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TasksClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TasksClientDocumentationIT.java deleted file mode 100644 index 2a541255409f..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TasksClientDocumentationIT.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.TaskOperationFailure; -import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest; -import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; -import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.tasks.CancelTasksRequest; -import org.elasticsearch.client.tasks.CancelTasksResponse; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.tasks.TaskId; -import org.elasticsearch.tasks.TaskInfo; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static java.util.Collections.emptyList; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.notNullValue; - -/** - * This class is used to generate the Java Tasks 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,macros"] - * -------------------------------------------------- - * include-tagged::{doc-tests}/{@link TasksClientDocumentationIT}.java[example] - * -------------------------------------------------- - * - * The column width of the code block is 84. If the code contains a line longer - * than 84, the line will be cut and a horizontal scroll bar will be displayed. - * (the code indentation of the tag is not included in the width) - */ -@SuppressWarnings("removal") -public class TasksClientDocumentationIT extends ESRestHighLevelClientTestCase { - - @SuppressWarnings("unused") - public void testListTasks() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - // tag::list-tasks-request - ListTasksRequest request = new ListTasksRequest(); - // end::list-tasks-request - - // tag::list-tasks-request-filter - request.setActions("cluster:*"); // <1> - request.setNodes("nodeId1", "nodeId2"); // <2> - request.setTargetParentTaskId(new TaskId("parentTaskId", 42)); // <3> - // end::list-tasks-request-filter - - // tag::list-tasks-request-detailed - request.setDetailed(true); // <1> - // end::list-tasks-request-detailed - - // tag::list-tasks-request-wait-completion - request.setWaitForCompletion(true); // <1> - request.setTimeout(TimeValue.timeValueSeconds(50)); // <2> - request.setTimeout("50s"); // <3> - // end::list-tasks-request-wait-completion - } - - ListTasksRequest request = new ListTasksRequest(); - - // tag::list-tasks-execute - ListTasksResponse response = client.tasks().list(request, RequestOptions.DEFAULT); - // end::list-tasks-execute - - assertThat(response, notNullValue()); - - // tag::list-tasks-response-tasks - List tasks = response.getTasks(); // <1> - // end::list-tasks-response-tasks - - // tag::list-tasks-response-calc - Map> perNodeTasks = response.getPerNodeTasks(); // <1> - List groups = response.getTaskGroups(); // <2> - // end::list-tasks-response-calc - - // tag::list-tasks-response-failures - List nodeFailures = response.getNodeFailures(); // <1> - List taskFailures = response.getTaskFailures(); // <2> - // end::list-tasks-response-failures - - assertThat(response.getNodeFailures(), equalTo(emptyList())); - assertThat(response.getTaskFailures(), equalTo(emptyList())); - assertThat(response.getTasks().size(), greaterThanOrEqualTo(2)); - } - - public void testListTasksAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - ListTasksRequest request = new ListTasksRequest(); - - // tag::list-tasks-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ListTasksResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::list-tasks-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::list-tasks-execute-async - client.tasks().listAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::list-tasks-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - @SuppressWarnings("unused") - public void testCancelTasks() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - // tag::cancel-tasks-request - CancelTasksRequest request = new org.elasticsearch.client.tasks.CancelTasksRequest.Builder() - .withNodesFiltered(List.of("nodeId1", "nodeId2")) - .withActionsFiltered(List.of("cluster:*")) - .build(); - // end::cancel-tasks-request - - // tag::cancel-tasks-request-filter - CancelTasksRequest byTaskIdRequest = new org.elasticsearch.client.tasks.CancelTasksRequest.Builder() // <1> - .withTaskId(new org.elasticsearch.client.tasks.TaskId("myNode",44L)) // <2> - .withWaitForCompletion(true) // <3> - .build(); // <4> - // end::cancel-tasks-request-filter - - } - - CancelTasksRequest request = new org.elasticsearch.client.tasks.CancelTasksRequest.Builder().build(); - - // tag::cancel-tasks-execute - CancelTasksResponse response = client.tasks().cancel(request, RequestOptions.DEFAULT); - // end::cancel-tasks-execute - - assertThat(response, notNullValue()); - - // tag::cancel-tasks-response-tasks - List tasks = response.getTasks(); // <1> - // end::cancel-tasks-response-tasks - - // tag::cancel-tasks-response-calc - Map> perNodeTasks = response.getPerNodeTasks(); // <1> - List groups = response.getTaskGroups(); // <2> - // end::cancel-tasks-response-calc - - // tag::cancel-tasks-response-failures - List nodeFailures = response.getNodeFailures(); // <1> - List taskFailures = response.getTaskFailures(); // <2> - // end::cancel-tasks-response-failures - - assertThat(response.getNodeFailures(), equalTo(emptyList())); - assertThat(response.getTaskFailures(), equalTo(emptyList())); - } - - public void testAsyncCancelTasks() throws InterruptedException { - - RestHighLevelClient client = highLevelClient(); - { - CancelTasksRequest request = new org.elasticsearch.client.tasks.CancelTasksRequest.Builder().build(); - - // tag::cancel-tasks-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(CancelTasksResponse response) { - // <1> - } - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::cancel-tasks-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::cancel-tasks-execute-async - client.tasks().cancelAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::cancel-tasks-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TextStructureClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TextStructureClientDocumentationIT.java deleted file mode 100644 index bcac9ff5e520..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TextStructureClientDocumentationIT.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.textstructure.FindStructureRequest; -import org.elasticsearch.client.textstructure.FindStructureResponse; -import org.elasticsearch.client.textstructure.structurefinder.TextStructure; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -@SuppressWarnings("removal") -public class TextStructureClientDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testFindStructure() throws Exception { - RestHighLevelClient client = highLevelClient(); - - Path anInterestingFile = createTempFile(); - String contents = """ - {"logger":"controller","timestamp":1478261151445,"level":"INFO","pid":42,"thread":"0x7fff7d2a8000","message":"message 1",\ - "class":"ml","method":"core::SomeNoiseMaker","file":"Noisemaker.cc","line":333} - {"logger":"controller","timestamp":1478261151445,"level":"INFO","pid":42,"thread":"0x7fff7d2a8000","message":"message 2",\ - "class":"ml","method":"core::SomeNoiseMaker","file":"Noisemaker.cc","line":333} - """; - Files.write(anInterestingFile, Collections.singleton(contents), StandardCharsets.UTF_8); - - { - // tag::find-structure-request - FindStructureRequest request = new FindStructureRequest(); // <1> - request.setSample(Files.readAllBytes(anInterestingFile)); // <2> - // end::find-structure-request - - // tag::find-structure-request-options - request.setLinesToSample(500); // <1> - request.setExplain(true); // <2> - // end::find-structure-request-options - - // tag::find-structure-execute - FindStructureResponse response = client - .textStructure() - .findStructure( - request, - RequestOptions.DEFAULT - ); - // end::find-structure-execute - - // tag::find-structure-response - TextStructure structure = response.getFileStructure(); // <1> - // end::find-structure-response - assertEquals(2, structure.getNumLinesAnalyzed()); - } - { - // tag::find-structure-execute-listener - ActionListener listener = new ActionListener<>() { - @Override - public void onResponse(FindStructureResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::find-structure-execute-listener - FindStructureRequest request = new FindStructureRequest(); - request.setSample(Files.readAllBytes(anInterestingFile)); - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::find-structure-execute-async - client - .textStructure() - .findStructureAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::find-structure-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TransformDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TransformDocumentationIT.java deleted file mode 100644 index acb31798d658..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TransformDocumentationIT.java +++ /dev/null @@ -1,749 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.AcknowledgedResponse; -import org.elasticsearch.client.core.PageParams; -import org.elasticsearch.client.indices.CreateIndexRequest; -import org.elasticsearch.client.indices.CreateIndexResponse; -import org.elasticsearch.client.transform.DeleteTransformRequest; -import org.elasticsearch.client.transform.GetTransformRequest; -import org.elasticsearch.client.transform.GetTransformResponse; -import org.elasticsearch.client.transform.GetTransformStatsRequest; -import org.elasticsearch.client.transform.GetTransformStatsResponse; -import org.elasticsearch.client.transform.PreviewTransformRequest; -import org.elasticsearch.client.transform.PreviewTransformResponse; -import org.elasticsearch.client.transform.PutTransformRequest; -import org.elasticsearch.client.transform.StartTransformRequest; -import org.elasticsearch.client.transform.StartTransformResponse; -import org.elasticsearch.client.transform.StopTransformRequest; -import org.elasticsearch.client.transform.StopTransformResponse; -import org.elasticsearch.client.transform.UpdateTransformRequest; -import org.elasticsearch.client.transform.UpdateTransformResponse; -import org.elasticsearch.client.transform.transforms.DestConfig; -import org.elasticsearch.client.transform.transforms.NodeAttributes; -import org.elasticsearch.client.transform.transforms.QueryConfig; -import org.elasticsearch.client.transform.transforms.RetentionPolicyConfig; -import org.elasticsearch.client.transform.transforms.SettingsConfig; -import org.elasticsearch.client.transform.transforms.SourceConfig; -import org.elasticsearch.client.transform.transforms.SyncConfig; -import org.elasticsearch.client.transform.transforms.TimeRetentionPolicyConfig; -import org.elasticsearch.client.transform.transforms.TimeSyncConfig; -import org.elasticsearch.client.transform.transforms.TransformConfig; -import org.elasticsearch.client.transform.transforms.TransformConfigUpdate; -import org.elasticsearch.client.transform.transforms.TransformIndexerStats; -import org.elasticsearch.client.transform.transforms.TransformProgress; -import org.elasticsearch.client.transform.transforms.TransformStats; -import org.elasticsearch.client.transform.transforms.pivot.AggregationConfig; -import org.elasticsearch.client.transform.transforms.pivot.GroupConfig; -import org.elasticsearch.client.transform.transforms.pivot.PivotConfig; -import org.elasticsearch.client.transform.transforms.pivot.TermsGroupSource; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.query.MatchAllQueryBuilder; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.xcontent.XContentBuilder; -import org.junit.After; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; - -@SuppressWarnings("removal") -public class TransformDocumentationIT extends ESRestHighLevelClientTestCase { - - private List transformsToClean = new ArrayList<>(); - - @After - public void cleanUpTransforms() throws Exception { - for (String transformId : transformsToClean) { - adminHighLevelClient().transform() - .stopTransform(new StopTransformRequest(transformId, true, TimeValue.timeValueSeconds(20), false), RequestOptions.DEFAULT); - } - - for (String transformId : transformsToClean) { - adminHighLevelClient().transform().deleteTransform(new DeleteTransformRequest(transformId), RequestOptions.DEFAULT); - } - - transformsToClean = new ArrayList<>(); - waitForPendingTasks(adminClient()); - } - - private void createIndex(String indexName) throws IOException { - - XContentBuilder builder = jsonBuilder(); - builder.startObject() - .startObject("properties") - .startObject("timestamp") - .field("type", "date") - .endObject() - .startObject("user_id") - .field("type", "keyword") - .endObject() - .startObject("stars") - .field("type", "integer") - .endObject() - .endObject() - .endObject(); - - CreateIndexRequest request = new CreateIndexRequest(indexName); - request.mapping(builder); - CreateIndexResponse response = highLevelClient().indices().create(request, RequestOptions.DEFAULT); - assertTrue(response.isAcknowledged()); - } - - public void testPutTransform() throws IOException, InterruptedException { - createIndex("source-index"); - - RestHighLevelClient client = highLevelClient(); - - // tag::put-transform-query-config - QueryConfig queryConfig = new QueryConfig(new MatchAllQueryBuilder()); - // end::put-transform-query-config - // tag::put-transform-source-config - SourceConfig sourceConfig = SourceConfig.builder() - .setIndex("source-index") - .setQueryConfig(queryConfig).build(); - // end::put-transform-source-config - // tag::put-transform-dest-config - DestConfig destConfig = DestConfig.builder() - .setIndex("pivot-destination") - .setPipeline("my-pipeline").build(); - // end::put-transform-dest-config - destConfig = DestConfig.builder().setIndex("pivot-destination").build(); - // tag::put-transform-group-config - GroupConfig groupConfig = GroupConfig.builder() - .groupBy("reviewer", // <1> - TermsGroupSource.builder().setField("user_id").build()) // <2> - .build(); - // end::put-transform-group-config - // tag::put-transform-agg-config - AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); - aggBuilder.addAggregator( - AggregationBuilders.avg("avg_rating").field("stars")); // <1> - AggregationConfig aggConfig = new AggregationConfig(aggBuilder); - // end::put-transform-agg-config - // tag::put-transform-pivot-config - PivotConfig pivotConfig = PivotConfig.builder() - .setGroups(groupConfig) // <1> - .setAggregationConfig(aggConfig) // <2> - .build(); - // end::put-transform-pivot-config - // tag::put-transform-settings-config - SettingsConfig settings = SettingsConfig.builder() - .setMaxPageSearchSize(1000) // <1> - .build(); - // end::put-transform-settings-config - // tag::put-transform-retention-policy-config - RetentionPolicyConfig retentionPolicy = TimeRetentionPolicyConfig.builder() - .setField("time-field") // <1> - .setMaxAge(TimeValue.timeValueDays(30)) // <2> - .build(); - // end::put-transform-retention-policy-config - // tag::put-transform-sync-config - SyncConfig syncConfig = TimeSyncConfig.builder() - .setField("time-field") // <1> - .setDelay(TimeValue.timeValueSeconds(30)) // <2> - .build(); - // end::put-transform-sync-config - // tag::put-transform-config - TransformConfig transformConfig = TransformConfig - .builder() - .setId("reviewer-avg-rating") // <1> - .setSource(sourceConfig) // <2> - .setDest(destConfig) // <3> - .setFrequency(TimeValue.timeValueSeconds(15)) // <4> - .setPivotConfig(pivotConfig) // <5> - .setDescription("This is my test transform") // <6> - .setSettings(settings) // <7> - .setRetentionPolicyConfig(retentionPolicy) // <8> - .setSyncConfig(syncConfig) // <9> - .build(); - // end::put-transform-config - - { - // tag::put-transform-request - PutTransformRequest request = - new PutTransformRequest(transformConfig); // <1> - request.setDeferValidation(false); // <2> - // end::put-transform-request - - // tag::put-transform-execute - AcknowledgedResponse response = - client.transform().putTransform( - request, RequestOptions.DEFAULT); - // end::put-transform-execute - transformsToClean.add(request.getConfig().getId()); - - assertTrue(response.isAcknowledged()); - } - { - TransformConfig configWithDifferentId = TransformConfig.builder() - .setId("reviewer-avg-rating2") - .setSource(transformConfig.getSource()) - .setDest(transformConfig.getDestination()) - .setPivotConfig(transformConfig.getPivotConfig()) - .build(); - PutTransformRequest request = new PutTransformRequest(configWithDifferentId); - - // tag::put-transform-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-transform-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-transform-execute-async - client.transform().putTransformAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::put-transform-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - transformsToClean.add(request.getConfig().getId()); - } - } - - public void testUpdateTransform() throws IOException, InterruptedException { - createIndex("source-data"); - - RestHighLevelClient client = highLevelClient(); - QueryConfig queryConfig = new QueryConfig(new MatchAllQueryBuilder()); - GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); - AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); - aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars")); - AggregationConfig aggConfig = new AggregationConfig(aggBuilder); - PivotConfig pivotConfig = PivotConfig.builder().setGroups(groupConfig).setAggregationConfig(aggConfig).build(); - - TransformConfig transformConfig = TransformConfig.builder() - .setId("my-transform-to-update") - .setSource(SourceConfig.builder().setIndex("source-data").setQueryConfig(queryConfig).build()) - .setDest(DestConfig.builder().setIndex("pivot-dest").build()) - .setPivotConfig(pivotConfig) - .setSyncConfig(TimeSyncConfig.builder().setField("time-field").setDelay(TimeValue.timeValueSeconds(120)).build()) - .build(); - - client.transform().putTransform(new PutTransformRequest(transformConfig), RequestOptions.DEFAULT); - transformsToClean.add(transformConfig.getId()); - - // tag::update-transform-config - TransformConfigUpdate update = TransformConfigUpdate - .builder() - .setSource(SourceConfig.builder() - .setIndex("source-data") - .build()) // <1> - .setDest(DestConfig.builder() - .setIndex("pivot-dest") - .build()) // <2> - .setFrequency(TimeValue.timeValueSeconds(15)) // <3> - .setSyncConfig(TimeSyncConfig.builder() - .setField("time-field") - .setDelay(TimeValue.timeValueSeconds(120)) - .build()) // <4> - .setDescription("This is my updated transform") // <5> - .setRetentionPolicyConfig(TimeRetentionPolicyConfig.builder() - .setField("time-field") - .setMaxAge(TimeValue.timeValueDays(30)) - .build()) // <6> - .build(); - // end::update-transform-config - - { - // tag::update-transform-request - UpdateTransformRequest request = - new UpdateTransformRequest( - update, // <1> - "my-transform-to-update"); // <2> - request.setDeferValidation(false); // <3> - // end::update-transform-request - - // tag::update-transform-execute - UpdateTransformResponse response = - client.transform().updateTransform(request, - RequestOptions.DEFAULT); - TransformConfig updatedConfig = - response.getTransformConfiguration(); - // end::update-transform-execute - - assertThat(updatedConfig.getDescription(), equalTo("This is my updated transform")); - } - { - UpdateTransformRequest request = new UpdateTransformRequest(update, "my-transform-to-update"); - - // tag::update-transform-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(UpdateTransformResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::update-transform-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::update-transform-execute-async - client.transform().updateTransformAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::update-transform-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testStartStop() throws IOException, InterruptedException { - createIndex("source-data"); - - RestHighLevelClient client = highLevelClient(); - - QueryConfig queryConfig = new QueryConfig(new MatchAllQueryBuilder()); - GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); - AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); - aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars")); - AggregationConfig aggConfig = new AggregationConfig(aggBuilder); - PivotConfig pivotConfig = PivotConfig.builder().setGroups(groupConfig).setAggregationConfig(aggConfig).build(); - - TransformConfig transformConfig = TransformConfig.builder() - .setId("mega-transform") - .setSource(SourceConfig.builder().setIndex("source-data").setQueryConfig(queryConfig).build()) - .setDest(DestConfig.builder().setIndex("pivot-dest").build()) - .setPivotConfig(pivotConfig) - .build(); - - client.transform().putTransform(new PutTransformRequest(transformConfig), RequestOptions.DEFAULT); - transformsToClean.add(transformConfig.getId()); - - { - // tag::start-transform-request - StartTransformRequest request = - new StartTransformRequest("mega-transform"); // <1> - // end::start-transform-request - - // tag::start-transform-request-options - request.setTimeout(TimeValue.timeValueSeconds(20)); // <1> - // end::start-transform-request-options - - // tag::start-transform-execute - StartTransformResponse response = - client.transform().startTransform( - request, RequestOptions.DEFAULT); - // end::start-transform-execute - - assertTrue(response.isAcknowledged()); - } - { - // tag::stop-transform-request - StopTransformRequest request = - new StopTransformRequest("mega-transform"); // <1> - // end::stop-transform-request - - // tag::stop-transform-request-options - request.setWaitForCompletion(Boolean.TRUE); // <1> - request.setTimeout(TimeValue.timeValueSeconds(30)); // <2> - request.setAllowNoMatch(true); // <3> - // end::stop-transform-request-options - - // tag::stop-transform-execute - StopTransformResponse response = - client.transform().stopTransform( - request, RequestOptions.DEFAULT); - // end::stop-transform-execute - - assertTrue(response.isAcknowledged()); - } - { - // tag::start-transform-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse( - StartTransformResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-transform-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - StartTransformRequest request = new StartTransformRequest("mega-transform"); - // tag::start-transform-execute-async - client.transform().startTransformAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::start-transform-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - { - // tag::stop-transform-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse( - StopTransformResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::stop-transform-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - StopTransformRequest request = new StopTransformRequest("mega-transform"); - // tag::stop-transform-execute-async - client.transform().stopTransformAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::stop-transform-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeleteTransform() throws IOException, InterruptedException { - createIndex("source-data"); - - RestHighLevelClient client = highLevelClient(); - - GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); - AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); - aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars")); - AggregationConfig aggConfig = new AggregationConfig(aggBuilder); - PivotConfig pivotConfig = PivotConfig.builder().setGroups(groupConfig).setAggregationConfig(aggConfig).build(); - - TransformConfig transformConfig1 = TransformConfig.builder() - .setId("mega-transform") - .setSource(SourceConfig.builder().setIndex("source-data").setQuery(new MatchAllQueryBuilder()).build()) - .setDest(DestConfig.builder().setIndex("pivot-dest").build()) - .setPivotConfig(pivotConfig) - .build(); - TransformConfig transformConfig2 = TransformConfig.builder() - .setId("mega-transform2") - .setSource(SourceConfig.builder().setIndex("source-data").setQuery(new MatchAllQueryBuilder()).build()) - .setDest(DestConfig.builder().setIndex("pivot-dest2").build()) - .setPivotConfig(pivotConfig) - .build(); - - client.transform().putTransform(new PutTransformRequest(transformConfig1), RequestOptions.DEFAULT); - client.transform().putTransform(new PutTransformRequest(transformConfig2), RequestOptions.DEFAULT); - - { - // tag::delete-transform-request - DeleteTransformRequest request = - new DeleteTransformRequest("mega-transform"); // <1> - request.setForce(false); // <2> - // end::delete-transform-request - - // tag::delete-transform-execute - AcknowledgedResponse response = - client.transform() - .deleteTransform(request, RequestOptions.DEFAULT); - // end::delete-transform-execute - - assertTrue(response.isAcknowledged()); - } - { - // tag::delete-transform-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-transform-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - DeleteTransformRequest request = new DeleteTransformRequest("mega-transform2"); - - // tag::delete-transform-execute-async - client.transform().deleteTransformAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-transform-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPreview() throws IOException, InterruptedException { - createIndex("source-data"); - - RestHighLevelClient client = highLevelClient(); - - QueryConfig queryConfig = new QueryConfig(new MatchAllQueryBuilder()); - GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); - AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); - aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars")); - AggregationConfig aggConfig = new AggregationConfig(aggBuilder); - PivotConfig pivotConfig = PivotConfig.builder().setGroups(groupConfig).setAggregationConfig(aggConfig).build(); - - // tag::preview-transform-request - TransformConfig transformConfig = - TransformConfig.forPreview( - SourceConfig.builder() - .setIndex("source-data") - .setQueryConfig(queryConfig) - .build(), // <1> - pivotConfig); // <2> - - PreviewTransformRequest request = - new PreviewTransformRequest(transformConfig); // <3> - // end::preview-transform-request - - { - // tag::preview-transform-execute - PreviewTransformResponse response = - client.transform() - .previewTransform(request, RequestOptions.DEFAULT); - // end::preview-transform-execute - - assertNotNull(response.getDocs()); - assertNotNull(response.getMappings()); - } - { - // tag::preview-transform-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(PreviewTransformResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::preview-transform-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::preview-transform-execute-async - client.transform().previewTransformAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::preview-transform-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetStats() throws IOException, InterruptedException { - createIndex("source-data"); - - RestHighLevelClient client = highLevelClient(); - - GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); - AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); - aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars")); - AggregationConfig aggConfig = new AggregationConfig(aggBuilder); - PivotConfig pivotConfig = PivotConfig.builder().setGroups(groupConfig).setAggregationConfig(aggConfig).build(); - - String id = "statisitcal-transform"; - TransformConfig transformConfig = TransformConfig.builder() - .setId(id) - .setSource(SourceConfig.builder().setIndex("source-data").setQuery(new MatchAllQueryBuilder()).build()) - .setDest(DestConfig.builder().setIndex("pivot-dest").build()) - .setPivotConfig(pivotConfig) - .build(); - client.transform().putTransform(new PutTransformRequest(transformConfig), RequestOptions.DEFAULT); - transformsToClean.add(id); - - // tag::get-transform-stats-request - GetTransformStatsRequest request = - new GetTransformStatsRequest(id); // <1> - // end::get-transform-stats-request - - // tag::get-transform-stats-request-options - request.setPageParams(new PageParams(0, 100)); // <1> - request.setAllowNoMatch(true); // <2> - // end::get-transform-stats-request-options - - { - // tag::get-transform-stats-execute - GetTransformStatsResponse response = - client.transform() - .getTransformStats(request, RequestOptions.DEFAULT); - // end::get-transform-stats-execute - - assertThat(response.getTransformsStats(), hasSize(1)); - - // tag::get-transform-stats-response - TransformStats stats = - response.getTransformsStats().get(0); // <1> - TransformStats.State state = - stats.getState(); // <2> - TransformIndexerStats indexerStats = - stats.getIndexerStats(); // <3> - TransformProgress progress = - stats.getCheckpointingInfo() - .getNext().getCheckpointProgress(); // <4> - NodeAttributes node = - stats.getNode(); // <5> - // end::get-transform-stats-response - - assertEquals(TransformStats.State.STOPPED, state); - assertNotNull(indexerStats); - assertNull(progress); - } - { - // tag::get-transform-stats-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse( - GetTransformStatsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-transform-stats-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-transform-stats-execute-async - client.transform().getTransformStatsAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::get-transform-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetTransform() throws IOException, InterruptedException { - createIndex("source-data"); - - GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); - AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); - aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars")); - AggregationConfig aggConfig = new AggregationConfig(aggBuilder); - PivotConfig pivotConfig = PivotConfig.builder().setGroups(groupConfig).setAggregationConfig(aggConfig).build(); - - TransformConfig putTransformConfig = TransformConfig.builder() - .setId("mega-transform") - .setSource(SourceConfig.builder().setIndex("source-data").setQuery(new MatchAllQueryBuilder()).build()) - .setDest(DestConfig.builder().setIndex("pivot-dest").build()) - .setPivotConfig(pivotConfig) - .build(); - - RestHighLevelClient client = highLevelClient(); - client.transform().putTransform(new PutTransformRequest(putTransformConfig), RequestOptions.DEFAULT); - transformsToClean.add(putTransformConfig.getId()); - - { - // tag::get-transform-request - GetTransformRequest request = - new GetTransformRequest("mega-transform"); // <1> - // end::get-transform-request - - // tag::get-transform-request-options - request.setPageParams(new PageParams(0, 100)); // <1> - request.setAllowNoMatch(true); // <2> - request.setExcludeGenerated(false); // <3> - // end::get-transform-request-options - - // tag::get-transform-execute - GetTransformResponse response = - client.transform() - .getTransform(request, RequestOptions.DEFAULT); - // end::get-transform-execute - - // tag::get-transform-response - List transformConfigs = - response.getTransformConfigurations(); - // end::get-transform-response - - assertEquals(1, transformConfigs.size()); - } - { - // tag::get-transform-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(GetTransformResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-transform-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - GetTransformRequest request = new GetTransformRequest("mega-transform"); - - // tag::get-transform-execute-async - client.transform().getTransformAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::get-transform-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java deleted file mode 100644 index abf1628119b6..000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java +++ /dev/null @@ -1,611 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.documentation; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.watcher.AckWatchRequest; -import org.elasticsearch.client.watcher.AckWatchResponse; -import org.elasticsearch.client.watcher.ActionStatus; -import org.elasticsearch.client.watcher.ActionStatus.AckStatus; -import org.elasticsearch.client.watcher.ActivateWatchRequest; -import org.elasticsearch.client.watcher.ActivateWatchResponse; -import org.elasticsearch.client.watcher.DeactivateWatchRequest; -import org.elasticsearch.client.watcher.DeactivateWatchResponse; -import org.elasticsearch.client.watcher.DeleteWatchRequest; -import org.elasticsearch.client.watcher.DeleteWatchResponse; -import org.elasticsearch.client.watcher.ExecuteWatchRequest; -import org.elasticsearch.client.watcher.ExecuteWatchResponse; -import org.elasticsearch.client.watcher.GetWatchRequest; -import org.elasticsearch.client.watcher.GetWatchResponse; -import org.elasticsearch.client.watcher.PutWatchRequest; -import org.elasticsearch.client.watcher.PutWatchResponse; -import org.elasticsearch.client.watcher.StartWatchServiceRequest; -import org.elasticsearch.client.watcher.StopWatchServiceRequest; -import org.elasticsearch.client.watcher.WatchStatus; -import org.elasticsearch.client.watcher.WatcherStatsRequest; -import org.elasticsearch.client.watcher.WatcherStatsResponse; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.xcontent.ObjectPath; -import org.elasticsearch.xcontent.XContentType; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.is; - -@SuppressWarnings("removal") -public class WatcherDocumentationIT extends ESRestHighLevelClientTestCase { - - public void testStartStopWatchService() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - //tag::start-watch-service-request - StartWatchServiceRequest request = new StartWatchServiceRequest(); - //end::start-watch-service-request - - //tag::start-watch-service-execute - AcknowledgedResponse response = client.watcher().startWatchService(request, RequestOptions.DEFAULT); - //end::start-watch-service-execute - - //tag::start-watch-service-response - boolean isAcknowledged = response.isAcknowledged(); // <1> - //end::start-watch-service-response - } - - { - //tag::stop-watch-service-request - StopWatchServiceRequest request = new StopWatchServiceRequest(); - //end::stop-watch-service-request - - //tag::stop-watch-service-execute - AcknowledgedResponse response = client.watcher().stopWatchService(request, RequestOptions.DEFAULT); - //end::stop-watch-service-execute - - //tag::stop-watch-service-response - boolean isAcknowledged = response.isAcknowledged(); // <1> - //end::stop-watch-service-response - } - - { - StartWatchServiceRequest request = new StartWatchServiceRequest(); - - // tag::start-watch-service-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-watch-service-execute-listener - - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::start-watch-service-execute-async - client.watcher().startWatchServiceAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::start-watch-service-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - StopWatchServiceRequest request = new StopWatchServiceRequest(); - - // tag::stop-watch-service-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::stop-watch-service-execute-listener - - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::stop-watch-service-execute-async - client.watcher().stopWatchServiceAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::stop-watch-service-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testWatcher() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - //tag::x-pack-put-watch-execute - // you can also use the WatchSourceBuilder from org.elasticsearch.plugin:x-pack-core to create a watch programmatically - BytesReference watch = new BytesArray(""" - { - "trigger": { "schedule": { "interval": "10h" } }, - "input": { "simple": { "foo" : "bar" } }, - "actions": { "logme": { "logging": { "text": "{{ctx.payload}}" } } } - }"""); - PutWatchRequest request = new PutWatchRequest("my_watch_id", watch, XContentType.JSON); - request.setActive(false); // <1> - PutWatchResponse response = client.watcher().putWatch(request, RequestOptions.DEFAULT); - //end::x-pack-put-watch-execute - - //tag::x-pack-put-watch-response - String watchId = response.getId(); // <1> - boolean isCreated = response.isCreated(); // <2> - long version = response.getVersion(); // <3> - //end::x-pack-put-watch-response - } - - { - BytesReference watch = new BytesArray(""" - { - "trigger": { "schedule": { "interval": "10h" } }, - "input": { "simple": { "foo" : "bar" } }, - "actions": { "logme": { "logging": { "text": "{{ctx.payload}}" } } } - }"""); - PutWatchRequest request = new PutWatchRequest("my_other_watch_id", watch, XContentType.JSON); - // tag::x-pack-put-watch-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-put-watch-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-put-watch-execute-async - client.watcher().putWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-put-watch-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::x-pack-execute-watch-by-id - ExecuteWatchRequest request = ExecuteWatchRequest.byId("my_watch_id"); - request.setAlternativeInput("{ \"foo\" : \"bar\" }"); // <1> - request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); // <2> - request.setRecordExecution(true); // <3> - request.setIgnoreCondition(true); // <4> - request.setTriggerData("{\"triggered_time\":\"now\"}"); // <5> - request.setDebug(true); // <6> - ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT); - // end::x-pack-execute-watch-by-id - - // tag::x-pack-execute-watch-by-id-response - String id = response.getRecordId(); // <1> - Map watch = response.getRecordAsMap(); // <2> - String watch_id = ObjectPath.eval("watch_record.watch_id", watch); // <3> - // end::x-pack-execute-watch-by-id-response - } - - { - ExecuteWatchRequest request = ExecuteWatchRequest.byId("my_watch_id"); - // tag::x-pack-execute-watch-by-id-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ExecuteWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-execute-watch-by-id-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-execute-watch-by-id-execute-async - client.watcher().executeWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-execute-watch-by-id-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - //tag::get-watch-request - GetWatchRequest request = new GetWatchRequest("my_watch_id"); - //end::get-watch-request - - //tag::get-watch-execute - GetWatchResponse response = client.watcher().getWatch(request, RequestOptions.DEFAULT); - //end::get-watch-execute - - //tag::get-watch-response - String watchId = response.getId(); // <1> - boolean found = response.isFound(); // <2> - long version = response.getVersion(); // <3> - WatchStatus status = response.getStatus(); // <4> - BytesReference source = response.getSource(); // <5> - //end::get-watch-response - } - - { - GetWatchRequest request = new GetWatchRequest("my_other_watch_id"); - // tag::get-watch-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-watch-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-watch-execute-async - client.watcher().getWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::get-watch-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - //tag::x-pack-delete-watch-execute - DeleteWatchRequest request = new DeleteWatchRequest("my_watch_id"); - DeleteWatchResponse response = client.watcher().deleteWatch(request, RequestOptions.DEFAULT); - //end::x-pack-delete-watch-execute - - //tag::x-pack-delete-watch-response - String watchId = response.getId(); // <1> - boolean found = response.isFound(); // <2> - long version = response.getVersion(); // <3> - //end::x-pack-delete-watch-response - } - - { - DeleteWatchRequest request = new DeleteWatchRequest("my_other_watch_id"); - // tag::x-pack-delete-watch-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(DeleteWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-delete-watch-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-delete-watch-execute-async - client.watcher().deleteWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-delete-watch-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testExecuteInlineWatch() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::x-pack-execute-watch-inline - String watchJson = """ - { - "trigger": { "schedule": { "interval": "10h" } }, - "input": { "none": {} }, - "actions": { "logme": { "logging": { "text": "{{ctx.payload}}" } } } - }"""; - ExecuteWatchRequest request = ExecuteWatchRequest.inline(watchJson); - request.setAlternativeInput("{ \"foo\" : \"bar\" }"); // <1> - request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); // <2> - request.setIgnoreCondition(true); // <3> - request.setTriggerData("{\"triggered_time\":\"now\"}"); // <4> - request.setDebug(true); // <5> - ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT); - // end::x-pack-execute-watch-inline - - // tag::x-pack-execute-watch-inline-response - String id = response.getRecordId(); // <1> - Map watch = response.getRecordAsMap(); // <2> - String watch_id = ObjectPath.eval("watch_record.watch_id", watch); // <3> - // end::x-pack-execute-watch-inline-response - } - - { - String watchJson = """ - { - "trigger": { "schedule": { "interval": "10h" } }, - "input": { "none": {} }, - "actions": { "logme": { "logging": { "text": "{{ctx.payload}}" } } } - }"""; - ExecuteWatchRequest request = ExecuteWatchRequest.inline(watchJson); - // tag::x-pack-execute-watch-inline-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ExecuteWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::x-pack-execute-watch-inline-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::x-pack-execute-watch-inline-execute-async - client.watcher().executeWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-execute-watch-inline-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testAckWatch() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - BytesReference watch = new BytesArray(""" - { - "trigger": { "schedule": { "interval": "10h" } }, - "input": { "simple": { "foo" : "bar" } }, - "actions": { "logme": { "logging": { "text": "{{ctx.payload}}" } } } - }"""); - PutWatchRequest putWatchRequest = new PutWatchRequest("my_watch_id", watch, XContentType.JSON); - client.watcher().putWatch(putWatchRequest, RequestOptions.DEFAULT); - - // TODO: use the high-level REST client here once it supports 'execute watch'. - Request executeWatchRequest = new Request("POST", "_watcher/watch/my_watch_id/_execute"); - executeWatchRequest.setJsonEntity("{ \"record_execution\": true }"); - Response executeResponse = client().performRequest(executeWatchRequest); - assertEquals(RestStatus.OK.getStatus(), executeResponse.getStatusLine().getStatusCode()); - } - - { - //tag::ack-watch-request - AckWatchRequest request = new AckWatchRequest("my_watch_id", // <1> - "logme", "emailme"); // <2> - //end::ack-watch-request - - //tag::ack-watch-execute - AckWatchResponse response = client.watcher().ackWatch(request, RequestOptions.DEFAULT); - //end::ack-watch-execute - - //tag::ack-watch-response - WatchStatus watchStatus = response.getStatus(); - ActionStatus actionStatus = watchStatus.actionStatus("logme"); // <1> - AckStatus.State ackState = actionStatus.ackStatus().state(); // <2> - //end::ack-watch-response - - assertEquals(AckStatus.State.ACKED, ackState); - } - - { - AckWatchRequest request = new AckWatchRequest("my_watch_id"); - // tag::ack-watch-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AckWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::ack-watch-execute-listener - - // For testing, replace the empty listener by a blocking listener. - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::ack-watch-execute-async - client.watcher().ackWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::ack-watch-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testDeactivateWatch() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - BytesReference watch = new BytesArray(""" - { - "trigger": { "schedule": { "interval": "10h" } }, - "input": { "simple": { "foo" : "bar" } }, - "actions": { "logme": { "logging": { "text": "{{ctx.payload}}" } } } - }"""); - PutWatchRequest putWatchRequest = new PutWatchRequest("my_watch_id", watch, XContentType.JSON); - client.watcher().putWatch(putWatchRequest, RequestOptions.DEFAULT); - } - - { - //tag::deactivate-watch-execute - DeactivateWatchRequest request = new DeactivateWatchRequest("my_watch_id"); - DeactivateWatchResponse response = client.watcher().deactivateWatch(request, RequestOptions.DEFAULT); - //end::deactivate-watch-execute - - assertThat(response.getStatus().state().isActive(), is(false)); - } - - { - DeactivateWatchRequest request = new DeactivateWatchRequest("my_watch_id"); - // tag::deactivate-watch-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(DeactivateWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::deactivate-watch-execute-listener - - // For testing, replace the empty listener by a blocking listener. - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::deactivate-watch-execute-async - client.watcher().deactivateWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::deactivate-watch-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testActivateWatch() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - BytesReference watch = new BytesArray(""" - { - "trigger": { "schedule": { "interval": "10h" } }, - "input": { "simple": { "foo" : "bar" } }, - "actions": { "logme": { "logging": { "text": "{{ctx.payload}}" } } } - }"""); - PutWatchRequest request = new PutWatchRequest("my_watch_id", watch, XContentType.JSON); - request.setActive(false); // <1> - PutWatchResponse response = client.watcher().putWatch(request, RequestOptions.DEFAULT); - } - - { - //tag::activate-watch-request - ActivateWatchRequest request = new ActivateWatchRequest("my_watch_id"); - ActivateWatchResponse response = client.watcher().activateWatch(request, RequestOptions.DEFAULT); - //end::activate-watch-request - - //tag::activate-watch-response - WatchStatus watchStatus = response.getStatus(); // <1> - //end::activate-watch-response - - assertTrue(watchStatus.state().isActive()); - } - - { - ActivateWatchRequest request = new ActivateWatchRequest("my_watch_id"); - //tag::activate-watch-request-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(ActivateWatchResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - //end::activate-watch-request-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - //tag::activate-watch-request-async - client.watcher().activateWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> - //end::activate-watch-request-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - - } - } - - public void testWatcherStats() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - //tag::watcher-stats-request - WatcherStatsRequest request = new WatcherStatsRequest(true, true); - //end::watcher-stats-request - - //tag::watcher-stats-execute - WatcherStatsResponse response = client.watcher().watcherStats(request, RequestOptions.DEFAULT); - //end::watcher-stats-execute - - //tag::watcher-stats-response - List nodes = response.getNodes(); // <1> - //end::watcher-stats-response - } - - { - WatcherStatsRequest request = new WatcherStatsRequest(); - - // tag::watcher-stats-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(WatcherStatsResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::watcher-stats-execute-listener - - CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::watcher-stats-execute-async - client.watcher().watcherStatsAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::watcher-stats-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - -} diff --git a/docs/Versions.asciidoc b/docs/Versions.asciidoc index 6f204267ab20..57b24904d015 100644 --- a/docs/Versions.asciidoc +++ b/docs/Versions.asciidoc @@ -21,10 +21,8 @@ Javadoc roots used to generate links from Painless's API reference ifeval::["{release-state}"=="unreleased"] :elasticsearch-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/elasticsearch/{version}-SNAPSHOT -:transport-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/client/transport/{version}-SNAPSHOT :rest-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/{version}-SNAPSHOT :rest-client-sniffer-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client-sniffer/{version}-SNAPSHOT -:rest-high-level-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-high-level-client/{version}-SNAPSHOT :mapper-extras-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/plugin/mapper-extras-client/{version}-SNAPSHOT :painless-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/painless/lang-painless/{version}-SNAPSHOT :parent-join-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/plugin/parent-join-client/{version}-SNAPSHOT @@ -36,10 +34,8 @@ endif::[] ifeval::["{release-state}"!="unreleased"] :elasticsearch-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/{version} -:transport-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/client/transport/{version} :rest-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/{version} :rest-client-sniffer-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client-sniffer/{version} -:rest-high-level-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-high-level-client/{version} :mapper-extras-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/plugin/mapper-extras-client/{version} :painless-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/painless/lang-painless/{version} :parent-join-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/plugin/parent-join-client/{version} @@ -49,8 +45,6 @@ ifeval::["{release-state}"!="unreleased"] :version_qualified: {bare_version} endif::[] -:javadoc-client: {rest-high-level-client-javadoc}/org/elasticsearch/client -:javadoc-xpack: {rest-high-level-client-javadoc}/org/elasticsearch/protocol/xpack :javadoc-license: {rest-high-level-client-javadoc}/org/elasticsearch/protocol/xpack/license :javadoc-watcher: {rest-high-level-client-javadoc}/org/elasticsearch/protocol/xpack/watcher diff --git a/docs/java-rest/high-level/aggs-builders.asciidoc b/docs/java-rest/high-level/aggs-builders.asciidoc deleted file mode 100644 index 718ac5056298..000000000000 --- a/docs/java-rest/high-level/aggs-builders.asciidoc +++ /dev/null @@ -1,84 +0,0 @@ -[[java-rest-high-aggregation-builders]] -=== Building Aggregations - -This page lists all the available aggregations with their corresponding `AggregationBuilder` class name and helper method name in the -`AggregationBuilders` or `PipelineAggregatorBuilders` utility classes. - -:agg-ref: {elasticsearch-javadoc}/org/elasticsearch/search/aggregations -:parentjoin-ref: {parent-join-client-javadoc}/org/elasticsearch/join/aggregations -:matrixstats-ref: {matrixstats-client-javadoc}/org/elasticsearch/search/aggregations - -==== Metrics Aggregations -[options="header"] -|====== -| Aggregation | AggregationBuilder Class | Method in AggregationBuilders -| {ref}/search-aggregations-metrics-avg-aggregation.html[Avg] | {agg-ref}/metrics/AvgAggregationBuilder.html[AvgAggregationBuilder] | {agg-ref}/AggregationBuilders.html#avg-java.lang.String-[AggregationBuilders.avg()] -| {ref}/search-aggregations-metrics-cardinality-aggregation.html[Cardinality] | {agg-ref}/metrics/CardinalityAggregationBuilder.html[CardinalityAggregationBuilder] | {agg-ref}/AggregationBuilders.html#cardinality-java.lang.String-[AggregationBuilders.cardinality()] -| {ref}/search-aggregations-metrics-extendedstats-aggregation.html[Extended Stats] | {agg-ref}/metrics/ExtendedStatsAggregationBuilder.html[ExtendedStatsAggregationBuilder] | {agg-ref}/AggregationBuilders.html#extendedStats-java.lang.String-[AggregationBuilders.extendedStats()] -| {ref}/search-aggregations-metrics-geobounds-aggregation.html[Geo Bounds] | {agg-ref}/metrics/GeoBoundsAggregationBuilder.html[GeoBoundsAggregationBuilder] | {agg-ref}/AggregationBuilders.html#geoBounds-java.lang.String-[AggregationBuilders.geoBounds()] -| {ref}/search-aggregations-metrics-geocentroid-aggregation.html[Geo Centroid] | {agg-ref}/metrics/GeoCentroidAggregationBuilder.html[GeoCentroidAggregationBuilder] | {agg-ref}/AggregationBuilders.html#geoCentroid-java.lang.String-[AggregationBuilders.geoCentroid()] -| {ref}/search-aggregations-metrics-max-aggregation.html[Max] | {agg-ref}/metrics/MaxAggregationBuilder.html[MaxAggregationBuilder] | {agg-ref}/AggregationBuilders.html#max-java.lang.String-[AggregationBuilders.max()] -| {ref}/search-aggregations-metrics-min-aggregation.html[Min] | {agg-ref}/metrics/MinAggregationBuilder.html[MinAggregationBuilder] | {agg-ref}/AggregationBuilders.html#min-java.lang.String-[AggregationBuilders.min()] -| {ref}/search-aggregations-metrics-percentile-aggregation.html[Percentiles] | {agg-ref}/metrics/PercentilesAggregationBuilder.html[PercentilesAggregationBuilder] | {agg-ref}/AggregationBuilders.html#percentiles-java.lang.String-[AggregationBuilders.percentiles()] -| {ref}/search-aggregations-metrics-percentile-rank-aggregation.html[Percentile Ranks] | {agg-ref}/metrics/PercentileRanksAggregationBuilder.html[PercentileRanksAggregationBuilder] | {agg-ref}/AggregationBuilders.html#percentileRanks-java.lang.String-[AggregationBuilders.percentileRanks()] -| {ref}/search-aggregations-metrics-scripted-metric-aggregation.html[Scripted Metric] | {agg-ref}/metrics/ScriptedMetricAggregationBuilder.html[ScriptedMetricAggregationBuilder] | {agg-ref}/AggregationBuilders.html#scriptedMetric-java.lang.String-[AggregationBuilders.scriptedMetric()] -| {ref}/search-aggregations-metrics-stats-aggregation.html[Stats] | {agg-ref}/metrics/StatsAggregationBuilder.html[StatsAggregationBuilder] | {agg-ref}/AggregationBuilders.html#stats-java.lang.String-[AggregationBuilders.stats()] -| {ref}/search-aggregations-metrics-sum-aggregation.html[Sum] | {agg-ref}/metrics/SumAggregationBuilder.html[SumAggregationBuilder] | {agg-ref}/AggregationBuilders.html#sum-java.lang.String-[AggregationBuilders.sum()] -| {ref}/search-aggregations-metrics-top-hits-aggregation.html[Top hits] | {agg-ref}/metrics/TopHitsAggregationBuilder.html[TopHitsAggregationBuilder] | {agg-ref}/AggregationBuilders.html#topHits-java.lang.String-[AggregationBuilders.topHits()] -| {ref}/search-aggregations-metrics-top-metrics.html[Top Metrics] | {javadoc-client}/analytics/TopMetricsAggregationBuilder.html[TopMetricsAggregationBuilder] | None -| {ref}/search-aggregations-metrics-valuecount-aggregation.html[Value Count] | {agg-ref}/metrics/ValueCountAggregationBuilder.html[ValueCountAggregationBuilder] | {agg-ref}/AggregationBuilders.html#count-java.lang.String-[AggregationBuilders.count()] -| {ref}/search-aggregations-metrics-string-stats-aggregation.html[String Stats] | {javadoc-client}/analytics/StringStatsAggregationBuilder.html[StringStatsAggregationBuilder] | None -|====== - -==== Bucket Aggregations -[options="header"] -|====== -| Aggregation | AggregationBuilder Class | Method in AggregationBuilders -| {ref}/search-aggregations-bucket-adjacency-matrix-aggregation.html[Adjacency Matrix] | {agg-ref}/bucket/adjacency/AdjacencyMatrixAggregationBuilder.html[AdjacencyMatrixAggregationBuilder] | {agg-ref}/AggregationBuilders.html#adjacencyMatrix-java.lang.String-java.util.Map-[AggregationBuilders.adjacencyMatrix()] -| {ref}/search-aggregations-bucket-children-aggregation.html[Children] | {parentjoin-ref}/ChildrenAggregationBuilder.html[ChildrenAggregationBuilder] | -| {ref}/search-aggregations-bucket-datehistogram-aggregation.html[Date Histogram] | {agg-ref}/bucket/histogram/DateHistogramAggregationBuilder.html[DateHistogramAggregationBuilder] | {agg-ref}/AggregationBuilders.html#dateHistogram-java.lang.String-[AggregationBuilders.dateHistogram()] -| {ref}/search-aggregations-bucket-daterange-aggregation.html[Date Range] | {agg-ref}/bucket/range/DateRangeAggregationBuilder.html[DateRangeAggregationBuilder] | {agg-ref}/AggregationBuilders.html#dateRange-java.lang.String-[AggregationBuilders.dateRange()] -| {ref}/search-aggregations-bucket-diversified-sampler-aggregation.html[Diversified Sampler] | {agg-ref}/bucket/sampler/DiversifiedAggregationBuilder.html[DiversifiedAggregationBuilder] | {agg-ref}/AggregationBuilders.html#diversifiedSampler-java.lang.String-[AggregationBuilders.diversifiedSampler()] -| {ref}/search-aggregations-bucket-filter-aggregation.html[Filter] | {agg-ref}/bucket/filter/FilterAggregationBuilder.html[FilterAggregationBuilder] | {agg-ref}/AggregationBuilders.html#filter-java.lang.String-org.elasticsearch.index.query.QueryBuilder-[AggregationBuilders.filter()] -| {ref}/search-aggregations-bucket-filters-aggregation.html[Filters] | {agg-ref}/bucket/filters/FiltersAggregationBuilder.html[FiltersAggregationBuilder] | {agg-ref}/AggregationBuilders.html#filters-java.lang.String-org.elasticsearch.index.query.QueryBuilder...-[AggregationBuilders.filters()] -| {ref}/search-aggregations-bucket-geodistance-aggregation.html[Geo Distance] | {agg-ref}/bucket/range/GeoDistanceAggregationBuilder.html[GeoDistanceAggregationBuilder] | {agg-ref}/AggregationBuilders.html#geoDistance-java.lang.String-org.elasticsearch.common.geo.GeoPoint-[AggregationBuilders.geoDistance()] -| {ref}/search-aggregations-bucket-geohashgrid-aggregation.html[GeoHash Grid] | {agg-ref}/bucket/geogrid/GeoGridAggregationBuilder.html[GeoGridAggregationBuilder] | {agg-ref}/AggregationBuilders.html#geohashGrid-java.lang.String-[AggregationBuilders.geohashGrid()] -| {ref}/search-aggregations-bucket-global-aggregation.html[Global] | {agg-ref}/bucket/global/GlobalAggregationBuilder.html[GlobalAggregationBuilder] | {agg-ref}/AggregationBuilders.html#global-java.lang.String-[AggregationBuilders.global()] -| {ref}/search-aggregations-bucket-histogram-aggregation.html[Histogram] | {agg-ref}/bucket/histogram/HistogramAggregationBuilder.html[HistogramAggregationBuilder] | {agg-ref}/AggregationBuilders.html#histogram-java.lang.String-[AggregationBuilders.histogram()] -| {ref}/search-aggregations-bucket-iprange-aggregation.html[IP Range] | {agg-ref}/bucket/range/IpRangeAggregationBuilder.html[IpRangeAggregationBuilder] | {agg-ref}/AggregationBuilders.html#ipRange-java.lang.String-[AggregationBuilders.ipRange()] -| {ref}/search-aggregations-bucket-missing-aggregation.html[Missing] | {agg-ref}/bucket/missing/MissingAggregationBuilder.html[MissingAggregationBuilder] | {agg-ref}/AggregationBuilders.html#missing-java.lang.String-[AggregationBuilders.missing()] -| {ref}/search-aggregations-bucket-nested-aggregation.html[Nested] | {agg-ref}/bucket/nested/NestedAggregationBuilder.html[NestedAggregationBuilder] | {agg-ref}/AggregationBuilders.html#nested-java.lang.String-java.lang.String-[AggregationBuilders.nested()] -| {ref}/search-aggregations-bucket-range-aggregation.html[Range] | {agg-ref}/bucket/range/RangeAggregationBuilder.html[RangeAggregationBuilder] | {agg-ref}/AggregationBuilders.html#range-java.lang.String-[AggregationBuilders.range()] -| {ref}/search-aggregations-bucket-reverse-nested-aggregation.html[Reverse nested] | {agg-ref}/bucket/nested/ReverseNestedAggregationBuilder.html[ReverseNestedAggregationBuilder] | {agg-ref}/AggregationBuilders.html#reverseNested-java.lang.String-[AggregationBuilders.reverseNested()] -| {ref}/search-aggregations-bucket-sampler-aggregation.html[Sampler] | {agg-ref}/bucket/sampler/SamplerAggregationBuilder.html[SamplerAggregationBuilder] | {agg-ref}/AggregationBuilders.html#sampler-java.lang.String-[AggregationBuilders.sampler()] -| {ref}/search-aggregations-bucket-significantterms-aggregation.html[Significant Terms] | {agg-ref}/bucket/significant/SignificantTermsAggregationBuilder.html[SignificantTermsAggregationBuilder] | {agg-ref}/AggregationBuilders.html#significantTerms-java.lang.String-[AggregationBuilders.significantTerms()] -| {ref}/search-aggregations-bucket-significanttext-aggregation.html[Significant Text] | {agg-ref}/bucket/significant/SignificantTextAggregationBuilder.html[SignificantTextAggregationBuilder] | {agg-ref}/AggregationBuilders.html#significantText-java.lang.String-java.lang.String-[AggregationBuilders.significantText()] -| {ref}/search-aggregations-bucket-terms-aggregation.html[Terms] | {agg-ref}/bucket/terms/TermsAggregationBuilder.html[TermsAggregationBuilder] | {agg-ref}/AggregationBuilders.html#terms-java.lang.String-[AggregationBuilders.terms()] -|====== - -==== Pipeline Aggregations -[options="header"] -|====== -| Pipeline on | PipelineAggregationBuilder Class | Method in PipelineAggregatorBuilders -| {ref}/search-aggregations-pipeline-avg-bucket-aggregation.html[Avg Bucket] | {agg-ref}/pipeline/AvgBucketPipelineAggregationBuilder.html[AvgBucketPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#avgBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.avgBucket()] -| {ref}/search-aggregations-pipeline-derivative-aggregation.html[Derivative] | {agg-ref}/pipeline/DerivativePipelineAggregationBuilder.html[DerivativePipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#derivative-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.derivative()] -| {ref}/search-aggregations-pipeline-inference-bucket-aggregation.html[Inference] | {javadoc-client}/analytics/InferencePipelineAggregationBuilder.html[InferencePipelineAggregationBuilder] | None -| {ref}/search-aggregations-pipeline-max-bucket-aggregation.html[Max Bucket] | {agg-ref}/pipeline/MaxBucketPipelineAggregationBuilder.html[MaxBucketPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#maxBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.maxBucket()] -| {ref}/search-aggregations-pipeline-min-bucket-aggregation.html[Min Bucket] | {agg-ref}/pipeline/MinBucketPipelineAggregationBuilder.html[MinBucketPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#minBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.minBucket()] -| {ref}/search-aggregations-pipeline-sum-bucket-aggregation.html[Sum Bucket] | {agg-ref}/pipeline/SumBucketPipelineAggregationBuilder.html[SumBucketPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#sumBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.sumBucket()] -| {ref}/search-aggregations-pipeline-stats-bucket-aggregation.html[Stats Bucket] | {agg-ref}/pipeline/StatsBucketPipelineAggregationBuilder.html[StatsBucketPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#statsBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.statsBucket()] -| {ref}/search-aggregations-pipeline-extended-stats-bucket-aggregation.html[Extended Stats Bucket] | {agg-ref}/pipeline/ExtendedStatsBucketPipelineAggregationBuilder.html[ExtendedStatsBucketPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#extendedStatsBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.extendedStatsBucket()] -| {ref}/search-aggregations-pipeline-percentiles-bucket-aggregation.html[Percentiles Bucket] | {agg-ref}/pipeline/PercentilesBucketPipelineAggregationBuilder.html[PercentilesBucketPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#percentilesBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.percentilesBucket()] -| {ref}/search-aggregations-pipeline-movfn-aggregation.html[Moving Function] | {agg-ref}/pipeline/MovFnPipelineAggregationBuilder.html[MovFnPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#movingFunction-java.lang.String-org.elasticsearch.script.Script-java.lang.String-int-[PipelineAggregatorBuilders.movingFunction()] -| {ref}/search-aggregations-pipeline-cumulative-sum-aggregation.html[Cumulative Sum] | {agg-ref}/pipeline/CumulativeSumPipelineAggregationBuilder.html[CumulativeSumPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#cumulativeSum-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.cumulativeSum()] -| {ref}/search-aggregations-pipeline-bucket-script-aggregation.html[Bucket Script] | {agg-ref}/pipeline/BucketScriptPipelineAggregationBuilder.html[BucketScriptPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#bucketScript-java.lang.String-java.util.Map-org.elasticsearch.script.Script-[PipelineAggregatorBuilders.bucketScript()] -| {ref}/search-aggregations-pipeline-bucket-selector-aggregation.html[Bucket Selector] | {agg-ref}/pipeline/BucketSelectorPipelineAggregationBuilder.html[BucketSelectorPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#bucketSelector-java.lang.String-java.util.Map-org.elasticsearch.script.Script-[PipelineAggregatorBuilders.bucketSelector()] -| {ref}/search-aggregations-pipeline-serialdiff-aggregation.html[Serial Differencing] | {agg-ref}/pipeline/SerialDiffPipelineAggregationBuilder.html[SerialDiffPipelineAggregationBuilder] | {agg-ref}/PipelineAggregatorBuilders.html#diff-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.diff()] -|====== - -==== Matrix Aggregations -[options="header"] -|====== -| Aggregation | AggregationBuilder Class | Method in MatrixStatsAggregationBuilders -| {ref}/search-aggregations-matrix-stats-aggregation.html[Matrix Stats] | {matrixstats-ref}/matrix/stats/MatrixStatsAggregationBuilder.html[MatrixStatsAggregationBuilder] | {matrixstats-ref}/MatrixStatsAggregationBuilders.html#matrixStats-java.lang.String-[MatrixStatsAggregationBuilders.matrixStats()] -|====== diff --git a/docs/java-rest/high-level/asyncsearch/delete.asciidoc b/docs/java-rest/high-level/asyncsearch/delete.asciidoc deleted file mode 100644 index f38961fe28c0..000000000000 --- a/docs/java-rest/high-level/asyncsearch/delete.asciidoc +++ /dev/null @@ -1,68 +0,0 @@ --- -:api: asyncsearch-delete -:request: DeleteAsyncSearchRequest -:response: AcknowledgedResponse --- - -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Async Search API - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ allows deleting a running asynchronous search task using -its id. Required arguments are the `id` of a running search: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-sync"] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute] --------------------------------------------------- -<1> Execute the request and get back the response as an +{response}+ object. - -[id="{upid}-{api}-async"] -==== Asynchronous Execution - -The asynchronous execution of a +{request}+ allows to use an -`ActionListener` to be called back when the submit request returns: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] --------------------------------------------------- -<1> The +{request}+ 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 +{response}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-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 - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates the acknowledgement of the request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isAcknowledged` was the deletion request acknowledged or not. \ No newline at end of file diff --git a/docs/java-rest/high-level/asyncsearch/get.asciidoc b/docs/java-rest/high-level/asyncsearch/get.asciidoc deleted file mode 100644 index 531c341d64b4..000000000000 --- a/docs/java-rest/high-level/asyncsearch/get.asciidoc +++ /dev/null @@ -1,87 +0,0 @@ --- -:api: asyncsearch-get -:request: GetAsyncSearchRequest -:response: AsyncSearchResponse --- - -[role="xpack"] -[id="{upid}-{api}"] -=== Get Async Search API - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ allows to get a running asynchronous search task by -its id. Required arguments are the `id` of a running async search: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-arguments] --------------------------------------------------- -<1> The minimum time that the request should wait before -returning a partial result (defaults to no wait). -<2> The expiration time of the request (defaults to none). - - -[id="{upid}-{api}-sync"] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute] --------------------------------------------------- -<1> Execute the request and get back the response as an +{response}+ object. - -[id="{upid}-{api}-async"] -==== Asynchronous Execution - -The asynchronous execution of a +{request}+ allows to use an -`ActionListener` to be called back when the submit request returns: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] --------------------------------------------------- -<1> The +{request}+ 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 +{response}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-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 - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The `SearchResponse`, or `null` if not available yet -<2> The id of the async search request, `null` if the response isn't stored -<3> `true` when the response contains partial results -<4> `true` when the search is still running -<5> The time the response was created (millis since epoch) -<6> The time the response expires (millis since epoch) -<7> Get failure reasons or `null` for no failures diff --git a/docs/java-rest/high-level/asyncsearch/submit.asciidoc b/docs/java-rest/high-level/asyncsearch/submit.asciidoc deleted file mode 100644 index cfe78f1d1215..000000000000 --- a/docs/java-rest/high-level/asyncsearch/submit.asciidoc +++ /dev/null @@ -1,94 +0,0 @@ --- -:api: asyncsearch-submit -:request: SubmitAsyncSearchRequest -:response: AsyncSearchResponse --- - -[role="xpack"] -[id="{upid}-{api}"] -=== Submit Async Search API - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ allows to submit an asynchronous search task to -the cluster. Required arguments are the `SearchSourceBuilder` defining -the search and the target indices: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The definition of the search to run -<2> The target indices for the search - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-arguments] --------------------------------------------------- -<1> The minimum time that the request should wait before -returning a partial result (defaults to 1 second). -<2> The expiration time of the request (defaults to 5 days). -<3> Controls whether the results should be stored if the request -completed within the provided `wait_for_completion` time (default: false) - -[id="{upid}-{api}-sync"] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute] --------------------------------------------------- -<1> Execute the request and get back the response as an +{response}+ object. - -[id="{upid}-{api}-async"] -==== Asynchronous Execution - -The asynchronous execution of a +{request}+ allows to use an -`ActionListener` to be called back when the submit request returns. Note -that this is does not concern the execution of the submitted search request, -which always executes asynchronously. The listener, however, waits for the -submit request itself to come back: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] --------------------------------------------------- -<1> The +{request}+ 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 +{response}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-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 - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The `SearchResponse`, or `null` if not available yet -<2> The id of the async search request, `null` if the response isn't stored -<3> `true` when the response contains partial results -<4> `true` when the search is still running -<5> The time the response was created (millis since epoch) -<6> The time the response expires (millis since epoch) -<7> Get failure reasons or `null` for no failures diff --git a/docs/java-rest/high-level/ccr/delete_auto_follow_pattern.asciidoc b/docs/java-rest/high-level/ccr/delete_auto_follow_pattern.asciidoc deleted file mode 100644 index 49aee815b89b..000000000000 --- a/docs/java-rest/high-level/ccr/delete_auto_follow_pattern.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ --- -:api: ccr-delete-auto-follow-pattern -:request: DeleteAutoFollowPatternRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Auto Follow Pattern API - -[id="{upid}-{api}-request"] -==== Request - -The Delete Auto Follow Pattern API allows you to delete an auto follow pattern. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the auto follow pattern to delete. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete auto follow pattern request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the delete auto follow pattern request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ccr/forget_follower.asciidoc b/docs/java-rest/high-level/ccr/forget_follower.asciidoc deleted file mode 100644 index b889993a4e9b..000000000000 --- a/docs/java-rest/high-level/ccr/forget_follower.asciidoc +++ /dev/null @@ -1,45 +0,0 @@ --- -:api: ccr-forget-follower -:request: ForgetFollowerRequest -:response: BroadcastResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Forget Follower API - -[id="{upid}-{api}-request"] -==== Request - -The Forget Follower API allows you to manually remove the follower retention -leases from the leader. Note that these retention leases are automatically -managed by the following index. This API exists only for cases when invoking -the unfollow API on the follower index is unable to remove the follower -retention leases. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the cluster containing the follower index. -<2> The name of the follower index. -<3> The UUID of the follower index (can be obtained from index stats). -<4> The alias of the remote cluster containing the leader index. -<5> The name of the leader index. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the response was successful. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The high-level shards summary. -<2> The total number of shards the request was executed on. -<3> The total number of shards the request was successful on. -<4> The total number of shards the request was skipped on (should always be zero). -<5> The total number of shards the request failed on. -<6> The shard-level failures. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ccr/get_auto_follow_pattern.asciidoc b/docs/java-rest/high-level/ccr/get_auto_follow_pattern.asciidoc deleted file mode 100644 index 98c9e5410193..000000000000 --- a/docs/java-rest/high-level/ccr/get_auto_follow_pattern.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: ccr-get-auto-follow-pattern -:request: GetAutoFollowPatternRequest -:response: GetAutoFollowPatternResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Auto Follow Pattern API - -[id="{upid}-{api}-request"] -==== Request - -The Get Auto Follow Pattern API allows you to get a specified auto follow pattern -or all auto follow patterns. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the auto follow pattern to get. - Use the default constructor to get all auto follow patterns. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ includes the requested auto follow pattern or -all auto follow patterns if default constructor or request class was used. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Get the requested pattern from the list of returned patterns - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ccr/get_follow_info.asciidoc b/docs/java-rest/high-level/ccr/get_follow_info.asciidoc deleted file mode 100644 index 70a71c1c90b7..000000000000 --- a/docs/java-rest/high-level/ccr/get_follow_info.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: ccr-get-follow-info -:request: FollowInfoRequest -:response: FollowInfoResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Follow Info API - - -[id="{upid}-{api}-request"] -==== Request - -The Get Follow Info API allows you to get follow information (parameters and status) for specific follower indices. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The follower index to get follow information for. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ includes follow information for the specified follower indices - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The follow information for specified follower indices. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ccr/get_follow_stats.asciidoc b/docs/java-rest/high-level/ccr/get_follow_stats.asciidoc deleted file mode 100644 index a510a53b70cc..000000000000 --- a/docs/java-rest/high-level/ccr/get_follow_stats.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: ccr-get-follow-stats -:request: FollowStatsRequest -:response: FollowStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Follow Stats API - - -[id="{upid}-{api}-request"] -==== Request - -The Get Follow Stats API allows you to get follow statistics for specific follower indices. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The follower index to get follow statistics for. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ includes follow statistics for the specified follower indices - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The follow stats for specified follower indices. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ccr/get_stats.asciidoc b/docs/java-rest/high-level/ccr/get_stats.asciidoc deleted file mode 100644 index 6c8502302fcc..000000000000 --- a/docs/java-rest/high-level/ccr/get_stats.asciidoc +++ /dev/null @@ -1,37 +0,0 @@ --- -:api: ccr-get-stats -:request: CcrStatsRequest -:response: CcrStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get CCR Stats API - - -[id="{upid}-{api}-request"] -==== Request - -The Get CCR Stats API allows you to get statistics about index following and auto following. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The request accepts no parameters. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ always includes index follow statistics of all follow indices and -auto follow statistics. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The follow stats of active follower indices. -<2> The auto follow stats of the cluster that has been queried. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ccr/pause_auto_follow_pattern.asciidoc b/docs/java-rest/high-level/ccr/pause_auto_follow_pattern.asciidoc deleted file mode 100644 index 2d40e4e9c4ae..000000000000 --- a/docs/java-rest/high-level/ccr/pause_auto_follow_pattern.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ --- -:api: ccr-pause-auto-follow-pattern -:request: PauseAutoFollowPatternRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Pause Auto Follow Pattern API - -[id="{upid}-{api}-request"] -==== Request - -The Pause Auto Follow Pattern API allows you to pause an existing auto follow pattern. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the auto follow pattern. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the pause auto follow pattern request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the pause auto follow pattern request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ccr/pause_follow.asciidoc b/docs/java-rest/high-level/ccr/pause_follow.asciidoc deleted file mode 100644 index 70694da0e815..000000000000 --- a/docs/java-rest/high-level/ccr/pause_follow.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: ccr-pause-follow -:request: PauseFollowRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Pause Follow API - - -[id="{upid}-{api}-request"] -==== Request - -The Pause Follow API allows you to pause following by follow index name. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of follow index. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the pause follow request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the pause follow was acknowledge. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ccr/put_auto_follow_pattern.asciidoc b/docs/java-rest/high-level/ccr/put_auto_follow_pattern.asciidoc deleted file mode 100644 index e9ebbe7c86fe..000000000000 --- a/docs/java-rest/high-level/ccr/put_auto_follow_pattern.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: ccr-put-auto-follow-pattern -:request: PutAutoFollowPatternRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Put Auto Follow Pattern API - -[id="{upid}-{api}-request"] -==== Request - -The Put Auto Follow Pattern API allows you to store auto follow patterns in order -to automatically follow leader indices in a remote clusters matching certain -index name patterns. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the auto follow pattern. -<2> The name of the remote cluster. -<3> The leader index patterns. -<4> The leader index exclusion patterns. -<5> The pattern used to create the follower index. -<6> The settings overrides for the follower index. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the put auto follow pattern request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the put auto follow pattern request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ccr/put_follow.asciidoc b/docs/java-rest/high-level/ccr/put_follow.asciidoc deleted file mode 100644 index 0ea7e596ea65..000000000000 --- a/docs/java-rest/high-level/ccr/put_follow.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: ccr-put-follow -:request: PutFollowRequest -:response: PutFollowResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create follower API - - -[id="{upid}-{api}-request"] -==== Request - -Creates a follower index and makes that index follow a leader index. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the remote cluster alias. -<2> The name of the leader in the remote cluster. -<3> The name of the follower index to create. -<4> The number of shard copies that must be active before the call returns. -<5> The settings overrides for the follower index. - -[id="{upid}-{api}-response"] -==== Response - -The +{response}+ indicates if the request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether the follower index was created. -<2> Whether the follower shards are started. -<3> Whether the follower index started following the leader index. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ccr/resume_auto_follow_pattern.asciidoc b/docs/java-rest/high-level/ccr/resume_auto_follow_pattern.asciidoc deleted file mode 100644 index 8bc24ead2779..000000000000 --- a/docs/java-rest/high-level/ccr/resume_auto_follow_pattern.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ --- -:api: ccr-resume-auto-follow-pattern -:request: ResumeAutoFollowPatternRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Resume Auto Follow Pattern API - -[id="{upid}-{api}-request"] -==== Request - -The Resume Auto Follow Pattern API allows you to resume the activity - for a pause auto follow pattern. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the auto follow pattern. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the resume auto follow pattern request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the resume auto follow pattern request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ccr/resume_follow.asciidoc b/docs/java-rest/high-level/ccr/resume_follow.asciidoc deleted file mode 100644 index e30f83115fa9..000000000000 --- a/docs/java-rest/high-level/ccr/resume_follow.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: ccr-resume-follow -:request: ResumeFollowRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Resume Follow API - - -[id="{upid}-{api}-request"] -==== Request - -The Resume Follow API allows you to resume following a follower index that has been paused. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of follower index. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the resume follow request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the resume follow was acknowledged. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ccr/unfollow.asciidoc b/docs/java-rest/high-level/ccr/unfollow.asciidoc deleted file mode 100644 index 946a2c6e6181..000000000000 --- a/docs/java-rest/high-level/ccr/unfollow.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: ccr-unfollow -:request: UnfollowRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Unfollow API - - -[id="{upid}-{api}-request"] -==== Request - -The Unfollow API allows you to unfollow a follower index and make it a regular index. -Note that the follower index needs to be paused and the follower index needs to be closed. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of follow index to unfollow. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the unfollow request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the unfollow was acknowledge. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/cluster/delete_component_template.asciidoc b/docs/java-rest/high-level/cluster/delete_component_template.asciidoc deleted file mode 100644 index 9655123d9a05..000000000000 --- a/docs/java-rest/high-level/cluster/delete_component_template.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ --- -:api: delete-component-template -:request: DeleteComponentTemplateRequest -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Delete Component Template API - -[id="{upid}-{api}-request"] -==== Request - -The Delete Component Template API allows you to delete a component template. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the component template to delete. - -=== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete component template request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the delete component template request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/cluster/get_component_template.asciidoc b/docs/java-rest/high-level/cluster/get_component_template.asciidoc deleted file mode 100644 index f112431b0c2f..000000000000 --- a/docs/java-rest/high-level/cluster/get_component_template.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ --- -:api: get-component-templates -:request: GetComponentTemplatesRequest -:response: GetComponentTemplatesResponse --- - -[id="{upid}-{api}"] -=== Get Component Templates API - -The Get Component Templates API allows to retrieve information about one or more component templates. - -[id="{upid}-{api}-request"] -==== Get Component Templates Request - -A +{request}+ specifies one component template name to retrieve. -To return all component templates omit the name altogether. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> A single component template name - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Component Templates Response - -The returned +{response}+ consists a map of component template names and their corresponding definition. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> A map of matching component template names and the corresponding definitions diff --git a/docs/java-rest/high-level/cluster/get_settings.asciidoc b/docs/java-rest/high-level/cluster/get_settings.asciidoc deleted file mode 100644 index 407d33f8fc8a..000000000000 --- a/docs/java-rest/high-level/cluster/get_settings.asciidoc +++ /dev/null @@ -1,63 +0,0 @@ --- -:api: get-settings -:request: ClusterGetSettingsRequest -:response: ClusterGetSettingsResponse --- - -[id="{upid}-{api}"] -=== Cluster Get Settings API - -The Cluster Get Settings API allows to get the cluster wide settings. - -[id="{upid}-{api}-request"] -==== Cluster Get Settings Request - -A +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-includeDefaults] --------------------------------------------------- -<1> By default only those settings that were explicitly set are returned. Setting this to true also returns -the default settings. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-local] --------------------------------------------------- -<1> By default the request goes to the master of the cluster to get the latest results. If local is specified it gets -the results from whichever node the request goes to. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Cluster Get Settings Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Get the persistent settings. -<2> Get the transient settings. -<3> Get the default settings (returns empty settings if `includeDefaults` was not set to `true`). -<4> Get the value as a `String` for a particular setting. The order of searching is first in `persistentSettings` then in -`transientSettings` and finally, if not found in either, in `defaultSettings`. - diff --git a/docs/java-rest/high-level/cluster/health.asciidoc b/docs/java-rest/high-level/cluster/health.asciidoc deleted file mode 100644 index 06163fca52da..000000000000 --- a/docs/java-rest/high-level/cluster/health.asciidoc +++ /dev/null @@ -1,177 +0,0 @@ --- -:api: health -:request: ClusterHealthRequest -:response: ClusterHealthResponse --- - -[id="{upid}-{api}"] -=== Cluster Health API - -The Cluster Health API allows getting cluster health. - -[id="{upid}-{api}-request"] -==== Cluster Health Request - -A +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -There are no required parameters. By default, the client will check all indices and will not wait -for any events. - -==== Indices - -Indices which should be checked can be passed in the constructor: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indices-ctr] --------------------------------------------------- - -Or using the corresponding setter method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indices-setter] --------------------------------------------------- - -==== Other parameters - -Other parameters can be passed only through setter methods: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout for the request as a `TimeValue`. Defaults to 30 seconds -<2> As a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-master-timeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue`. Defaults to the same as `timeout` -<2> As a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait-status] --------------------------------------------------- -<1> The status to wait (e.g. `green`, `yellow`, or `red`). Accepts a `ClusterHealthStatus` value. -<2> Using predefined method - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait-events] --------------------------------------------------- -<1> The priority of the events to wait for. Accepts a `Priority` value. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-level] --------------------------------------------------- -<1> The level of detail of the returned health information. Accepts a +{request}.Level+ value. -Default value is `cluster`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait-relocation] --------------------------------------------------- -<1> Wait for 0 relocating shards. Defaults to `false` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait-initializing] --------------------------------------------------- -<1> Wait for 0 initializing shards. Defaults to `false` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait-nodes] --------------------------------------------------- -<1> Wait for `N` nodes in the cluster. Defaults to `0` -<2> Using `>=N`, `<=N`, `>N` and ` Using `ge(N)`, `le(N)`, `gt(N)`, `lt(N)` notation - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait-active] --------------------------------------------------- - -<1> Wait for all shards to be active in the cluster -<2> Wait for `N` shards to be active in the cluster - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-local] --------------------------------------------------- -<1> Non-master node can be used for this request. Defaults to `false` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Cluster Health Response - -The returned +{response}+ contains the next information about the -cluster: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-general] --------------------------------------------------- -<1> Name of the cluster -<2> Cluster status (`green`, `yellow` or `red`) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-request-status] --------------------------------------------------- -<1> Whether request was timed out while processing -<2> Status of the request (`OK` or `REQUEST_TIMEOUT`). Other errors will be thrown as exceptions - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-nodes] --------------------------------------------------- -<1> Number of nodes in the cluster -<2> Number of data nodes in the cluster - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-shards] --------------------------------------------------- -<1> Number of active shards -<2> Number of primary active shards -<3> Number of relocating shards -<4> Number of initializing shards -<5> Number of unassigned shards -<6> Number of unassigned shards that are currently being delayed -<7> Percent of active shards - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-task] --------------------------------------------------- -<1> Maximum wait time of all tasks in the queue -<2> Number of currently pending tasks -<3> Number of async fetches that are currently ongoing - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-indices] --------------------------------------------------- -<1> Detailed information about indices in the cluster - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-index] --------------------------------------------------- -<1> Detailed information about a specific index - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-shard-details] --------------------------------------------------- -<1> Detailed information about a specific shard \ No newline at end of file diff --git a/docs/java-rest/high-level/cluster/put_component_template.asciidoc b/docs/java-rest/high-level/cluster/put_component_template.asciidoc deleted file mode 100644 index 2ef158ca3daf..000000000000 --- a/docs/java-rest/high-level/cluster/put_component_template.asciidoc +++ /dev/null @@ -1,64 +0,0 @@ --- -:api: put-component-template -:request: PutComponentTemplateRequest -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Create or update component template API - -Creates or updates a component template. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ specifies the name of the component template and the template definition, -which can consist of the settings, mappings or aliases, together with a version (which -can be used to simply component template management by external systems) and a metadata -map consisting of user specific information. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the component template -<2> Template configuration containing the settings, mappings and aliases for this component template - -===== Version -A component template can optionally specify a version number which can be used to simplify template -management by external systems. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-version] --------------------------------------------------- -<1> The version number of the template - -=== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-create] --------------------------------------------------- -<1> To force to only create a new template; do not overwrite the existing template - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/cluster/put_settings.asciidoc b/docs/java-rest/high-level/cluster/put_settings.asciidoc deleted file mode 100644 index bc9abc62456c..000000000000 --- a/docs/java-rest/high-level/cluster/put_settings.asciidoc +++ /dev/null @@ -1,93 +0,0 @@ --- -:api: put-settings -:request: ClusterUpdateSettingsRequest -:response: ClusterUpdateSettingsResponse --- - -[id="{upid}-{api}"] -=== Cluster Update Settings API - -The Cluster Update Settings API allows to update cluster wide settings. - -[id="{upid}-{api}-request"] -==== Cluster Update Settings Request - -A +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -==== Cluster Settings -At least one setting to be updated must be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-cluster-settings] --------------------------------------------------- -<1> Sets the transient settings to be applied -<2> Sets the persistent setting to be applied - -==== Providing the Settings -The settings to be applied can be provided in different ways: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-create-settings] --------------------------------------------------- -<1> Creates a transient setting as `Settings` -<2> Creates a persistent setting as `Settings` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-settings-builder] --------------------------------------------------- -<1> Settings provided as `Settings.Builder` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-settings-source] --------------------------------------------------- -<1> Settings provided as `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-settings-map] --------------------------------------------------- -<1> Settings provided as a `Map` - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Cluster Update Settings Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates which transient settings have been applied -<3> Indicates which persistent settings have been applied diff --git a/docs/java-rest/high-level/cluster/remote_info.asciidoc b/docs/java-rest/high-level/cluster/remote_info.asciidoc deleted file mode 100644 index 6496a04a3a76..000000000000 --- a/docs/java-rest/high-level/cluster/remote_info.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ --- -:api: remote-info -:request: RemoteInfoRequest -:response: RemoteInfoResponse --- - -[id="{upid}-{api}"] -=== Remote Cluster Info API - -The Remote cluster info API allows to get all of the configured remote cluster information. - -[id="{upid}-{api}-request"] -==== Remote Cluster Info Request - -A +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -There are no required parameters. - -==== Remote Cluster Info Response - -The returned +{response}+ allows to retrieve remote cluster information. -It returns connection and endpoint information keyed by the configured remote cluster alias. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/document/bulk.asciidoc b/docs/java-rest/high-level/document/bulk.asciidoc deleted file mode 100644 index 061516388c4b..000000000000 --- a/docs/java-rest/high-level/document/bulk.asciidoc +++ /dev/null @@ -1,217 +0,0 @@ --- -:api: bulk -:request: BulkRequest -:response: BulkResponse --- - -[id="{upid}-{api}"] -=== Bulk API - -NOTE: The Java High Level REST Client provides the -<<{upid}-{api}-processor>> to assist with bulk requests. - -[id="{upid}-{api}-request"] -==== Bulk Request - -A +{request}+ can be used to execute multiple index, update and/or delete -operations using a single request. - -It requires at least one operation to be added to the Bulk request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Creates the +{request}+ -<2> Adds a first `IndexRequest` to the Bulk request. See <<{upid}-index>> for -more information on how to build `IndexRequest`. -<3> Adds a second `IndexRequest` -<4> Adds a third `IndexRequest` - -WARNING: The Bulk API supports only documents encoded in JSON or SMILE. -Providing documents in any other format will result in an error. - -And different operation types can be added to the same +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-with-mixed-operations] --------------------------------------------------- -<1> Adds a `DeleteRequest` to the +{request}+. See <<{upid}-delete>> -for more information on how to build `DeleteRequest`. -<2> Adds an `UpdateRequest` to the +{request}+. See <<{upid}-update>> -for more information on how to build `UpdateRequest`. -<3> Adds an `IndexRequest` using the SMILE format - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the bulk request to be performed as a `TimeValue` -<2> Timeout to wait for the bulk request to be performed as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -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-file}[{api}-request-active-shards] --------------------------------------------------- -<1> Sets the number of shard copies that must be active before proceeding with -the index/update/delete operations. -<2> Number of shard copies provided as a `ActiveShardCount`: can be -`ActiveShardCount.ALL`, `ActiveShardCount.ONE` or -`ActiveShardCount.DEFAULT` (default) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-pipeline] --------------------------------------------------- -<1> Global pipelineId used on all sub requests, unless overridden on a sub request - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Global routingId used on all sub requests, unless overridden on a sub request - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-index-type] --------------------------------------------------- -<1> A bulk request with a global index used on all sub requests, unless overridden on a sub request. -This parameter is @Nullable and can only be set during +{request}+ creation. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Bulk Response - -The returned +{response}+ contains information about the executed operations and - allows to iterate over each result as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Iterate over the results of all operations -<2> Retrieve the response of the operation (successful or not), can be -`IndexResponse`, `UpdateResponse` or `DeleteResponse` which can all be seen as -`DocWriteResponse` instances -<3> Handle the response of an index operation -<4> Handle the response of a update operation -<5> Handle the response of a delete operation - -The Bulk response provides a method to quickly check if one or more operation -has failed: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-has-failures] --------------------------------------------------- -<1> This method returns `true` if at least one operation failed - -In such situation it is necessary to iterate over all operation results in order -to check if the operation failed, and if so, retrieve the corresponding failure: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-errors] --------------------------------------------------- -<1> Indicate if a given operation failed -<2> Retrieve the failure of the failed operation - -[id="{upid}-{api}-processor"] -==== Bulk Processor - -The `BulkProcessor` simplifies the usage of the Bulk API by providing -a utility class that allows index/update/delete operations to be -transparently executed as they are added to the processor. - -In order to execute the requests, the `BulkProcessor` requires the following -components: - -`RestHighLevelClient`:: This client is used to execute the +{request}+ -and to retrieve the `BulkResponse` -`BulkProcessor.Listener`:: This listener is called before and after -every +{request}+ execution or when a +{request}+ failed - -Then the `BulkProcessor.builder` method can be used to build a new -`BulkProcessor`: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-processor-init] --------------------------------------------------- -<1> Create the `BulkProcessor.Listener` -<2> This method is called before each execution of a +{request}+ -<3> This method is called after each execution of a +{request}+ -<4> This method is called when a +{request}+ failed -<5> Create the `BulkProcessor` by calling the `build()` method from -the `BulkProcessor.Builder`. The `RestHighLevelClient.bulkAsync()` -method will be used to execute the +{request}+ under the hood. - -The `BulkProcessor.Builder` provides methods to configure how the -`BulkProcessor` should handle requests execution: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-processor-options] --------------------------------------------------- -<1> Set when to flush a new bulk request based on the number of -actions currently added (defaults to 1000, use -1 to disable it) -<2> Set when to flush a new bulk request based on the size of -actions currently added (defaults to 5Mb, use -1 to disable it) -<3> Set the number of concurrent requests allowed to be executed -(default to 1, use 0 to only allow the execution of a single request) -<4> Set a flush interval flushing any +{request}+ pending if the -interval passes (defaults to not set) -<5> Set a constant back off policy that initially waits for 1 second -and retries up to 3 times. See `BackoffPolicy.noBackoff()`, -`BackoffPolicy.constantBackoff()` and `BackoffPolicy.exponentialBackoff()` -for more options. - -Once the `BulkProcessor` is created requests can be added to it: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-processor-add] --------------------------------------------------- - -The requests will be executed by the `BulkProcessor`, which takes care of -calling the `BulkProcessor.Listener` for every bulk request. - -The listener provides methods to access to the +{request}+ and the +{response}+: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-processor-listener] --------------------------------------------------- -<1> Called before each execution of a +{request}+, this method allows to know -the number of operations that are going to be executed within the +{request}+ -<2> Called after each execution of a +{request}+, this method allows to know if -the +{response}+ contains errors -<3> Called if the +{request}+ failed, this method allows to know -the failure - -Once all requests have been added to the `BulkProcessor`, its instance needs to -be closed using one of the two available closing methods. - -The `awaitClose()` method can be used to wait until all requests have been -processed or the specified waiting time elapses: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-processor-await] --------------------------------------------------- -<1> The method returns `true` if all bulk requests completed and `false` if the -waiting time elapsed before all the bulk requests completed - -The `close()` method can be used to immediately close the `BulkProcessor`: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-processor-close] --------------------------------------------------- - -Both methods flush the requests added to the processor before closing the -processor and also forbid any new request to be added to it. diff --git a/docs/java-rest/high-level/document/delete-by-query.asciidoc b/docs/java-rest/high-level/document/delete-by-query.asciidoc deleted file mode 100644 index f4ef87741e63..000000000000 --- a/docs/java-rest/high-level/document/delete-by-query.asciidoc +++ /dev/null @@ -1,131 +0,0 @@ --- -:api: delete-by-query -:request: DeleteByQueryRequest -:response: DeleteByQueryResponse --- - -[id="{upid}-{api}"] -=== Delete By Query API - -[id="{upid}-{api}-request"] -==== Delete By Query Request - -A +{request}+ can be used to delete documents from an index. It requires an -existing index (or a set of indices) on which deletion is to be performed. - -The simplest form of a +{request}+ looks like this and deletes all documents -in an index: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Creates the +{request}+ on a set of indices. - -By default version conflicts abort the +{request}+ process but you can just -count them with this: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-conflicts] --------------------------------------------------- -<1> Set `proceed` on version conflict - -You can limit the documents by adding a query. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-query] --------------------------------------------------- -<1> Only copy documents which have field `user` set to `kimchy` - -It’s also possible to limit the number of processed documents by setting `maxDocs`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-maxDocs] --------------------------------------------------- -<1> Only copy 10 documents - -By default +{request}+ uses batches of 1000. You can change the batch size -with `setBatchSize`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-scrollSize] --------------------------------------------------- -<1> Use batches of 100 documents - -+{request}+ can also be parallelized using `sliced-scroll` with `setSlices`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-slices] --------------------------------------------------- -<1> set number of slices to use - -+{request}+ uses the `scroll` parameter to control how long it keeps the -"search context" alive. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-scroll] --------------------------------------------------- -<1> set scroll time - -If you provide routing then the routing is copied to the scroll query, limiting the process to the shards that match -that routing value. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> set routing - - -==== Optional arguments -In addition to the options above the following arguments can optionally be also provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the delete by query request to be performed as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-refresh] --------------------------------------------------- -<1> Refresh index after calling delete by query - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Set indices options - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete By Query Response - -The returned +{response}+ contains information about the executed operations and -allows to iterate over each result as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Get total time taken -<2> Check if the request timed out -<3> Get total number of docs processed -<4> Number of docs that were deleted -<5> Number of batches that were executed -<6> Number of skipped docs -<7> Number of version conflicts -<8> Number of times request had to retry bulk index operations -<9> Number of times request had to retry search operations -<10> The total time this request has throttled itself not including the current throttle time if it is currently sleeping -<11> Remaining delay of any current throttle sleep or 0 if not sleeping -<12> Failures during search phase -<13> Failures during bulk index operation diff --git a/docs/java-rest/high-level/document/delete.asciidoc b/docs/java-rest/high-level/document/delete.asciidoc deleted file mode 100644 index 60da9d52787b..000000000000 --- a/docs/java-rest/high-level/document/delete.asciidoc +++ /dev/null @@ -1,90 +0,0 @@ --- -:api: delete -:request: DeleteRequest -:response: DeleteResponse --- - -[id="{upid}-{api}"] -=== Delete API - -[id="{upid}-{api}-request"] -==== Delete Request - -A +{request}+ has two required arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Index -<2> Document id - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Routing value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -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-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-file}[{api}-request-version] --------------------------------------------------- -<1> Version - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-version-type] --------------------------------------------------- -<1> Version type - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Handle the situation where number of successful shards is less than -total shards -<2> Handle the potential failures - - -It is also possible to check whether the document was found or not: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-notfound] --------------------------------------------------- -<1> Do something if the document to be deleted was not found - -If there is a version conflict, an `ElasticsearchException` will -be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-conflict] --------------------------------------------------- -<1> The raised exception indicates that a version conflict error was returned - diff --git a/docs/java-rest/high-level/document/exists.asciidoc b/docs/java-rest/high-level/document/exists.asciidoc deleted file mode 100644 index 7ca3b82fb861..000000000000 --- a/docs/java-rest/high-level/document/exists.asciidoc +++ /dev/null @@ -1,37 +0,0 @@ --- -:api: exists -:request: GetRequest -:response: boolean --- - -[id="{upid}-{api}"] -=== Exists API - -The exists API returns `true` if a document exists, and `false` otherwise. - -[id="{upid}-{api}-request"] -==== Exists Request - -It uses +{request}+ just like the <>. -All of its <> -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-file}[{api}-request] --------------------------------------------------- -<1> Index -<2> Document id -<3> Disable fetching `_source`. -<4> Disable fetching stored fields. - -include::../execution.asciidoc[] - - -==== Source exists request -A variant of the exists request is `existsSource` method which has the additional check -that the document in question has stored the `source`. If the mapping for the index has opted -to remove support for storing JSON source in documents then this method will return false -for documents in this index. diff --git a/docs/java-rest/high-level/document/get-source.asciidoc b/docs/java-rest/high-level/document/get-source.asciidoc deleted file mode 100644 index f5a2ca8ec5d8..000000000000 --- a/docs/java-rest/high-level/document/get-source.asciidoc +++ /dev/null @@ -1,72 +0,0 @@ --- -:api: get-source -:request: GetSourceRequest -:response: GetSourceResponse --- - -[id="{upid}-{api}"] -=== Get Source API - -This API helps to get only the `_source` field of a document. - -[id="{upid}-{api}-request"] -==== Get Source Request - -A +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Index -<2> Document id - -[id="{upid}-{api}-request-optional"] -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-optional] --------------------------------------------------- -<1> `FetchSourceContext` 's first argument `fetchSource` must be `true`, otherwise -`ElasticsearchException` get thrown -<2> Arguments of the context `excludes` and `includes` are optional -(see examples in Get API documentation) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Routing value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-preference] --------------------------------------------------- -<1> Preference value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-realtime] --------------------------------------------------- -<1> Set realtime flag to `false` (`true` by default) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-refresh] --------------------------------------------------- -<1> Perform a refresh before retrieving the document (`false` by default) - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Source Response - -The returned +{response}+ contains the field `source` that represents the -source of a document as a map. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/document/get.asciidoc b/docs/java-rest/high-level/document/get.asciidoc deleted file mode 100644 index 2916eb9335c7..000000000000 --- a/docs/java-rest/high-level/document/get.asciidoc +++ /dev/null @@ -1,126 +0,0 @@ --- -:api: get -:request: GetRequest -:response: GetResponse --- - -[id="{upid}-{api}"] -=== Get API - -[id="{upid}-{api}-request"] -==== Get Request - -A +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Index -<2> Document id - -[id="{upid}-{api}-request-optional-arguments"] -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-no-source] --------------------------------------------------- -<1> Disable source retrieval, enabled by default - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-source-include] --------------------------------------------------- -<1> Configure source inclusion for specific fields - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-source-exclude] --------------------------------------------------- -<1> Configure source exclusion for specific fields - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-stored] --------------------------------------------------- -<1> Configure retrieval for specific stored fields (requires fields to be -stored separately in the mappings) -<2> Retrieve the `message` stored field (requires the field to be stored -separately in the mappings) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Routing value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-preference] --------------------------------------------------- -<1> Preference value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-realtime] --------------------------------------------------- -<1> Set realtime flag to `false` (`true` by default) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-refresh] --------------------------------------------------- -<1> Perform a refresh before retrieving the document (`false` by default) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-version] --------------------------------------------------- -<1> Version - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-version-type] --------------------------------------------------- -<1> Version type - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Response - -The returned +{response}+ allows to retrieve the requested document along with -its metadata and eventually stored fields. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Retrieve the document as a `String` -<2> Retrieve the document as a `Map` -<3> Retrieve the document as a `byte[]` -<4> Handle the scenario where the document was not found. Note that although -the returned response has `404` status code, a valid +{response}+ is -returned rather than an exception thrown. Such response does not hold any -source document and its `isExists` method returns `false`. - -When a get request is performed against an index that does not exist, the -response has `404` status code, an `ElasticsearchException` gets thrown -which needs to be handled as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-indexnotfound] --------------------------------------------------- -<1> Handle the exception thrown because the index does not exist - -In case a specific document version has been requested, and the existing -document has a different version number, a version conflict is raised: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-conflict] --------------------------------------------------- -<1> The raised exception indicates that a version conflict error was returned diff --git a/docs/java-rest/high-level/document/index.asciidoc b/docs/java-rest/high-level/document/index.asciidoc deleted file mode 100644 index 5a201a02a88b..000000000000 --- a/docs/java-rest/high-level/document/index.asciidoc +++ /dev/null @@ -1,132 +0,0 @@ --- -:api: index -:request: IndexRequest -:response: IndexResponse --- - -[id="{upid}-{api}"] -=== Index API - -[id="{upid}-{api}-request"] -==== Index Request - -An +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-string] --------------------------------------------------- -<1> Index -<2> Document id for the request -<3> Document source provided as a `String` - -==== Providing the document source -The document source can be provided in different ways in addition to the -`String` example shown above: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-map] --------------------------------------------------- -<1> Document source provided as a `Map` which gets automatically converted -to JSON format - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-xcontent] --------------------------------------------------- -<1> Document source provided as an `XContentBuilder` object, the Elasticsearch -built-in helpers to generate JSON content - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-shortcut] --------------------------------------------------- -<1> Document source provided as `Object` key-pairs, which gets converted to -JSON format - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Routing value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -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-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-file}[{api}-request-version] --------------------------------------------------- -<1> Version - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-version-type] --------------------------------------------------- -<1> Version type - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-op-type] --------------------------------------------------- -<1> Operation type provided as an `DocWriteRequest.OpType` value -<2> Operation type provided as a `String`: can be `create` or `index` (default) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-pipeline] --------------------------------------------------- -<1> The name of the ingest pipeline to be executed before indexing the document - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Index Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Handle (if needed) the case where the document was created for the first -time -<2> Handle (if needed) the case where the document was rewritten as it was -already existing -<3> Handle the situation where number of successful shards is less than -total shards -<4> Handle the potential failures - -If there is a version conflict, an `ElasticsearchException` will -be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-conflict] --------------------------------------------------- -<1> The raised exception indicates that a version conflict error was returned - -Same will happen in case `opType` was set to `create` and a document with -same index and id already existed: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-optype] --------------------------------------------------- -<1> The raised exception indicates that a version conflict error was returned diff --git a/docs/java-rest/high-level/document/multi-get.asciidoc b/docs/java-rest/high-level/document/multi-get.asciidoc deleted file mode 100644 index 18f94d123d69..000000000000 --- a/docs/java-rest/high-level/document/multi-get.asciidoc +++ /dev/null @@ -1,134 +0,0 @@ --- -:api: multi-get -:request: MultiGetRequest -:response: MultiGetResponse --- - -[id="{upid}-{api}"] -=== Multi-Get API - -The `multiGet` API executes multiple <> -requests in a single http request in parallel. - -[id="{upid}-{api}-request"] -==== Multi-Get Request - -A +{request}+ is built empty and you add `MultiGetRequest.Item`s to configure -what to fetch: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Index -<2> Document id -<3> Add another item to fetch - -==== Optional arguments - -`multiGet` supports the same optional arguments that the -<> supports. -You can set most of these on the `Item`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-no-source] --------------------------------------------------- -<1> Disable source retrieval, enabled by default - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-source-include] --------------------------------------------------- -<1> Configure source inclusion for specific fields - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-source-exclude] --------------------------------------------------- -<1> Configure source exclusion for specific fields - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-stored] --------------------------------------------------- -<1> Configure retrieval for specific stored fields (requires fields to be -stored separately in the mappings) -<2> Retrieve the `foo` stored field (requires the field to be stored -separately in the mappings) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-item-extras] --------------------------------------------------- -<1> Routing value -<2> Version -<3> Version type - -{ref}/search-search.html#search-preference[`preference`], -{ref}/docs-get.html#realtime[`realtime`] -and -{ref}/docs-get.html#get-refresh[`refresh`] can be set on the main request but -not on any items: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-top-level-extras] --------------------------------------------------- -<1> Preference value -<2> Set realtime flag to `false` (`true` by default) -<3> Perform a refresh before retrieving the document (`false` by default) - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Multi Get Response - -The returned +{response}+ contains a list of `MultiGetItemResponse`s in -`getResponses` in the same order that they were requested. -`MultiGetItemResponse` contains *either* a -<> if the get succeeded -or a `MultiGetResponse.Failure` if it failed. A success looks just like a -normal `GetResponse`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `getFailure` returns null because there isn't a failure. -<2> `getResponse` returns the `GetResponse`. -<3> Retrieve the document as a `String` -<4> Retrieve the document as a `Map` -<5> Retrieve the document as a `byte[]` -<6> Handle the scenario where the document was not found. Note that although -the returned response has `404` status code, a valid `GetResponse` is -returned rather than an exception thrown. Such response does not hold any -source document and its `isExists` method returns `false`. - -When one of the subrequests as performed against an index that does not exist -`getFailure` will contain an exception: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-indexnotfound] --------------------------------------------------- -<1> `getResponse` is null. -<2> `getFailure` isn't and contains an `Exception`. -<3> That `Exception` is actually an `ElasticsearchException` -<4> and it has a status of `NOT_FOUND`. It'd have been an HTTP 404 if this -wasn't a multi get. -<5> `getMessage` explains the actual cause, `no such index`. - -In case a specific document version has been requested, and the existing -document has a different version number, a version conflict is raised: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-conflict] --------------------------------------------------- -<1> `getResponse` is null. -<2> `getFailure` isn't and contains an `Exception`. -<3> That `Exception` is actually an `ElasticsearchException` -<4> and it has a status of `CONFLICT`. It'd have been an HTTP 409 if this -wasn't a multi get. -<5> `getMessage` explains the actual cause, ` diff --git a/docs/java-rest/high-level/document/multi-term-vectors.asciidoc b/docs/java-rest/high-level/document/multi-term-vectors.asciidoc deleted file mode 100644 index 52d633b2d593..000000000000 --- a/docs/java-rest/high-level/document/multi-term-vectors.asciidoc +++ /dev/null @@ -1,59 +0,0 @@ --- -:api: multi-term-vectors -:request: MultiTermVectorsRequest -:response: MultiTermVectorsResponse -:tvrequest: TermVectorsRequest --- - -[id="{upid}-{api}"] -=== Multi Term Vectors API - -Multi Term Vectors API allows to get multiple term vectors at once. - -[id="{upid}-{api}-request"] -==== Multi Term Vectors Request -There are two ways to create a +{request}+. - -The first way is to create an empty +{request}+, and then add individual -<> to it. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Create an empty +{request}+. -<2> Add the first +{tvrequest}+ to the +{request}+. -<3> Add the second +{tvrequest}+ for an artificial doc to the +{request}+. - - -The second way can be used when all term vectors requests share the same -arguments, such as index and other settings. In this case, a template -+{tvrequest}+ can be created with all necessary settings set, and -this template request can be passed to +{request}+ along with all -documents' ids for which to execute these requests. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-template] --------------------------------------------------- -<1> Create a template +{tvrequest}+. -<2> Pass documents' ids and the template to the +{request}+. - - -include::../execution.asciidoc[] - - -[id="{upid}-{api}-response"] -==== Multi Term Vectors Response - -+{response}+ allows to get the list of term vectors responses, -each of which can be inspected as described in -<>. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Get a list of `TermVectorsResponse` - - diff --git a/docs/java-rest/high-level/document/reindex.asciidoc b/docs/java-rest/high-level/document/reindex.asciidoc deleted file mode 100644 index c094a5f1ab7e..000000000000 --- a/docs/java-rest/high-level/document/reindex.asciidoc +++ /dev/null @@ -1,186 +0,0 @@ --- -:api: reindex -:request: ReindexRequest -:response: BulkByScrollResponse --- - -[id="{upid}-{api}"] -=== Reindex API - -[id="{upid}-{api}-request"] -==== Reindex Request - -A +{request}+ can be used to copy documents from one or more indexes into a -destination index. - -It requires an existing source index and a target index which may or may not exist pre-request. Reindex does not attempt -to set up the destination index. It does not copy the settings of the source index. You should set up the destination -index prior to running a _reindex action, including setting up mappings, shard counts, replicas, etc. - -The simplest form of a +{request}+ looks like this: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Creates the +{request}+ -<2> Adds a list of sources to copy from -<3> Adds the destination index - -The `dest` element can be configured like the index API to control optimistic concurrency control. Just leaving out -`versionType` (as above) or setting it to internal will cause Elasticsearch to blindly dump documents into the target. -Setting `versionType` to external will cause Elasticsearch to preserve the version from the source, create any documents -that are missing, and update any documents that have an older version in the destination index than they do in the -source index. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-versionType] --------------------------------------------------- -<1> Set the versionType to `EXTERNAL` - -Setting `opType` to `create` will cause `_reindex` to only create missing documents in the target index. All existing -documents will cause a version conflict. The default `opType` is `index`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-opType] --------------------------------------------------- -<1> Set the opType to `create` - -By default version conflicts abort the `_reindex` process but you can just count -them instead with: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-conflicts] --------------------------------------------------- -<1> Set `proceed` on version conflict - -You can limit the documents by adding a query. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-query] --------------------------------------------------- -<1> Only copy documents which have field `user` set to `kimchy` - -It’s also possible to limit the number of processed documents by setting `maxDocs`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-maxDocs] --------------------------------------------------- -<1> Only copy 10 documents - -By default `_reindex` uses batches of 1000. You can change the batch size with `sourceBatchSize`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-sourceSize] --------------------------------------------------- -<1> Use batches of 100 documents - -Reindex can also use the ingest feature by specifying a `pipeline`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-pipeline] --------------------------------------------------- -<1> set pipeline to `my_pipeline` - -+{request}+ also supports a `script` that modifies the document. It allows you to -also change the document's metadata. The following example illustrates that. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-script] --------------------------------------------------- -<1> `setScript` to increment the `likes` field on all documents with user `kimchy`. - -+{request}+ supports reindexing from a remote Elasticsearch cluster. When using a remote cluster the query should be -specified inside the `RemoteInfo` object and not using `setSourceQuery`. If both the remote info and the source query are -set it results in a validation error during the request. The reason for this is that the remote Elasticsearch may not -understand queries built by the modern query builders. The remote cluster support works all the way back to Elasticsearch -0.90 and the query language has changed since then. When reaching older versions, it is safer to write the query by hand -in JSON. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-remote] --------------------------------------------------- -<1> set remote elastic cluster - -+{request}+ also helps in automatically parallelizing using `sliced-scroll` to -slice on `_id`. Use `setSlices` to specify the number of slices to use. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-slices] --------------------------------------------------- -<1> set number of slices to use - -+{request}+ uses the `scroll` parameter to control how long it keeps the -"search context" alive. -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-scroll] --------------------------------------------------- -<1> set scroll time - - -==== Optional arguments -In addition to the options above the following arguments can optionally be also provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the reindex request to be performed as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-refresh] --------------------------------------------------- -<1> Refresh index after calling reindex - -include::../execution.asciidoc[] - -[id="{upid}-{api}-task-submission"] -==== Reindex task submission -It is also possible to submit a +{request}+ and not wait for it completion with the use of Task API. This is an equivalent of a REST request -with wait_for_completion flag set to false. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{hlrc-tests}/ReindexIT.java[submit-reindex-task] --------------------------------------------------- -<1> A +{request}+ is constructed the same way as for the synchronous method -<2> A submit method returns a `TaskSubmissionResponse` which contains a task identifier. -<3> The task identifier can be used to get `response` from a completed task. - -[id="{upid}-{api}-response"] -==== Reindex Response - -The returned +{response}+ contains information about the executed operations and -allows to iterate over each result as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Get total time taken -<2> Check if the request timed out -<3> Get total number of docs processed -<4> Number of docs that were updated -<5> Number of docs that were created -<6> Number of docs that were deleted -<7> Number of batches that were executed -<8> Number of skipped docs -<9> Number of version conflicts -<10> Number of times request had to retry bulk index operations -<11> Number of times request had to retry search operations -<12> The total time this request has throttled itself not including the current throttle time if it is currently sleeping -<13> Remaining delay of any current throttle sleep or 0 if not sleeping -<14> Failures during search phase -<15> Failures during bulk index operation diff --git a/docs/java-rest/high-level/document/rethrottle.asciidoc b/docs/java-rest/high-level/document/rethrottle.asciidoc deleted file mode 100644 index cb606521a1d5..000000000000 --- a/docs/java-rest/high-level/document/rethrottle.asciidoc +++ /dev/null @@ -1,79 +0,0 @@ --- -:api: rethrottle -:request: RethrottleRequest -:response: ListTasksResponse --- - -[id="{upid}-{api}"] -=== Rethrottle API - -[id="{upid}-{api}-request"] -==== Rethrottle Request - -A +{request}+ can be used to change the current throttling on a running -reindex, update-by-query or delete-by-query task or to disable throttling of -the task entirely. It requires the task Id of the task to change. - -In its simplest form, you can use it to disable throttling of a running -task using the following: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-disable-request] --------------------------------------------------- -<1> Create a +{request}+ that disables throttling for a specific task id - -By providing a `requestsPerSecond` argument, the request will change the -existing task throttling to the specified value: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Request to change the throttling of a task to 100 requests per second - -The rethrottling request can be executed by using one of the three appropriate -methods depending on whether a reindex, update-by-query or delete-by-query task -should be rethrottled: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-execution] --------------------------------------------------- -<1> Execute reindex rethrottling request -<2> The same for update-by-query -<3> The same for delete-by-query - -[id="{upid}-{api}-async"] -==== Asynchronous Execution - -The asynchronous execution of a rethrottle request requires both the +{request}+ -instance and an `ActionListener` instance to be passed to the asynchronous -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] --------------------------------------------------- -<1> Execute reindex rethrottling asynchronously -<2> The same for update-by-query -<3> The same for delete-by-query - -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 looks like this: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-async-listener] --------------------------------------------------- -<1> Code executed when the request is successfully completed -<2> Code executed when the request fails with an exception - -[id="{upid}-{api}-response"] -==== Rethrottle Response - -Rethrottling returns the task that has been rethrottled in the form of a -+{response}+. The structure of this response object is described in detail -in <>. diff --git a/docs/java-rest/high-level/document/term-vectors.asciidoc b/docs/java-rest/high-level/document/term-vectors.asciidoc deleted file mode 100644 index 65bb1eb0675f..000000000000 --- a/docs/java-rest/high-level/document/term-vectors.asciidoc +++ /dev/null @@ -1,100 +0,0 @@ --- -:api: term-vectors -:request: TermVectorsRequest -:response: TermVectorsResponse --- - -[id="{upid}-{api}"] -=== Term Vectors API - -Term Vectors API returns information and statistics on terms in the fields -of a particular document. The document could be stored in the index or -artificially provided by the user. - - -[id="{upid}-{api}-request"] -==== Term Vectors Request - -A +{request}+ expects an `index` and an `id` to specify -a certain document, and fields for which the information is retrieved. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -Term vectors can also be generated for artificial documents, that is for -documents not present in the index: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-artificial] --------------------------------------------------- -<1> An artificial document is provided as an `XContentBuilder` object, -the Elasticsearch built-in helper to generate JSON content. - -===== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-optional-arguments] --------------------------------------------------- -<1> Set `fieldStatistics` to `false` (default is `true`) to omit document count, -sum of document frequencies, sum of total term frequencies. -<2> Set `termStatistics` to `true` (default is `false`) to display -total term frequency and document frequency. -<3> Set `positions` to `false` (default is `true`) to omit the output of -positions. -<4> Set `offsets` to `false` (default is `true`) to omit the output of -offsets. -<5> Set `payloads` to `false` (default is `true`) to omit the output of -payloads. -<6> Set `filterSettings` to filter the terms that can be returned based -on their tf-idf scores. -<7> Set `perFieldAnalyzer` to specify a different analyzer than -the one that the field has. -<8> Set `realtime` to `false` (default is `true`) to retrieve term vectors -near realtime. -<9> Set a routing parameter - - -include::../execution.asciidoc[] - - -[id="{upid}-{api}-response"] -==== Term Vectors Response - -+{response}+ contains the following information: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The index name of the document. -<2> The id of the document. -<3> Indicates whether or not the document found. - - -===== Inspecting Term Vectors -If +{response}+ contains non-null list of term vectors, -more information about each term vector can be obtained using the following: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-term-vectors] --------------------------------------------------- -<1> The name of the current field -<2> Fields statistics for the current field - document count -<3> Fields statistics for the current field - sum of total term frequencies -<4> Fields statistics for the current field - sum of document frequencies -<5> Terms for the current field -<6> The name of the term -<7> Term frequency of the term -<8> Document frequency of the term -<9> Total term frequency of the term -<10> Score of the term -<11> Tokens of the term -<12> Position of the token -<13> Start offset of the token -<14> End offset of the token -<15> Payload of the token diff --git a/docs/java-rest/high-level/document/update-by-query.asciidoc b/docs/java-rest/high-level/document/update-by-query.asciidoc deleted file mode 100644 index 26a6bc362b19..000000000000 --- a/docs/java-rest/high-level/document/update-by-query.asciidoc +++ /dev/null @@ -1,148 +0,0 @@ --- -:api: update-by-query -:request: UpdateByQueryRequest -:response: UpdateByQueryResponse --- - -[id="{upid}-{api}"] -=== Update By Query API - -[id="{upid}-{api}-request"] -==== Update By Query Request - -A +{request}+ can be used to update documents in an index. - -It requires an existing index (or a set of indices) on which the update is to -be performed. - -The simplest form of a +{request}+ looks like this: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Creates the +{request}+ on a set of indices. - -By default version conflicts abort the +{request}+ process but you can just -count them instead with: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-conflicts] --------------------------------------------------- -<1> Set `proceed` on version conflict - -You can limit the documents by adding a query. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-query] --------------------------------------------------- -<1> Only copy documents which have field `user` set to `kimchy` - -It’s also possible to limit the number of processed documents by setting `maxDocs`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-maxDocs] --------------------------------------------------- -<1> Only copy 10 documents - -By default +{request}+ uses batches of 1000. You can change the batch size with -`setBatchSize`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-scrollSize] --------------------------------------------------- -<1> Use batches of 100 documents - -Update by query can also use the ingest feature by specifying a `pipeline`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-pipeline] --------------------------------------------------- -<1> set pipeline to `my_pipeline` - -+{request}+ also supports a `script` that modifies the document: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-script] --------------------------------------------------- -<1> `setScript` to increment the `likes` field on all documents with user `kimchy`. - -+{request}+ can be parallelized using `sliced-scroll` with `setSlices`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-slices] --------------------------------------------------- -<1> set number of slices to use - -`UpdateByQueryRequest` uses the `scroll` parameter to control how long it keeps the "search context" alive. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-scroll] --------------------------------------------------- -<1> set scroll time - -If you provide routing then the routing is copied to the scroll query, limiting the process to the shards that match -that routing value. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> set routing - - -==== Optional arguments -In addition to the options above the following arguments can optionally be also provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the update by query request to be performed as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-refresh] --------------------------------------------------- -<1> Refresh index after calling update by query - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Set indices options - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Update By Query Response - -The returned +{response}+ contains information about the executed operations and -allows to iterate over each result as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Get total time taken -<2> Check if the request timed out -<3> Get total number of docs processed -<4> Number of docs that were updated -<5> Number of docs that were deleted -<6> Number of batches that were executed -<7> Number of skipped docs -<8> Number of version conflicts -<9> Number of times request had to retry bulk index operations -<10> Number of times request had to retry search operations -<11> The total time this request has throttled itself not including the current throttle time if it is currently sleeping -<12> Remaining delay of any current throttle sleep or 0 if not sleeping -<13> Failures during search phase -<14> Failures during bulk index operation diff --git a/docs/java-rest/high-level/document/update.asciidoc b/docs/java-rest/high-level/document/update.asciidoc deleted file mode 100644 index 35300512dfc3..000000000000 --- a/docs/java-rest/high-level/document/update.asciidoc +++ /dev/null @@ -1,237 +0,0 @@ --- -:api: update -:request: UpdateRequest -:response: UpdateResponse --- - -[id="{upid}-{api}"] -=== Update API - -[id="{upid}-{api}-request"] -==== Update Request - -An +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Index -<2> Document id - -The Update API allows to update an existing document by using a script -or by passing a partial document. - -==== Updates with a script -The script can be provided as an inline script: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-with-inline-script] --------------------------------------------------- -<1> Script parameters provided as a `Map` of objects -<2> Create an inline script using the `painless` language and the previous parameters -<3> Sets the script to the update request - -Or as a stored script: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-with-stored-script] --------------------------------------------------- -<1> Reference to a script stored under the name `increment-field` in the `painless` language -<2> Sets the script in the update request - -==== Updates with a partial document -When using updates with a partial document, the partial document will be merged with the -existing document. - -The partial document can be provided in different ways: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-with-doc-as-string] --------------------------------------------------- -<1> Partial document source provided as a `String` in JSON format - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-with-doc-as-map] --------------------------------------------------- -<1> Partial document source provided as a `Map` which gets automatically converted -to JSON format - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-with-doc-as-xcontent] --------------------------------------------------- -<1> Partial document source provided as an `XContentBuilder` object, the Elasticsearch -built-in helpers to generate JSON content - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-shortcut] --------------------------------------------------- -<1> Partial document source provided as `Object` key-pairs, which gets converted to -JSON format - -==== Upserts -If the document does not already exist, it is possible to define some content that -will be inserted as a new document using the `upsert` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-upsert] --------------------------------------------------- -<1> Upsert document source provided as a `String` - -Similarly to the partial document updates, the content of the `upsert` document -can be defined using methods that accept `String`, `Map`, `XContentBuilder` or -`Object` key-pairs. - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Routing value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -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-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-file}[{api}-request-retry] --------------------------------------------------- -<1> How many times to retry the update operation if the document to update has -been changed by another operation between the get and indexing phases of the -update operation - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-no-source] --------------------------------------------------- -<1> Enable source retrieval, disabled by default - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-source-include] --------------------------------------------------- -<1> Configure source inclusion for specific fields - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-source-exclude] --------------------------------------------------- -<1> Configure source exclusion for specific fields - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-cas] --------------------------------------------------- -<1> ifSeqNo -<2> ifPrimaryTerm - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-detect-noop] --------------------------------------------------- -<1> Disable the noop detection - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-scripted-upsert] --------------------------------------------------- -<1> Indicate that the script must run regardless of whether the document exists or not, -ie the script takes care of creating the document if it does not already exist. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-doc-upsert] --------------------------------------------------- -<1> Indicate that the partial document must be used as the upsert document if it -does not exist yet. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-active-shards] --------------------------------------------------- -<1> Sets the number of shard copies that must be active before proceeding with -the update operation. -<2> Number of shard copies provided as a `ActiveShardCount`: can be `ActiveShardCount.ALL`, -`ActiveShardCount.ONE` or `ActiveShardCount.DEFAULT` (default) - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Update Response - -The returned +{response}+ allows to retrieve information about the executed -operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Handle the case where the document was created for the first time (upsert) -<2> Handle the case where the document was updated -<3> Handle the case where the document was deleted -<4> Handle the case where the document was not impacted by the update, -ie no operation (noop) was executed on the document - -When the source retrieval is enabled in the `UpdateRequest` -through the fetchSource method, the response contains the -source of the updated document: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-getresult] --------------------------------------------------- -<1> Retrieve the updated document as a `GetResult` -<2> Retrieve the source of the updated document as a `String` -<3> Retrieve the source of the updated document as a `Map` -<4> Retrieve the source of the updated document as a `byte[]` -<5> Handle the scenario where the source of the document is not present in -the response (this is the case by default) - -It is also possible to check for shard failures: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-failure] --------------------------------------------------- -<1> Handle the situation where number of successful shards is less than -total shards -<2> Handle the potential failures - -When a `UpdateRequest` is performed against a document that does not exist, -the response has `404` status code, an `ElasticsearchException` gets thrown -which needs to be handled as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-docnotfound] --------------------------------------------------- -<1> Handle the exception thrown because the document not exist - -If there is a version conflict, an `ElasticsearchException` will -be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-conflict] --------------------------------------------------- -<1> The raised exception indicates that a version conflict error was returned. diff --git a/docs/java-rest/high-level/enrich/delete_policy.asciidoc b/docs/java-rest/high-level/enrich/delete_policy.asciidoc deleted file mode 100644 index 9bee686cce02..000000000000 --- a/docs/java-rest/high-level/enrich/delete_policy.asciidoc +++ /dev/null @@ -1,31 +0,0 @@ --- -:api: enrich-delete-policy -:request: DeletePolicyRequest -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Delete Policy API - -[id="{upid}-{api}-request"] -==== Request - -The Delete Policy API deletes an enrich policy from Elasticsearch. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete policy request was acknowledged. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether delete policy request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/enrich/execute_policy.asciidoc b/docs/java-rest/high-level/enrich/execute_policy.asciidoc deleted file mode 100644 index 59594f1b741a..000000000000 --- a/docs/java-rest/high-level/enrich/execute_policy.asciidoc +++ /dev/null @@ -1,30 +0,0 @@ --- -:api: enrich-execute-policy -:request: ExecutePolicyRequest -:response: ExecutePolicyResponse --- - -[id="{upid}-{api}"] -=== Execute Policy API - -[id="{upid}-{api}-request"] -==== Request - -The Execute Policy API allows to execute an enrich policy by name. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ includes either the status or task id. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/enrich/get_policy.asciidoc b/docs/java-rest/high-level/enrich/get_policy.asciidoc deleted file mode 100644 index 401a78ccca6d..000000000000 --- a/docs/java-rest/high-level/enrich/get_policy.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ --- -:api: enrich-get-policy -:request: GetPolicyRequest -:response: GetPolicyResponse --- - -[id="{upid}-{api}"] -=== Get Policy API - -[id="{upid}-{api}-request"] -==== Request - -The Get Policy API allows to retrieve enrich policies by name -or all policies if no name is provided. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ includes the requested enrich policy. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The actual enrich policy. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/enrich/put_policy.asciidoc b/docs/java-rest/high-level/enrich/put_policy.asciidoc deleted file mode 100644 index f8e5a4f5ed64..000000000000 --- a/docs/java-rest/high-level/enrich/put_policy.asciidoc +++ /dev/null @@ -1,31 +0,0 @@ --- -:api: enrich-put-policy -:request: PutPolicyRequest -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Create enrich policy API - -[id="{upid}-{api}-request"] -==== Request - -Creates an enrich policy. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The +{response}+ indicates if the request was acknowledged. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether the request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/enrich/stats.asciidoc b/docs/java-rest/high-level/enrich/stats.asciidoc deleted file mode 100644 index 1d4ae50238aa..000000000000 --- a/docs/java-rest/high-level/enrich/stats.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ --- -:api: enrich-stats -:request: StatsRequest -:response: StatsResponse --- - -[id="{upid}-{api}"] -=== Stats API - -[id="{upid}-{api}-request"] -==== Request - -The stats API returns enrich related stats. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ includes enrich related stats. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> List of policies that are currently executing with - additional details. -<2> List of coordinator stats per ingest node. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/execution-no-req.asciidoc b/docs/java-rest/high-level/execution-no-req.asciidoc deleted file mode 100644 index e9a2780d1bc3..000000000000 --- a/docs/java-rest/high-level/execution-no-req.asciidoc +++ /dev/null @@ -1,55 +0,0 @@ -//// -This file is included by high level rest client API documentation pages -where the client method does not use a request object. -For methods with requests, see execution.asciidoc -//// - -[id="{upid}-{api}-sync"] -==== Synchronous execution - -When executing the +{api}+ API in the following manner, the client waits -for the +{response}+ to be returned before continuing with code execution: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute] --------------------------------------------------- - -Synchronous calls may throw an `IOException` in case of either failing to -parse the REST response in the high-level REST client, the request times out -or similar cases where there is no response coming back from the server. - -In cases where the server returns a `4xx` or `5xx` error code, the high-level -client tries to parse the response body error details instead and then throws -a generic `ElasticsearchException` and adds the original `ResponseException` as a -suppressed exception to it. - -[id="{upid}-{api}-async"] -==== Asynchronous execution - -The +{api}+ API can also be called in an asynchronous fashion so that -the client can return directly. Users need to specify how the response or -potential failures will be handled by passing a listener to the -asynchronous {api} method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] --------------------------------------------------- -<1> The `RequestOptions` and `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. Failure scenarios and expected exceptions are the same as in the -synchronous execution case. - -A typical listener for +{api}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the +{api}+ call fails. diff --git a/docs/java-rest/high-level/execution.asciidoc b/docs/java-rest/high-level/execution.asciidoc deleted file mode 100644 index cbc44a24f6c9..000000000000 --- a/docs/java-rest/high-level/execution.asciidoc +++ /dev/null @@ -1,58 +0,0 @@ -//// -This file is included by every high level rest client API documentation page -so we don't have to copy and paste the same asciidoc over and over again. We -*do* have to copy and paste the same Java tests over and over again. For now -this is intentional because it forces us to *write* and execute the tests -which, while a bit ceremonial, does force us to cover these calls in *some* -test. -//// - -[id="{upid}-{api}-sync"] -==== Synchronous execution - -When executing a +{request}+ in the following manner, the client waits -for the +{response}+ to be returned before continuing with code execution: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute] --------------------------------------------------- - -Synchronous calls may throw an `IOException` in case of either failing to -parse the REST response in the high-level REST client, the request times out -or similar cases where there is no response coming back from the server. - -In cases where the server returns a `4xx` or `5xx` error code, the high-level -client tries to parse the response body error details instead and then throws -a generic `ElasticsearchException` and adds the original `ResponseException` as a -suppressed exception to it. - -[id="{upid}-{api}-async"] -==== Asynchronous execution - -Executing a +{request}+ can also be done in an asynchronous fashion so that -the client can return directly. Users need to specify how the response or -potential failures will be handled by passing the request and a listener to the -asynchronous {api} method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] --------------------------------------------------- -<1> The +{request}+ 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. Failure scenarios and expected exceptions are the same as in the -synchronous execution case. - -A typical listener for +{api}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the whole +{request}+ fails. diff --git a/docs/java-rest/high-level/getting-started.asciidoc b/docs/java-rest/high-level/getting-started.asciidoc deleted file mode 100644 index 226bcd0492a0..000000000000 --- a/docs/java-rest/high-level/getting-started.asciidoc +++ /dev/null @@ -1,197 +0,0 @@ -[[java-rest-high-getting-started]] -== 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. - -[[java-rest-high-compatibility]] -=== Compatibility -The Java High Level REST Client requires at least 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. See the <> -if you need to migrate an application from `TransportClient` to the new REST client. - -The High Level Client is guaranteed to be able to communicate with any Elasticsearch -node running on the same major version and greater or equal minor version. It -doesn't need to be in the same minor version as the Elasticsearch nodes it -communicates with, as it is forward compatible meaning that it supports -communicating with later versions of Elasticsearch than the one it was developed for. - -The 6.0 client is able to communicate with any 6.x Elasticsearch node, while the 6.1 -client is for sure able to communicate with 6.1, 6.2 and any later 6.x version, but -there may be incompatibility issues when communicating with a previous Elasticsearch -node version, for instance between 6.1 and 6.0, in case the 6.1 client supports new -request body fields for some APIs that are not known by the 6.0 node(s). - -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 depending on the node that is hit by the request, and newly added APIs will -only be supported by the newer version of the client. The client should always be -updated last, once all of the nodes in the cluster have been upgraded to the new -major version. - -[[java-rest-high-javadoc]] -=== Javadoc - -The javadoc for the REST high level client can be found at {rest-high-level-client-javadoc}/index.html. - -[[java-rest-high-getting-started-maven]] -=== Maven Repository - -The high-level Java REST client is hosted on -https://search.maven.org/search?q=g:org.elasticsearch.client[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. - -If you are looking for a SNAPSHOT version, you should add our snapshot repository to your Maven config: - -["source","xml",subs="attributes"] --------------------------------------------------- - - - es-snapshots - elasticsearch snapshot repo - https://snapshots.elastic.co/maven/ - - --------------------------------------------------- - -or in Gradle: - -["source","groovy",subs="attributes"] --------------------------------------------------- -maven { - url "https://snapshots.elastic.co/maven/" -} --------------------------------------------------- - -[[java-rest-high-getting-started-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"] --------------------------------------------------- - - org.elasticsearch.client - elasticsearch-rest-high-level-client - {version} - --------------------------------------------------- - -[[java-rest-high-getting-started-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:elasticsearch-rest-high-level-client:{version}' -} --------------------------------------------------- - -[[java-rest-high-getting-started-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 `7.0.0-beta1` version which depends on Lucene `8.0.0-snapshot-83f9835`, you must -define the following repository. - -For Maven: - -["source","xml",subs="attributes"] --------------------------------------------------- - - elastic-lucene-snapshots - Elastic Lucene Snapshots - https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/83f9835 - true - false - --------------------------------------------------- - -For Gradle: - -["source","groovy",subs="attributes"] --------------------------------------------------- -maven { - name 'lucene-snapshots' - url 'https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/83f9835' -} --------------------------------------------------- - -[[java-rest-high-getting-started-dependencies]] -=== Dependencies - -The High Level Java REST Client depends on the following artifacts and their -transitive dependencies: - -- org.elasticsearch.client:elasticsearch-rest-client -- org.elasticsearch:elasticsearch - - -[[java-rest-high-getting-started-initialization]] -=== Initialization - -A `RestHighLevelClient` instance needs a <> -to be built as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[rest-high-level-client-init] --------------------------------------------------- - -The high-level client will internally create the low-level client used to -perform requests based on the provided builder. That low-level client -maintains a pool of connections and starts some threads so you should -close the high-level client when you are well and truly done with -it and it will in turn close the internal low-level client to free those -resources. This can be done through the `close`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[rest-high-level-client-close] --------------------------------------------------- - -In the rest of this documentation about the Java High Level Client, the `RestHighLevelClient` instance -will be referenced as `client`. - -[[java-rest-high-getting-started-request-options]] -=== RequestOptions - -All APIs in the `RestHighLevelClient` accept a `RequestOptions` which you can -use to customize the request in ways that won't change how Elasticsearch -executes the request. For example, this is the place where you'd specify a -`NodeSelector` to control which node receives the request. See the -<> for -more examples of customizing the options. - -[[java-rest-high-getting-started-asynchronous-usage]] -=== Asynchronous usage - -All of the methods across the different clients exist in a traditional synchronous and -asynchronous variant. The difference is that the asynchronous ones use asynchronous requests -in the REST Low Level Client. This is useful if you are doing multiple requests or are using e.g. -rx java, Kotlin co-routines, or similar frameworks. - -The asynchronous methods are recognizable by the fact that they have the word "Async" in their name -and return a `Cancellable` instance. The asynchronous methods accept the same request object -as the synchronous variant and accept a generic `ActionListener` where `T` is the return -type of the synchronous method. - -All asynchronous methods return a `Cancellable` object with a `cancel` method that you may call -in case you want to abort the request. Cancelling -no longer needed requests is a good way to avoid putting unnecessary -load on Elasticsearch. - -Using the `Cancellable` instance is optional and you can safely ignore this if you have -no need for this. A use case for this would be using this with e.g. Kotlin's `suspendCancellableCoRoutine`. - diff --git a/docs/java-rest/high-level/graph/explore.asciidoc b/docs/java-rest/high-level/graph/explore.asciidoc deleted file mode 100644 index 1a76d8ec41e3..000000000000 --- a/docs/java-rest/high-level/graph/explore.asciidoc +++ /dev/null @@ -1,54 +0,0 @@ -[role="xpack"] -[[java-rest-high-x-pack-graph-explore]] -=== Graph explore API - -[[java-rest-high-x-pack-graph-explore-execution]] -==== Initial request - -Graph queries are executed using the `explore()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/GraphDocumentationIT.java[x-pack-graph-explore-request] --------------------------------------------------- -<1> In this example we seed the exploration with a query to find messages mentioning the mysterious `projectx` -<2> What we want to discover in these messages are the ids of `participants` in the communications and the md5 hashes -of any attached files. In each case, we want to find people or files that have had at least one document connecting them -to projectx. -<3> The next "hop" in the graph exploration is to find the people who have shared several messages with the people or files -discovered in the previous hop (the projectx conspirators). The `minDocCount` control is used here to ensure the people -discovered have had at least 5 communications with projectx entities. Note we could also supply a "guiding query" here e.g. a -date range to consider only recent communications but we pass null to consider all connections. -<4> Finally we call the graph explore API with the GraphExploreRequest object. - - -==== Response - -Graph responses consist of Vertex and Connection objects (aka "nodes" and "edges" respectively): - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/GraphDocumentationIT.java[x-pack-graph-explore-response] --------------------------------------------------- -<1> Each Vertex is a unique term (a combination of fieldname and term value). The "hopDepth" property tells us at which point in the -requested exploration this term was first discovered. -<2> Each Connection is a pair of Vertex objects and includes a docCount property telling us how many times these two -Vertex terms have been sighted together - - -[[java-rest-high-x-pack-graph-expand-execution]] -==== Expanding a client-side Graph - -Typically once an application has rendered an initial GraphExploreResponse as a collection of vertices and connecting lines (graph visualization toolkits such as D3, sigma.js or Keylines help here) the next step a user may want to do is "expand". This involves finding new vertices that might be connected to the existing ones currently shown. - -To do this we use the same `explore` method but our request contains details about which vertices to expand from and which vertices to avoid re-discovering. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/GraphDocumentationIT.java[x-pack-graph-explore-expand] --------------------------------------------------- -<1> Unlike the initial request we do not need to pass a starting query -<2> In the first hop which represents our "from" vertices we explicitly list the terms that we already have on-screen and want to expand by using the `addInclude` filter. -We can supply a boost for those terms that are considered more important to follow than others but here we select a common value of 1 for all. -<3> When defining the second hop which represents the "to" vertices we hope to discover we explicitly list the terms that we already know about using the `addExclude` filter - diff --git a/docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc deleted file mode 100644 index a68a2d9de5ba..000000000000 --- a/docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: ilm-delete-lifecycle-policy -:request: DeleteLifecyclePolicyRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Lifecycle Policy API - - -[id="{upid}-{api}-request"] -==== Request - -The Delete Lifecycle Policy API allows you to delete an Index Lifecycle -Management Policy from the cluster. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The policy named `my_policy` will be deleted. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete lifecycle policy request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the delete lifecycle policy request was acknowledged. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/delete_snapshot_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/delete_snapshot_lifecycle_policy.asciidoc deleted file mode 100644 index 4079ac3dc084..000000000000 --- a/docs/java-rest/high-level/ilm/delete_snapshot_lifecycle_policy.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: slm-delete-snapshot-lifecycle-policy -:request: DeleteSnapshotLifecyclePolicyRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Snapshot Lifecycle Policy API - - -[id="{upid}-{api}-request"] -==== Request - -The Delete Snapshot Lifecycle Policy API allows you to delete a Snapshot Lifecycle Management Policy -from the cluster. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The policy with the id `policy_id` will be deleted. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete snapshot lifecycle policy request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the delete snapshot lifecycle policy request was acknowledged. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/execute_snapshot_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/execute_snapshot_lifecycle_policy.asciidoc deleted file mode 100644 index b2c36a4e2731..000000000000 --- a/docs/java-rest/high-level/ilm/execute_snapshot_lifecycle_policy.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: slm-execute-snapshot-lifecycle-policy -:request: ExecuteSnapshotLifecyclePolicyRequest -:response: ExecuteSnapshotLifecyclePolicyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Execute Snapshot Lifecycle Policy API - - -[id="{upid}-{api}-request"] -==== Request - -The Execute Snapshot Lifecycle Policy API allows you to execute a Snapshot Lifecycle Management -Policy, taking a snapshot immediately. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The policy id to execute - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the name of the snapshot that was created. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The created snapshot name - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/execute_snapshot_lifecycle_retention.asciidoc b/docs/java-rest/high-level/ilm/execute_snapshot_lifecycle_retention.asciidoc deleted file mode 100644 index 190f7be20921..000000000000 --- a/docs/java-rest/high-level/ilm/execute_snapshot_lifecycle_retention.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: slm-execute-snapshot-lifecycle-retention -:request: ExecuteSnapshotLifecycleRetentionRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Execute Snapshot Lifecycle Retention API - - -[id="{upid}-{api}-request"] -==== Request - -The Execute Snapshot Lifecycle Retention API allows you to execute Snapshot Lifecycle Management -Retention immediately, rather than waiting for its regularly scheduled execution. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains a boolean for whether the request was -acknowledged by the master node. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/explain_lifecycle.asciidoc b/docs/java-rest/high-level/ilm/explain_lifecycle.asciidoc deleted file mode 100644 index b85d482299ad..000000000000 --- a/docs/java-rest/high-level/ilm/explain_lifecycle.asciidoc +++ /dev/null @@ -1,50 +0,0 @@ --- -:api: ilm-explain-lifecycle -:request: ExplainLifecycleRequest -:response: ExplainLifecycleResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Explain Lifecycle API - - -[id="{upid}-{api}-request"] -==== Request - -The Explain Lifecycle API allows you to retrieve information about the execution -of a Lifecycle Policy with respect to one or more indices. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Requests an explanation of policy execution for `my_index` and `other_index` - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains a map of `LifecyclePolicyMetadata`, -accessible by the name of the policy, which contains data about each policy, -as well as the policy definition. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The name of the policy in use for this index, if any. Will be `null` if the -index does not have an associated policy. -<2> Indicates whether this index is being managed by Index Lifecycle Management. -<3> The Phase (`hot`, `warm`, etc.) this index is currently in. Will be `null` if -the index is not managed by Index Lifecycle Management. -<4> The time this index entered this Phase of execution. -<5> The Action (`rollover`, `shrink`, etc.) this index is currently in. Will be `null` if -the index is not managed by Index Lifecycle Management. -<6> The Step this index is currently in. Will be `null` if -the index is not managed by Index Lifecycle Management. -<7> If this index is in the `ERROR` Step, this will indicate which Step failed. -Otherwise, it will be `null`. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/get_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/get_lifecycle_policy.asciidoc deleted file mode 100644 index 506c2c736e54..000000000000 --- a/docs/java-rest/high-level/ilm/get_lifecycle_policy.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: ilm-get-lifecycle-policy -:request: GetLifecyclePolicyRequest -:response: GetLifecyclePolicyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Lifecycle Policy API - - -[id="{upid}-{api}-request"] -==== Request - -The Get Lifecycle Policy API allows you to retrieve the definition of an Index -Lifecycle Management Policy from the cluster. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Gets all policies. -<2> Gets `my_policy` and `other_policy` - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains a map of `LifecyclePolicyMetadata`, -accessible by the name of the policy, which contains data about each policy, -as well as the policy definition. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The retrieved policies are retrieved by name. -<2> The policy definition itself. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/get_snapshot_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/get_snapshot_lifecycle_policy.asciidoc deleted file mode 100644 index da51760961c8..000000000000 --- a/docs/java-rest/high-level/ilm/get_snapshot_lifecycle_policy.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: slm-get-snapshot-lifecycle-policy -:request: GetSnapshotLifecyclePolicyRequest -:response: GetSnapshotLifecyclePolicyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Snapshot Lifecycle Policy API - - -[id="{upid}-{api}-request"] -==== Request - -The Get Snapshot Lifecycle Policy API allows you to retrieve the definition of a Snapshot Lifecycle -Management Policy from the cluster. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Gets all policies. -<2> Gets `policy_id` - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains a map of `SnapshotLifecyclePolicyMetadata`, accessible by the id -of the policy, which contains data about each policy, as well as the policy definition. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The retrieved policies are retrieved by id. -<2> The policy definition itself. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/get_snapshot_lifecycle_stats.asciidoc b/docs/java-rest/high-level/ilm/get_snapshot_lifecycle_stats.asciidoc deleted file mode 100644 index c9ff0a9880cd..000000000000 --- a/docs/java-rest/high-level/ilm/get_snapshot_lifecycle_stats.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: slm-get-snapshot-lifecycle-stats -:request: GetSnapshotLifecycleStatsRequest -:response: GetSnapshotLifecycleStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Snapshot Lifecycle Stats API - - -[id="{upid}-{api}-request"] -==== Request - -The Get Snapshot Lifecycle Stats API allows you to retrieve statistics about snapshots taken or -deleted, as well as retention runs by the snapshot lifecycle service. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains global statistics as well as a map of `SnapshotPolicyStats`, -accessible by the id of the policy, which contains statistics about each policy. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/lifecycle_management_status.asciidoc b/docs/java-rest/high-level/ilm/lifecycle_management_status.asciidoc deleted file mode 100644 index 6bf4344477ea..000000000000 --- a/docs/java-rest/high-level/ilm/lifecycle_management_status.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: ilm-status -:request: LifecycleManagementStatusRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Index Lifecycle Management Status API - - -[id="{upid}-{api}-request"] -==== Request - -The Index Lifecycle Management Status API allows you to retrieve the status -of Index Lifecycle Management - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates the status of Index Lifecycle Management. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The returned status can be `RUNNING`, `STOPPING`, or `STOPPED`. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/put_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/put_lifecycle_policy.asciidoc deleted file mode 100644 index 7cb6f37989a1..000000000000 --- a/docs/java-rest/high-level/ilm/put_lifecycle_policy.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: ilm-put-lifecycle-policy -:request: PutLifecyclePolicyRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create or update lifecycle policy API - - -[id="{upid}-{api}-request"] -==== Request - -Creates or updates an index lifecycle management policy. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Adds a hot phase with a rollover action -<2> Adds a delete phase that will delete in the index 90 days after rollover -<3> Creates the policy with the defined phases and the name `my_policy` - -[id="{upid}-{api}-response"] -==== Response - -The +{response}+ indicates if the request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the request was acknowledged. - -include::../execution.asciidoc[] - diff --git a/docs/java-rest/high-level/ilm/put_snapshot_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/put_snapshot_lifecycle_policy.asciidoc deleted file mode 100644 index d9de7d75934c..000000000000 --- a/docs/java-rest/high-level/ilm/put_snapshot_lifecycle_policy.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ --- -:api: slm-put-snapshot-lifecycle-policy -:request: PutSnapshotLifecyclePolicyRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create or update snapshot lifecycle policy API - - -[id="{upid}-{api}-request"] -==== Request - -Creates or updates a snapshot lifecycle management policy. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The +{response}+ indicates if the request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the request was acknowledged. - -include::../execution.asciidoc[] - diff --git a/docs/java-rest/high-level/ilm/remove_lifecycle_policy_from_index.asciidoc b/docs/java-rest/high-level/ilm/remove_lifecycle_policy_from_index.asciidoc deleted file mode 100644 index 4b12e89d6aa4..000000000000 --- a/docs/java-rest/high-level/ilm/remove_lifecycle_policy_from_index.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: ilm-remove-lifecycle-policy-from-index -:request: RemoveIndexLifecyclePolicyRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Remove Policy from Index API - - -[id="{upid}-{api}-request"] -==== Request - -Removes the assigned lifecycle policy from an index. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> removes the `my_policy` policy from `my_index` - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the request to remove -the lifecycle policy from the index was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not there were any policies failed -to be removed from any indices from the request -<2> A list of index names which are still managed -by their policies. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ilm/retry_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/retry_lifecycle_policy.asciidoc deleted file mode 100644 index 2798b1fecfd3..000000000000 --- a/docs/java-rest/high-level/ilm/retry_lifecycle_policy.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: ilm-retry-lifecycle-policy -:request: RetryLifecyclePolicyRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Retry Lifecycle Policy API - - -[id="{upid}-{api}-request"] -==== Request - -The Retry Lifecycle Policy API allows you to invoke execution of policies -that encountered errors in certain indices. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Retries execution of `my_index`'s policy - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the retry lifecycle policy request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the lifecycle policy retry was acknowledged. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/snapshot_lifecycle_management_status.asciidoc b/docs/java-rest/high-level/ilm/snapshot_lifecycle_management_status.asciidoc deleted file mode 100644 index ae6986711bc3..000000000000 --- a/docs/java-rest/high-level/ilm/snapshot_lifecycle_management_status.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: slm-status -:request: SnapshotLifecycleManagementStatusRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Snapshot Lifecycle Management Status API - - -[id="{upid}-{api}-request"] -==== Request - -The Snapshot Lifecycle Management Status API allows you to retrieve the status -of Snapshot Lifecycle Management - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates the status of Snapshot Lifecycle Management. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The returned status can be `RUNNING`, `STOPPING`, or `STOPPED`. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/start_lifecycle_management.asciidoc b/docs/java-rest/high-level/ilm/start_lifecycle_management.asciidoc deleted file mode 100644 index 20a772596633..000000000000 --- a/docs/java-rest/high-level/ilm/start_lifecycle_management.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: ilm-start-ilm -:request: StartILMRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Start Index Lifecycle Management API - - -[id="{upid}-{api}-request"] -==== Request - -The Start Lifecycle Management API allows you to start Index Lifecycle -Management if it has previously been stopped. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the request to start Index Lifecycle -Management was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the request to start Index Lifecycle Management was -acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ilm/start_snapshot_lifecycle_management.asciidoc b/docs/java-rest/high-level/ilm/start_snapshot_lifecycle_management.asciidoc deleted file mode 100644 index b359f237ea51..000000000000 --- a/docs/java-rest/high-level/ilm/start_snapshot_lifecycle_management.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: slm-start-slm -:request: StartSLMRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Start Snapshot Lifecycle Management API - - -[id="{upid}-{api}-request"] -==== Request - -The Start Snapshot Lifecycle Management API allows you to start Snapshot -Lifecycle Management if it has previously been stopped. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the request to start Snapshot Lifecycle -Management was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the request to start Snapshot Lifecycle Management was -acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ilm/stop_lifecycle_management.asciidoc b/docs/java-rest/high-level/ilm/stop_lifecycle_management.asciidoc deleted file mode 100644 index 04c30e1012f8..000000000000 --- a/docs/java-rest/high-level/ilm/stop_lifecycle_management.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: ilm-stop-ilm -:request: StopILMRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Stop Index Lifecycle Management API - - -[id="{upid}-{api}-request"] -==== Request - -The Stop Lifecycle Management API allows you to stop Index Lifecycle -Management temporarily. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the request to stop Index Lifecycle -Management was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the request to stop Index Lifecycle Management was -acknowledged. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/ilm/stop_snapshot_lifecycle_management.asciidoc b/docs/java-rest/high-level/ilm/stop_snapshot_lifecycle_management.asciidoc deleted file mode 100644 index 3f54341d430a..000000000000 --- a/docs/java-rest/high-level/ilm/stop_snapshot_lifecycle_management.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: slm-stop-slm -:request: StopSLMRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Stop Snapshot Lifecycle Management API - - -[id="{upid}-{api}-request"] -==== Request - -The Stop Snapshot Management API allows you to stop Snapshot Lifecycle -Management temporarily. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the request to stop Snapshot -Lifecycle Management was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the request to stop Snapshot Lifecycle Management was -acknowledged. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/index.asciidoc b/docs/java-rest/high-level/index.asciidoc deleted file mode 100644 index 86d303ce6f08..000000000000 --- a/docs/java-rest/high-level/index.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ -:mainid: java-rest-high - -[id="{mainid}"] -= Java High Level REST Client - -[partintro] --- - -deprecated[7.15.0, The High Level REST Client is deprecated in favour of the {java-api-client}/index.html[Java API Client].] - -The Java High Level REST Client works on top of the Java Low Level REST client. -Its main goal is to expose API specific methods, that accept request objects as -an argument and return response objects, so that request marshalling and -response un-marshalling is handled by the client itself. - -Each API can be called synchronously or asynchronously. The synchronous -methods return a response object, while the asynchronous methods, whose names -end with the `async` suffix, require a listener argument that is notified -(on the thread pool managed by the low level client) once a response or an -error is received. - -The Java High Level REST Client depends on the Elasticsearch core project. -It accepts the same request arguments as the `TransportClient` and returns -the same response objects. - --- - -:doc-tests: {elasticsearch-root}/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation -:hlrc-tests: {elasticsearch-root}/client/rest-high-level/src/test/java/org/elasticsearch/client - -include::getting-started.asciidoc[] -include::supported-apis.asciidoc[] -include::java-builders.asciidoc[] -include::migration.asciidoc[] -include::../license.asciidoc[] - -:doc-tests!: -:mainid!: diff --git a/docs/java-rest/high-level/indices/analyze.asciidoc b/docs/java-rest/high-level/indices/analyze.asciidoc deleted file mode 100644 index de3ac07542f7..000000000000 --- a/docs/java-rest/high-level/indices/analyze.asciidoc +++ /dev/null @@ -1,97 +0,0 @@ --- -:api: analyze -:request: AnalyzeRequest -:response: AnalyzeResponse --- - -[id="{upid}-{api}"] -=== Analyze API - -[id="{upid}-{api}-request"] -==== Analyze Request - -An +{request}+ contains the text to analyze, and one of several options to -specify how the analysis should be performed. - -The simplest version uses a built-in analyzer: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-builtin-request] ---------------------------------------------------- -<1> A built-in analyzer -<2> The text to include. Multiple strings are treated as a multi-valued field - -You can configure a custom analyzer: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-custom-request] ---------------------------------------------------- -<1> Configuration for a custom tokenfilter -<2> Configure the tokenizer -<3> Configure char filters -<4> Add a built-in tokenfilter -<5> Add the custom tokenfilter - -You can also build a custom normalizer, by including only charfilters and -tokenfilters: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-custom-normalizer-request] ---------------------------------------------------- - -You can analyze text using an analyzer defined in an existing index: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-index-request] ---------------------------------------------------- -<1> The index containing the mappings -<2> The analyzer defined on this index to use - -Or you can use a normalizer: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-index-normalizer-request] ---------------------------------------------------- -<1> The index containing the mappings -<2> The normalizer defined on this index to use - -You can analyze text using the mappings for a particular field in an index: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-field-request] ---------------------------------------------------- - -==== Optional arguments -The following arguments can also optionally be provided: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-explain] ---------------------------------------------------- -<1> Setting `explain` to true will add further details to the response -<2> Setting `attributes` allows you to return only token attributes that you are -interested in - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Analyze Response - -The returned +{response}+ allows you to retrieve details of the analysis as -follows: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-tokens] ---------------------------------------------------- -<1> `AnalyzeToken` holds information about the individual tokens produced by analysis - -If `explain` was set to `true`, then information is instead returned from the `detail()` -method: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-detail] ---------------------------------------------------- -<1> `DetailAnalyzeResponse` holds more detailed information about tokens produced by -the various substeps in the analysis chain. \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/clear_cache.asciidoc b/docs/java-rest/high-level/indices/clear_cache.asciidoc deleted file mode 100644 index bbd2389ee6e2..000000000000 --- a/docs/java-rest/high-level/indices/clear_cache.asciidoc +++ /dev/null @@ -1,80 +0,0 @@ --- -:api: clear-cache -:request: ClearIndicesCacheRequest -:response: ClearIndicesCacheResponse --- - -[id="{upid}-{api}"] -=== Clear Cache API - -[id="{upid}-{api}-request"] -==== Clear Cache Request - -A +{request}+ can be applied to one or more indices, or even on -`_all` the indices: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Clears the cache of one index -<2> Clears the cache of multiple indices -<3> Clears the cache of all the indices - -==== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-query] --------------------------------------------------- -<1> Set the `query` flag to `true` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-fielddata] --------------------------------------------------- -<1> Set the `fielddata` flag to `true` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-request] --------------------------------------------------- -<1> Set the `request` flag to `true` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-fields] --------------------------------------------------- -<1> Set the `fields` parameter - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Clear Cache Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Total number of shards hit by the clear cache request -<2> Number of shards where the clear cache has succeeded -<3> Number of shards where the clear cache has failed -<4> A list of failures if the operation failed on one or more shards - -By default, if the indices were not found, an `ElasticsearchException` will be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-notfound] --------------------------------------------------- -<1> Do something if the indices to be cleared were not found \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/clone_index.asciidoc b/docs/java-rest/high-level/indices/clone_index.asciidoc deleted file mode 100644 index 7448b8a402bb..000000000000 --- a/docs/java-rest/high-level/indices/clone_index.asciidoc +++ /dev/null @@ -1,80 +0,0 @@ --- -:api: clone-index -:request: ResizeRequest -:response: ResizeResponse --- - -[id="{upid}-{api}"] -=== Clone Index API - -[id="{upid}-{api}-request"] -==== Resize Request - -The Clone Index API requires a +{request}+ instance. -A +{request}+ requires two string arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The target index (first argument) to clone the source index (second argument) into -<2> The resize type needs to be set to `CLONE` - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the clone index API -returns a response, as an `int` -<2> The number of active shard copies to wait for before the clone index API -returns a response, as an `ActiveShardCount` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-settings] --------------------------------------------------- -<1> The settings to apply to the target index, which optionally include the -number of shards to create for it - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aliases] --------------------------------------------------- -<1> The aliases to associate the target index with - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Clone Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out - - diff --git a/docs/java-rest/high-level/indices/close_index.asciidoc b/docs/java-rest/high-level/indices/close_index.asciidoc deleted file mode 100644 index 6d6fb917c794..000000000000 --- a/docs/java-rest/high-level/indices/close_index.asciidoc +++ /dev/null @@ -1,56 +0,0 @@ --- -:api: close-index -:request: CloseIndexRequest -:response: CloseIndexResponse --- - -[id="{upid}-{api}"] -=== Close Index API - -[id="{upid}-{api}-request"] -==== Close Index Request - -A +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to close - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is closed -as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Close Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/indices/create_index.asciidoc b/docs/java-rest/high-level/indices/create_index.asciidoc deleted file mode 100644 index 004279ba2a89..000000000000 --- a/docs/java-rest/high-level/indices/create_index.asciidoc +++ /dev/null @@ -1,116 +0,0 @@ --- -:api: create-index -:request: CreateIndexRequest -:response: CreateIndexResponse --- - -[id="{upid}-{api}"] -=== Create Index API - -[id="{upid}-{api}-request"] -==== Create Index Request - -A +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to create - -==== Index settings -Each index created can have specific settings associated with it. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-settings] --------------------------------------------------- -<1> Settings for this index - -[[java-rest-high-create-index-request-mappings]] -==== Index mappings -An index may be created with mappings for its document types - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-mappings] --------------------------------------------------- -<1> The type to define -<2> The mapping for this type, provided as a JSON string - -The mapping source can be provided in different ways in addition to the -`String` example shown above: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-mappings-map] --------------------------------------------------- -<1> Mapping source provided as a `Map` which gets automatically converted -to JSON format - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-mappings-xcontent] --------------------------------------------------- -<1> Mapping source provided as an `XContentBuilder` object, the Elasticsearch -built-in helpers to generate JSON content - -==== Index aliases -Aliases can be set at index creation time - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aliases] --------------------------------------------------- -<1> The alias to define - -==== Providing the whole source - -The whole source including all of its sections (mappings, settings and aliases) -can also be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-whole-source] --------------------------------------------------- -<1> The source provided as a JSON string. It can also be provided as a `Map` -or an `XContentBuilder`. - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the create index API returns a -response, as an `int` -<2> The number of active shard copies to wait for before the create index API returns a -response, as an `ActiveShardCount` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Create Index Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for each shard in the index before timing out diff --git a/docs/java-rest/high-level/indices/delete_alias.asciidoc b/docs/java-rest/high-level/indices/delete_alias.asciidoc deleted file mode 100644 index ec451c5bc5c2..000000000000 --- a/docs/java-rest/high-level/indices/delete_alias.asciidoc +++ /dev/null @@ -1,49 +0,0 @@ --- -:api: delete-alias -:request: DeleteAliasRequest -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Delete Alias API - -[id="{upid}-{api}-request"] -==== Delete Alias Request - -An +{request}+ requires an `index` and an `alias` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -[id="{upid}-{api}-response"] -==== Delete Alias Response - -The returned +{response}+ indicates if the request to delete the alias -was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the request to delete the alias was -acknowledged. - -include::../execution.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/delete_index.asciidoc b/docs/java-rest/high-level/indices/delete_index.asciidoc deleted file mode 100644 index c96885790b37..000000000000 --- a/docs/java-rest/high-level/indices/delete_index.asciidoc +++ /dev/null @@ -1,65 +0,0 @@ --- -:api: delete-index -:request: DeleteIndexRequest -:response: DeleteIndexResponse --- - -[id="{upid}-{api}"] -=== Delete Index API - -[id="{upid}-{api}-request"] -==== Delete Index Request - -A +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Index - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index deletion as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the index deletion as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete Index Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request - -If the index was not found, an `ElasticsearchException` will be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-notfound] --------------------------------------------------- -<1> Do something if the index to be deleted was not found diff --git a/docs/java-rest/high-level/indices/delete_index_template.asciidoc b/docs/java-rest/high-level/indices/delete_index_template.asciidoc deleted file mode 100644 index 0f28e0d80eb9..000000000000 --- a/docs/java-rest/high-level/indices/delete_index_template.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ --- -:api: delete-index-template-v2 -:request: DeleteIndexTemplateV2Request -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Delete Composable Index Template API - -[id="{upid}-{api}-request"] -==== Request - -The Delete Composable Index Template API allows you to delete an index template. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of an index template to delete. - -=== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete template request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the delete template request was acknowledged. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/indices/delete_template.asciidoc b/docs/java-rest/high-level/indices/delete_template.asciidoc deleted file mode 100644 index 4ca88f1bfc12..000000000000 --- a/docs/java-rest/high-level/indices/delete_template.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ --- -:api: delete-template -:request: DeleteIndexTemplateRequest -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Delete Template API - -[id="{upid}-{api}-request"] -==== Request - -The Delete Template API allows you to delete an index template. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of an index template to delete. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete template request was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the delete template request was acknowledged. - -include::../execution.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/exists_alias.asciidoc b/docs/java-rest/high-level/indices/exists_alias.asciidoc deleted file mode 100644 index baaf7585683a..000000000000 --- a/docs/java-rest/high-level/indices/exists_alias.asciidoc +++ /dev/null @@ -1,58 +0,0 @@ --- -:api: exists-alias -:request: GetAliasesRequest -:response: Boolean --- - -[id="{upid}-{api}"] -=== Exists Alias API - -[id="{upid}-{api}-request"] -==== Exists Alias Request - -The Exists Alias API uses +{request}+ as its request object. -One or more aliases can be optionally provided either at construction -time or later on through the relevant setter method. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-alias] --------------------------------------------------- -<1> One or more aliases to look for - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indices] --------------------------------------------------- -<1> The index or indices that the alias is associated with - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-local] --------------------------------------------------- -<1> The `local` flag (defaults to `false`) controls whether the aliases need -to be looked up in the local cluster state or in the cluster state held by -the elected master node - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Exists Alias Response - -The Exists Alias API returns a +{response}+ that indicates whether the provided -alias (or aliases) was found or not. diff --git a/docs/java-rest/high-level/indices/flush.asciidoc b/docs/java-rest/high-level/indices/flush.asciidoc deleted file mode 100644 index 8bcb203186f9..000000000000 --- a/docs/java-rest/high-level/indices/flush.asciidoc +++ /dev/null @@ -1,67 +0,0 @@ --- -:api: flush -:request: FlushRequest -:response: FlushResponse --- - -[id="{upid}-{api}"] -=== Flush API - -[id="{upid}-{api}-request"] -==== Flush Request - -A +{request}+ can be applied to one or more indices, or even on `_all` the indices: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Flush one index -<2> Flush multiple indices -<3> Flush all the indices - -==== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait] --------------------------------------------------- -<1> Set the `wait_if_ongoing` flag to `true` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-force] --------------------------------------------------- -<1> Set the `force` flag to `true` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Flush Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Total number of shards hit by the flush request -<2> Number of shards where the flush has succeeded -<3> Number of shards where the flush has failed -<4> A list of failures if the operation failed on one or more shards - -By default, if the indices were not found, an `ElasticsearchException` will be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-notfound] --------------------------------------------------- -<1> Do something if the indices to be flushed were not found \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/force_merge.asciidoc b/docs/java-rest/high-level/indices/force_merge.asciidoc deleted file mode 100644 index 8126ad597f99..000000000000 --- a/docs/java-rest/high-level/indices/force_merge.asciidoc +++ /dev/null @@ -1,73 +0,0 @@ --- -:api: force-merge -:request: ForceMergeRequest -:response: ForceMergeResponse --- - -[id="{upid}-{api}"] -=== Force Merge API - -[id="{upid}-{api}-request"] -==== Force merge Request - -A +{request}+ can be applied to one or more indices, or even on `_all` the indices: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Force merge one index -<2> Force merge multiple indices -<3> Force merge all the indices - -==== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-segments-num] --------------------------------------------------- -<1> Set `max_num_segments` to control the number of segments to merge down to. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-only-expunge-deletes] --------------------------------------------------- -<1> Set the `only_expunge_deletes` flag to `true` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-flush] --------------------------------------------------- -<1> Set the `flush` flag to `true` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Force Merge Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Total number of shards hit by the force merge request -<2> Number of shards where the force merge has succeeded -<3> Number of shards where the force merge has failed -<4> A list of failures if the operation failed on one or more shards - -By default, if the indices were not found, an `ElasticsearchException` will be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-notfound] --------------------------------------------------- -<1> Do something if the indices to be force merged were not found \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/freeze_index.asciidoc b/docs/java-rest/high-level/indices/freeze_index.asciidoc deleted file mode 100644 index c3773aee80c3..000000000000 --- a/docs/java-rest/high-level/indices/freeze_index.asciidoc +++ /dev/null @@ -1,65 +0,0 @@ --- -:api: freeze-index -:request: FreezeIndexRequest -:response: FreezeIndexResponse --- - -[id="{upid}-{api}"] -=== Freeze Index API - -[id="{upid}-{api}-request"] -==== Freeze Index Request - -An +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to freeze - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is frozen -as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the freeze index API -returns a response, as an `ActiveShardCount` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Freeze Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out diff --git a/docs/java-rest/high-level/indices/get_alias.asciidoc b/docs/java-rest/high-level/indices/get_alias.asciidoc deleted file mode 100644 index c51f9fe5b95b..000000000000 --- a/docs/java-rest/high-level/indices/get_alias.asciidoc +++ /dev/null @@ -1,85 +0,0 @@ --- -:api: get-alias -:request: GetAliasesRequest -:response: GetAliasesResponse --- - -[id="{upid}-{api}"] -=== Get Alias API - -[id="{upid}-{api}-request"] -==== Get Alias Request - -The Get Alias API uses +{request}+ as its request object. -One or more aliases can be optionally provided either at construction -time or later on through the relevant setter method. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-alias] --------------------------------------------------- -<1> One or more aliases to retrieve - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indices] --------------------------------------------------- -<1> The index or indices that the alias is associated with - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded when looking for aliases that belong to -specified indices. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-local] --------------------------------------------------- -<1> The `local` flag (defaults to `false`) controls whether the aliases need -to be looked up in the local cluster state or in the cluster state held by -the elected master node - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Alias Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Retrieves a map of indices and their aliases - -+{response}+ class contains information about errors if they occurred. -This info could be in fields `error` or `exception` depends on a case. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-error] --------------------------------------------------- -<1> Client sets status to `NOT_FOUND` if at least one item of specified -indices or aliases is not found. Otherwise it is `OK`. - -<2> If at least one item of specified indices isn't exist client sets -`ElasticsearchException` and returns empty result. - -<3> If at least one item of specified aliases ins't exist client puts -error description in `error` field and returns partial result if any -of other patterns match. - -If user specified indices or aliases as regular expressions -and nothing was found client returns `OK` status and no errors. diff --git a/docs/java-rest/high-level/indices/get_field_mappings.asciidoc b/docs/java-rest/high-level/indices/get_field_mappings.asciidoc deleted file mode 100644 index d8124cf65197..000000000000 --- a/docs/java-rest/high-level/indices/get_field_mappings.asciidoc +++ /dev/null @@ -1,51 +0,0 @@ --- -:api: get-field-mappings -:request: GetFieldMappingsRequest -:response: GetFieldMappingsResponse --- - -[id="{upid}-{api}"] -=== Get Field Mappings API - -[id="{upid}-{api}-request"] -==== Get Field Mappings Request - -A +{request}+ can have an optional list of indices, optional list of types and the list of fields: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> An empty request -<2> Setting the indices to fetch mapping for -<3> The fields to be returned - -==== Optional arguments -The following arguments can also optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] - -==== Get Field Mappings Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Returning all requested indices fields' mappings -<2> Retrieving the mappings for a particular index -<3> Getting the mappings metadata for the `message` field -<4> Getting the full name of the field -<5> Getting the mapping source of the field - diff --git a/docs/java-rest/high-level/indices/get_index.asciidoc b/docs/java-rest/high-level/indices/get_index.asciidoc deleted file mode 100644 index 8698bff7d7c6..000000000000 --- a/docs/java-rest/high-level/indices/get_index.asciidoc +++ /dev/null @@ -1,60 +0,0 @@ --- -:api: get-index -:request: GetIndexRequest -:response: GetIndexResponse --- - -[id="{upid}-{api}"] -[[java-rest-high-get-index]] -=== Get Index API - -[id="{upid}-{api}-request"] -==== Get Index Request - -A +{request}+ requires one or more `index` arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index whose information we want to retrieve - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-includeDefaults] --------------------------------------------------- -<1> If true, defaults will be returned for settings not explicitly set on the index - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Retrieve a Map of different types to `MappingMetadata` for `index`. -<2> Retrieve a Map for the properties for document type `doc`. -<3> Get the list of aliases for `index`. -<4> Get the value for the setting string `index.number_of_shards` for `index`. If the setting was not explicitly -specified but was part of the default settings (and includeDefault was `true`) then the default setting would be -retrieved. -<5> Retrieve all settings for `index`. -<6> The `Settings` objects gives more flexibility. Here it is used to extract the setting `index.number_of_shards` as an -integer. -<7> Get the default setting `index.refresh_interval` (if `includeDefault` was set to `true`). If `includeDefault` was set -to `false`, `getIndexResponse.defaultSettings()` will return an empty map. \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/get_index_template.asciidoc b/docs/java-rest/high-level/indices/get_index_template.asciidoc deleted file mode 100644 index 3ddbfc7e8c32..000000000000 --- a/docs/java-rest/high-level/indices/get_index_template.asciidoc +++ /dev/null @@ -1,43 +0,0 @@ --- -:api: get-index-templates-v2 -:request: GetIndexTemplateV2Request -:response: GetIndexTemplatesV2Response --- - -[id="{upid}-{api}"] -=== Get Composable Index Templates API - -The Get Index Templates API allows to retrieve information about one or more index templates. - -[id="{upid}-{api}-request"] -==== Get Composable Index Templates Request - -A +{request}+ specifies one, or a wildcard expression of index template names -to get. To return all index templates, omit the name altogether or use a value of `*`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> A single index template name -<2> An index template name using wildcard - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Templates Response - -The returned +{response}+ consists a map of index template names and their corresponding configurations. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> A map of matching index templates names and the corresponding configurations diff --git a/docs/java-rest/high-level/indices/get_mappings.asciidoc b/docs/java-rest/high-level/indices/get_mappings.asciidoc deleted file mode 100644 index 516e0633f83c..000000000000 --- a/docs/java-rest/high-level/indices/get_mappings.asciidoc +++ /dev/null @@ -1,51 +0,0 @@ --- -:api: get-mappings -:request: GetMappingsRequest -:response: GetMappingsResponse --- - -[id="{upid}-{api}"] -=== Get Mappings API - -[id="{upid}-{api}-request"] -==== Get Mappings Request - -A +{request}+ can have an optional list of indices: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> An empty request that will return all indices -<2> Setting the indices to fetch mapping for - -==== Optional arguments -The following arguments can also optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Options for expanding indices names - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Mappings Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Returning all indices' mappings -<2> Retrieving the mappings for a particular index -<3> Getting the mappings as a Java Map diff --git a/docs/java-rest/high-level/indices/get_settings.asciidoc b/docs/java-rest/high-level/indices/get_settings.asciidoc deleted file mode 100644 index 9eb7ec5099ea..000000000000 --- a/docs/java-rest/high-level/indices/get_settings.asciidoc +++ /dev/null @@ -1,67 +0,0 @@ --- -:api: get-settings -:request: GetSettingsRequest -:response: GetSettingsResponse --- - -[id="{upid}-{api}"] -=== Get Settings API - -[id="{upid}-{api}-request"] -==== Get Settings Request - -A +{request}+ requires one or more `index` arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index whose settings we should retrieve - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-names] --------------------------------------------------- -<1> One or more settings that be the only settings retrieved. If unset, all settings will be retrieved - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-include-defaults] --------------------------------------------------- -<1> If true, defaults will be returned for settings not explicitly set on the index - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Settings Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> We can retrieve the setting value for a particular index directly from the response as a string -<2> We can also retrieve the Settings object for a particular index for further examination -<3> The returned Settings object provides convenience methods for non String types - -If the `includeDefaults` flag was set to true in the +{request}+ the -behavior of +{response}+ will differ somewhat. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-defaults-response] --------------------------------------------------- -<1> Individual default setting values may be retrieved directly from the +{response}+ -<2> We may retrieve a Settings object for an index that contains those settings with default values diff --git a/docs/java-rest/high-level/indices/get_templates.asciidoc b/docs/java-rest/high-level/indices/get_templates.asciidoc deleted file mode 100644 index 07460a64a646..000000000000 --- a/docs/java-rest/high-level/indices/get_templates.asciidoc +++ /dev/null @@ -1,43 +0,0 @@ --- -:api: get-templates -:request: GetIndexTemplatesRequest -:response: GetIndexTemplatesResponse --- - -[id="{upid}-{api}"] -=== Get Templates API - -The Get Templates API allows to retrieve a list of index templates by name. - -[id="{upid}-{api}-request"] -==== Get Index Templates Request - -A +{request}+ specifies one or several names of the index templates to get. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> A single index template name -<2> Multiple index template names -<3> An index template name using wildcard - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Templates Response - -The returned +{response}+ consists a list of matching index templates. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> A list of matching index templates \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/indices_exists.asciidoc b/docs/java-rest/high-level/indices/indices_exists.asciidoc deleted file mode 100644 index a830ab54d3b3..000000000000 --- a/docs/java-rest/high-level/indices/indices_exists.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: indices-exists -:request: GetIndexRequest -:response: boolean --- - -[id="{upid}-{api}"] -=== Index Exists API - -[id="{upid}-{api}-request"] -==== Index Exists Request - -The high-level REST client uses a +{request}+ for Index Exists API. The index name (or indices' names) are required. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Index - -[[java-rest-high-indices-exists-optional-args]] -==== Optional arguments -Index exists API also accepts following optional arguments, through a +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-optionals] --------------------------------------------------- -<1> Whether to return local information or retrieve the state from master node -<2> Return result in a format suitable for humans -<3> Whether to return all default setting for each of the indices -<4> Controls how unavailable indices are resolved and how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response -The response is a +{response}+ value, indicating whether the index (or indices) exist. diff --git a/docs/java-rest/high-level/indices/open_index.asciidoc b/docs/java-rest/high-level/indices/open_index.asciidoc deleted file mode 100644 index 7d0b042ffa07..000000000000 --- a/docs/java-rest/high-level/indices/open_index.asciidoc +++ /dev/null @@ -1,70 +0,0 @@ --- -:api: open-index -:request: OpenIndexRequest -:response: OpenIndexResponse --- - -[id="{upid}-{api}"] -=== Open Index API - -[id="{upid}-{api}-request"] -==== Open Index Request - -An +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to open - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the open index API -returns a response, as an `int` -<2> The number of active shard copies to wait for before the open index API -returns a response, as an `ActiveShardCount` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Open Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out diff --git a/docs/java-rest/high-level/indices/put_index_template.asciidoc b/docs/java-rest/high-level/indices/put_index_template.asciidoc deleted file mode 100644 index 8679c35ccfa3..000000000000 --- a/docs/java-rest/high-level/indices/put_index_template.asciidoc +++ /dev/null @@ -1,120 +0,0 @@ --- -:api: put-index-template-v2 -:request: PutIndexTemplateV2Request -:response: AcknowledgedResponse --- - -[id="{upid}-{api}"] -=== Create or update composable index template API - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ specifies the `name` of a template and the index template configuration -which consists of the `patterns` that control whether the template should be applied -to the new index, and the optional mappings, settings and aliases configuration. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the template -<2> The index template configuration that specifies the index name patterns this template will match - -==== Settings -The settings of the template will be applied to the new index whose name matches the -template's patterns. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-settings] --------------------------------------------------- -<1> Settings for this template -<2> Configure the settings on the template building block -<3> Create the IndexTemplateV2 object that configures the index template to apply the defined template to indices matching the patterns - -==== Mappings -The mapping of the template will be applied to the new index whose name matches the -template's patterns. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-mappings-json] --------------------------------------------------- -<1> The mapping, provided as a JSON string -<2> Configure the mapping on the template building block - -==== Aliases -The aliases of the template will define aliasing to the index whose name matches the -template's patterns. A placeholder `{index}` can be used in an alias of a template. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aliases] --------------------------------------------------- -<1> The alias to define -<2> The alias to define with placeholder -<3> Configure the aliases on the template building block - -==== Component templates -Component templates can be used as building blocks for specifying mappings, settings or aliases -configurations, but they don't apply to indices themselves. To be applied to an index, the -component templates must be specified in the `componentTemplates` list of the `IndexTemplateV2` -index template definition object. The order in which they are specified in the list is the order -in which the component templates are applied. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-component-template] --------------------------------------------------- -<1> The component template used by this index template - -==== Priority -In case multiple templates match an index, the priority of matching templates determines -the index template which will be applied. -Index templates with higher priority "win" over index templates with lower priority. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-priority] --------------------------------------------------- -<1> The priority of the template - -==== Version -A template can optionally specify a version number which can be used to simplify template -management by external systems. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-version] --------------------------------------------------- -<1> The version number of the template - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-create] --------------------------------------------------- -<1> To force to only create a new template; do not overwrite the existing template - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/indices/put_mapping.asciidoc b/docs/java-rest/high-level/indices/put_mapping.asciidoc deleted file mode 100644 index 1e846a3fb05e..000000000000 --- a/docs/java-rest/high-level/indices/put_mapping.asciidoc +++ /dev/null @@ -1,78 +0,0 @@ --- -:api: put-mapping -:request: PutMappingRequest -:response: PutMappingResponse --- - -[id="{upid}-{api}"] -=== Update mapping API - -Adds new fields to an existing data stream or index. You can also use the API to -change the search settings of existing fields. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to add the mapping to - -==== Mapping source -A description of the fields to create on the mapping; if not defined, the mapping will default to empty. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-source] --------------------------------------------------- -<1> Mapping source provided as a `String` - -==== Providing the mapping source -The mapping source can be provided in different ways in addition to -the `String` example shown above: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-map] --------------------------------------------------- -<1> Mapping source provided as a `Map` which gets automatically converted -to JSON format - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-xcontent] --------------------------------------------------- -<1> Mapping source provided as an `XContentBuilder` object, the Elasticsearch -built-in helpers to generate JSON content - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/indices/put_settings.asciidoc b/docs/java-rest/high-level/indices/put_settings.asciidoc deleted file mode 100644 index f798482bfdd4..000000000000 --- a/docs/java-rest/high-level/indices/put_settings.asciidoc +++ /dev/null @@ -1,106 +0,0 @@ --- -:api: indices-put-settings -:request: UpdateSettingsRequest -:response: UpdateSettingsResponse --- - -[id="{upid}-{api}"] -=== Update Indices Settings API - -The Update Indices Settings API allows to change specific index level settings. - -[id="{upid}-{api}-request"] -==== Update Indices Settings Request - -An +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Update settings for one index -<2> Update settings for multiple indices -<3> Update settings for all indices - -==== Indices Settings -At least one setting to be updated must be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-create-settings] --------------------------------------------------- -<1> Sets the index settings to be applied - -==== Providing the Settings -The settings to be applied can be provided in different ways: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-create-settings] --------------------------------------------------- -<1> Creates a setting as `Settings` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-settings-builder] --------------------------------------------------- -<1> Settings provided as `Settings.Builder` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-settings-source] --------------------------------------------------- -<1> Settings provided as `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-settings-map] --------------------------------------------------- -<1> Settings provided as a `Map` - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-preserveExisting] --------------------------------------------------- -<1> Whether to update existing settings. If set to `true` existing settings -on an index remain unchanged, the default is `false` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the new setting -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the new setting -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Update Indices Settings Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/put_template.asciidoc b/docs/java-rest/high-level/indices/put_template.asciidoc deleted file mode 100644 index f10ddd0b543c..000000000000 --- a/docs/java-rest/high-level/indices/put_template.asciidoc +++ /dev/null @@ -1,132 +0,0 @@ --- -:api: put-template -:request: PutIndexTemplateRequest -:response: PutIndexTemplateResponse --- - -[id="{upid}-{api}"] -=== Create or update index template API - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ specifies the `name` of a template and `patterns` -which controls whether the template should be applied to the new index. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the template -<2> The patterns of the template - -==== Settings -The settings of the template will be applied to the new index whose name matches the -template's patterns. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-settings] --------------------------------------------------- -<1> Settings for this template - -[[java-rest-high-put-template-request-mappings]] -==== Mappings -The mapping of the template will be applied to the new index whose name matches the -template's patterns. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-mappings-json] --------------------------------------------------- -<1> The mapping, provided as a JSON string - -The mapping source can be provided in different ways in addition to the -`String` example shown above: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-mappings-map] --------------------------------------------------- -<1> Mapping source provided as a `Map` which gets automatically converted -to JSON format - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-mappings-xcontent] --------------------------------------------------- -<1> Mapping source provided as an `XContentBuilder` object, the Elasticsearch -built-in helpers to generate JSON content - -==== Aliases -The aliases of the template will define aliasing to the index whose name matches the -template's patterns. A placeholder `{index}` can be used in an alias of a template. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aliases] --------------------------------------------------- -<1> The alias to define -<2> The alias to define with placeholder - -==== Order -In case multiple templates match an index, the orders of matching templates determine -the sequence that settings, mappings, and alias of each matching template is applied. -Templates with lower orders are applied first, and higher orders override them. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-order] --------------------------------------------------- -<1> The order of the template - -==== Version -A template can optionally specify a version number which can be used to simplify template -management by external systems. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-version] --------------------------------------------------- -<1> The version number of the template - -==== Providing the whole source -The whole source including all of its sections (mappings, settings and aliases) -can also be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-whole-source] --------------------------------------------------- -<1> The source provided as a JSON string. It can also be provided as a `Map` -or an `XContentBuilder`. - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-create] --------------------------------------------------- -<1> To force to only create a new template; do not overwrite the existing template - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/indices/refresh.asciidoc b/docs/java-rest/high-level/indices/refresh.asciidoc deleted file mode 100644 index a8f812c3ed32..000000000000 --- a/docs/java-rest/high-level/indices/refresh.asciidoc +++ /dev/null @@ -1,55 +0,0 @@ --- -:api: refresh -:request: RefreshRequest -:response: RefreshResponse --- - -[id="{upid}-{api}"] -=== Refresh API - -[id="{upid}-{api}-request"] -==== Refresh Request - -A +{request}+ can be applied to one or more indices, or even on `_all` the indices: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Refresh one index -<2> Refresh multiple indices -<3> Refresh all the indices - -==== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Refresh Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Total number of shards hit by the refresh request -<2> Number of shards where the refresh has succeeded -<3> Number of shards where the refresh has failed -<4> A list of failures if the operation failed on one or more shards - -By default, if the indices were not found, an `ElasticsearchException` will be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-notfound] --------------------------------------------------- -<1> Do something if the indices to be refreshed were not found \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/reload_analyzers.asciidoc b/docs/java-rest/high-level/indices/reload_analyzers.asciidoc deleted file mode 100644 index 29db206bf140..000000000000 --- a/docs/java-rest/high-level/indices/reload_analyzers.asciidoc +++ /dev/null @@ -1,50 +0,0 @@ --- -:api: reload-analyzers -:request: ReloadAnalyzersRequest -:response: ReloadAnalyzersResponse --- - -[id="{upid}-{api}"] -=== Reload Search Analyzers API - -[id="{upid}-{api}-request"] -==== Reload Search Analyzers Request - -An +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to reload - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Reload Search Analyzers Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Shard statistics. Note that reloading does not happen on each shard of an -index, but once on each node the index has shards on. The reported shard count -can therefore differ from the number of index shards -<2> Reloading details of all indices the request was executed on -<3> Details can be retrieved by index name -<4> The reloaded index name -<5> The nodes the index was reloaded on -<6> The analyzer names that were reloaded diff --git a/docs/java-rest/high-level/indices/rollover.asciidoc b/docs/java-rest/high-level/indices/rollover.asciidoc deleted file mode 100644 index e1e3298544b2..000000000000 --- a/docs/java-rest/high-level/indices/rollover.asciidoc +++ /dev/null @@ -1,98 +0,0 @@ --- -:api: rollover-index -:request: RolloverRequest -:response: RolloverResponse --- - -[id="{upid}-{api}"] -=== Rollover Index API - -[id="{upid}-{api}-request"] -==== Rollover Request - -The Rollover Index API requires a +{request}+ instance. -A +{request}+ requires two string arguments at construction time, and -one or more conditions that determine when the index has to be rolled over: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The alias (first argument) that points to the index to rollover, and -the name of the new index in case the rollover operation is performed. -The new index argument is optional, and can be set to null -<2> Condition on the age of the index -<3> Condition on the number of documents in the index -<4> Condition on the size of the index -<5> Condition on the size of the largest primary shard of the index - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-dryRun] --------------------------------------------------- -<1> Whether the rollover should be performed (default) or only simulated - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> Sets the number of active shard copies to wait for before the rollover -index API returns a response -<2> Resets the number of active shard copies to wait for to the default value - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-settings] --------------------------------------------------- -<1> Add the settings to apply to the new index, which include the number of -shards to create for it - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-mapping] --------------------------------------------------- -<1> Add the mappings to associate the new index with. See <> -for examples on the different ways to provide mappings - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-alias] --------------------------------------------------- -<1> Add the aliases to associate the new index with - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Rollover Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out -<3> The name of the old index, eventually rolled over -<4> The name of the new index -<5> Whether the index has been rolled over -<6> Whether the operation was performed or it was a dry run -<7> The different conditions and whether they were matched or not diff --git a/docs/java-rest/high-level/indices/shrink_index.asciidoc b/docs/java-rest/high-level/indices/shrink_index.asciidoc deleted file mode 100644 index 3e6ec1f55142..000000000000 --- a/docs/java-rest/high-level/indices/shrink_index.asciidoc +++ /dev/null @@ -1,83 +0,0 @@ --- -:api: shrink-index -:request: ResizeRequest -:response: ResizeResponse --- - -[id="{upid}-{api}"] -=== Shrink Index API - -[id="{upid}-{api}-request"] -==== Resize Request - -The Shrink API requires a +{request}+ instance. -A +{request}+ requires two string arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The target index (first argument) to shrink the source index (second argument) into - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the shrink index API -returns a response, as an `int` -<2> The number of active shard copies to wait for before the shrink index API -returns a response, as an `ActiveShardCount` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-settings] --------------------------------------------------- -<1> The number of shards on the target of the shrink index request -<2> Remove the allocation requirement copied from the source index - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-maxPrimaryShardSize] --------------------------------------------------- -<1> The max primary shard size of the target index - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aliases] --------------------------------------------------- -<1> The aliases to associate the target index with - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Shrink Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out diff --git a/docs/java-rest/high-level/indices/simulate_index_template.asciidoc b/docs/java-rest/high-level/indices/simulate_index_template.asciidoc deleted file mode 100644 index 4dc4429ea8ac..000000000000 --- a/docs/java-rest/high-level/indices/simulate_index_template.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: simulate-index-template -:request: SimulateIndexTemplateRequest -:response: SimulateIndexTemplateResponse --- - -[id="{upid}-{api}"] -=== Simulate Index Template API - -[id="{upid}-{api}-request"] -==== Simulate Index Template Request - -A +{request}+ specifies the `indexName` to simulate matching against the -templates in the system. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the index -<2> Optionally, defines a new template - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Simulate Index Template Response - -The returned +{response}+ includes a resolved `Template` object containing -the resolved settings, mappings and aliases of the index template that matched -and would be applied to the index with the provided name (if any). It will -also return a `Map` of index templates (both legacy and composable) names and their -corresponding index patterns: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Resolved template configuration that would be applied when creating the index with the provided name -<2> Overlapping index templates and their corresponding index patterns diff --git a/docs/java-rest/high-level/indices/split_index.asciidoc b/docs/java-rest/high-level/indices/split_index.asciidoc deleted file mode 100644 index c142b2ed9e15..000000000000 --- a/docs/java-rest/high-level/indices/split_index.asciidoc +++ /dev/null @@ -1,80 +0,0 @@ --- -:api: split-index -:request: ResizeRequest -:response: ResizeResponse --- - -[id="{upid}-{api}"] -=== Split Index API - -[id="{upid}-{api}-request"] -==== Resize Request - -The Split API requires a +{request}+ instance. -A +{request}+ requires two string arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The target index (first argument) to split the source index (second argument) into -<2> The resize type needs to be set to `SPLIT` - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the index is opened -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the split index API -returns a response, as an `int` -<2> The number of active shard copies to wait for before the split index API -returns a response, as an `ActiveShardCount` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-settings] --------------------------------------------------- -<1> The settings to apply to the target index, which include the number of -shards to create for it - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aliases] --------------------------------------------------- -<1> The aliases to associate the target index with - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Split Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out - - diff --git a/docs/java-rest/high-level/indices/templates_exist.asciidoc b/docs/java-rest/high-level/indices/templates_exist.asciidoc deleted file mode 100644 index c89627c43c19..000000000000 --- a/docs/java-rest/high-level/indices/templates_exist.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ --- -:api: templates-exist -:request: IndexTemplatesExistRequest -:response: Boolean --- - -[id="{upid}-{api}"] -=== Templates Exist API - -[id="{upid}-{api}-request"] -==== Templates Exist Request - -The Templates Exist API uses +{request}+ as its request object. One or more -index template names can be provided at construction. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> A single index template name -<2> Multiple index template names -<3> An index template name using wildcard - -==== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-optionals] --------------------------------------------------- -<1> If `true`, reads templates from the node's local cluster state. Otherwise -reads from the cluster state of the elected master node -<2> Timeout to connect to the master node as a `TimeValue` -<3> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The response is a +{response}+ value, `true` if any of the request's template -names match existing templates and `false` otherwise \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/unfreeze_index.asciidoc b/docs/java-rest/high-level/indices/unfreeze_index.asciidoc deleted file mode 100644 index 03a4d16c9c57..000000000000 --- a/docs/java-rest/high-level/indices/unfreeze_index.asciidoc +++ /dev/null @@ -1,64 +0,0 @@ --- -:api: unfreeze-index -:request: UnfreezeIndexRequest -:response: UnfreezeIndexResponse --- -[id="{upid}-{api}"] -=== Unfreeze Index API - -[id="{upid}-{api}-request"] -==== Unfreeze Index Request - -An +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to unfreeze - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is frozen -as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the unfreeze index API -returns a response, as an `ActiveShardCount` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Unfreeze Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out diff --git a/docs/java-rest/high-level/indices/update_aliases.asciidoc b/docs/java-rest/high-level/indices/update_aliases.asciidoc deleted file mode 100644 index 964f66d4bcd2..000000000000 --- a/docs/java-rest/high-level/indices/update_aliases.asciidoc +++ /dev/null @@ -1,68 +0,0 @@ --- -:api: update-aliases -:request: IndicesAliasesRequest -:response: IndicesAliasesResponse --- - -[id="{upid}-{api}"] -=== Index Aliases API - -[id="{upid}-{api}-request"] -==== Indices Aliases Request - -The Index Aliases API allows aliasing an index with a name, with all APIs -automatically converting the alias name to the actual index name. - -An +{request}+ must have at least one `AliasActions`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Creates an `IndicesAliasesRequest` -<2> Creates an `AliasActions` that aliases index `test1` with `alias1` -<3> Adds the alias action to the request - -The following action types are supported: `add` - alias an index, `remove` - -removes the alias associated with the index, and `remove_index` - deletes the -index. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request2] --------------------------------------------------- -<1> Creates an alias `alias1` with an optional filter on field `year` -<2> Creates an alias `alias2` associated with two indices and with an optional routing -<3> Removes the associated alias `alias3` -<4> `remove_index` is just like <> - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the operation as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the operation as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Indices Aliases Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request \ No newline at end of file diff --git a/docs/java-rest/high-level/indices/validate_query.asciidoc b/docs/java-rest/high-level/indices/validate_query.asciidoc deleted file mode 100644 index 920e5cf43547..000000000000 --- a/docs/java-rest/high-level/indices/validate_query.asciidoc +++ /dev/null @@ -1,83 +0,0 @@ --- -:api: indices-validate-query -:request: ValidateQueryRequest -:response: ValidateQueryResponse --- - -[id="{upid}-{api}"] -=== Validate Query API - -[id="{upid}-{api}-request"] -==== Validate Query Request - -A +{request}+ requires one or more `indices` on which the query is validated. If no index -is provided the request is executed on all indices. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index on which to run the request. - -In addition it also needs the query that needs to be validated. The query can be built using the `QueryBuilders` utility class. -The following code snippet builds a sample boolean query. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-query] --------------------------------------------------- -<1> Build the desired query. -<2> Set it to the request. - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-explain] --------------------------------------------------- -<1> The explain parameter can be set to true to get more detailed information about why a query failed - -By default, the request is executed on a single shard only, which is randomly selected. The detailed explanation of -the query may depend on which shard is being hit, and therefore may vary from one request to another. So, in case of -query rewrite the `allShards` parameter should be used to get response from all available shards. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-allShards] --------------------------------------------------- -<1> Set the allShards parameter. - -When the query is valid, the explanation defaults to the string representation of that query. With rewrite set to true, -the explanation is more detailed showing the actual Lucene query that will be executed - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-rewrite] --------------------------------------------------- -<1> Set the rewrite parameter. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Validate Query Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Check if the query is valid or not. -<2> Get total number of shards. -<3> Get number of shards that were successful. -<4> Get number of shards that failed. -<5> Get the shard failures as `DefaultShardOperationFailedException`. -<6> Get the index of a failed shard. -<7> Get the shard id of a failed shard. -<8> Get the reason for shard failure. -<9> Get the detailed explanation for the shards (if explain was set to `true`). -<10> Get the index to which a particular explanation belongs. -<11> Get the shard id to which a particular explanation belongs. -<12> Get the actual explanation string. \ No newline at end of file diff --git a/docs/java-rest/high-level/ingest/delete_pipeline.asciidoc b/docs/java-rest/high-level/ingest/delete_pipeline.asciidoc deleted file mode 100644 index 3801f8a3b528..000000000000 --- a/docs/java-rest/high-level/ingest/delete_pipeline.asciidoc +++ /dev/null @@ -1,80 +0,0 @@ -[[java-rest-high-ingest-delete-pipeline]] -=== Delete Pipeline API - -[[java-rest-high-ingest-delete-pipeline-request]] -==== Delete Pipeline Request - -A `DeletePipelineRequest` requires a pipeline `id` to delete. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-request] --------------------------------------------------- -<1> The pipeline id to delete - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the pipeline deletion as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the pipeline deletion as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-ingest-delete-pipeline-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-execute] --------------------------------------------------- -<1> Execute the request and get back the response in a `WritePipelineResponse` object. - -[[java-rest-high-ingest-delete-pipeline-async]] -==== Asynchronous Execution - -The asynchronous execution of a delete pipeline request requires both the `DeletePipelineRequest` -instance and an `ActionListener` instance to be passed to the asynchronous -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-execute-async] --------------------------------------------------- -<1> The `DeletePipelineRequest` 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 `WritePipelineResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-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 - -[[java-rest-high-ingest-delete-pipeline-response]] -==== Delete Pipeline Response - -The returned `WritePipelineResponse` allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/ingest/get_pipeline.asciidoc b/docs/java-rest/high-level/ingest/get_pipeline.asciidoc deleted file mode 100644 index 54ba545d7098..000000000000 --- a/docs/java-rest/high-level/ingest/get_pipeline.asciidoc +++ /dev/null @@ -1,75 +0,0 @@ -[[java-rest-high-ingest-get-pipeline]] -=== Get Pipeline API - -[[java-rest-high-ingest-get-pipeline-request]] -==== Get Pipeline Request - -A `GetPipelineRequest` requires one or more `pipelineIds` to fetch. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-request] --------------------------------------------------- -<1> The pipeline id to fetch - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-ingest-get-pipeline-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-execute] --------------------------------------------------- -<1> Execute the request and get back the response in a GetPipelineResponse object. - -[[java-rest-high-ingest-get-pipeline-async]] -==== Asynchronous Execution - -The asynchronous execution of a get pipeline request requires both the `GetPipelineRequest` -instance and an `ActionListener` instance to be passed to the asynchronous -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-execute-async] --------------------------------------------------- -<1> The `GetPipelineRequest` 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 `GetPipelineResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-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 - -[[java-rest-high-ingest-get-pipeline-response]] -==== Get Pipeline Response - -The returned `GetPipelineResponse` allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-response] --------------------------------------------------- -<1> Check if a matching pipeline id was found or not. -<2> Get the list of pipelines found as a list of `PipelineConfig` objects. -<3> Get the individual configuration of each pipeline as a `Map`. diff --git a/docs/java-rest/high-level/ingest/put_pipeline.asciidoc b/docs/java-rest/high-level/ingest/put_pipeline.asciidoc deleted file mode 100644 index 50dc049ae58d..000000000000 --- a/docs/java-rest/high-level/ingest/put_pipeline.asciidoc +++ /dev/null @@ -1,83 +0,0 @@ -[[java-rest-high-ingest-put-pipeline]] -=== Create or update pipeline API - -[[java-rest-high-ingest-put-pipeline-request]] -==== Request - -A `PutPipelineRequest` requires an `id` argument, a source and a `XContentType`. The source consists -of a description and a list of `Processor` objects. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-request] --------------------------------------------------- -<1> The pipeline id -<2> The source for the pipeline as a `ByteArray`. -<3> The XContentType for the pipeline source supplied above. - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the pipeline creation as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the pipeline creation as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-ingest-put-pipeline-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-execute] --------------------------------------------------- -<1> Execute the request and get back the response in a WritePipelineResponse object. - -[[java-rest-high-ingest-put-pipeline-async]] -==== Asynchronous Execution - -The asynchronous execution of a create or update pipeline request requires both -the `PutPipelineRequest` instance and an `ActionListener` instance to be passed -to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-execute-async] --------------------------------------------------- -<1> The `PutPipelineRequest` 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 `WritePipelineResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-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 - -[[java-rest-high-ingest-put-pipeline-response]] -==== Response - -The returned `WritePipelineResponse` allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/ingest/simulate_pipeline.asciidoc b/docs/java-rest/high-level/ingest/simulate_pipeline.asciidoc deleted file mode 100644 index 9d1bbd06ceb2..000000000000 --- a/docs/java-rest/high-level/ingest/simulate_pipeline.asciidoc +++ /dev/null @@ -1,90 +0,0 @@ -[[java-rest-high-ingest-simulate-pipeline]] -=== Simulate Pipeline API - -[[java-rest-high-ingest-simulate-pipeline-request]] -==== Simulate Pipeline Request - -A `SimulatePipelineRequest` requires a source and a `XContentType`. The source consists -of the request body. See the https://www.elastic.co/guide/en/elasticsearch/reference/master/simulate-pipeline-api.html[docs] -for more details on the request body. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-request] --------------------------------------------------- -<1> The request body as a `ByteArray`. -<2> The XContentType for the request body supplied above. - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-request-pipeline-id] --------------------------------------------------- -<1> You can either specify an existing pipeline to execute against the provided documents, or supply a -pipeline definition in the body of the request. This option sets the id for an existing pipeline. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-request-verbose] --------------------------------------------------- -<1> To see the intermediate results of each processor in the simulate request, you can add the verbose parameter -to the request. - -[[java-rest-high-ingest-simulate-pipeline-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-execute] --------------------------------------------------- -<1> Execute the request and get back the response in a `SimulatePipelineResponse` object. - -[[java-rest-high-ingest-simulate-pipeline-async]] -==== Asynchronous Execution - -The asynchronous execution of a simulate pipeline request requires both the `SimulatePipelineRequest` -instance and an `ActionListener` instance to be passed to the asynchronous -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-execute-async] --------------------------------------------------- -<1> The `SimulatePipelineRequest` 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 `SimulatePipelineResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-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 - -[[java-rest-high-ingest-simulate-pipeline-response]] -==== Simulate Pipeline Response - -The returned `SimulatePipelineResponse` allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-response] --------------------------------------------------- -<1> Get results for each of the documents provided as instance of `List`. -<2> If the request was in verbose mode cast the response to `SimulateDocumentVerboseResult`. -<3> Check the result after each processor is applied. -<4> Get the ingest document for the result obtained in 3. -<5> Or get the failure for the result obtained in 3. -<6> Get the result as `SimulateDocumentBaseResult` if the result was not verbose. -<7> Get the ingest document for the result obtained in 6. -<8> Or get the failure for the result obtained in 6. diff --git a/docs/java-rest/high-level/java-builders.asciidoc b/docs/java-rest/high-level/java-builders.asciidoc deleted file mode 100644 index 89f2de5fa9f4..000000000000 --- a/docs/java-rest/high-level/java-builders.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ -[[java-rest-high-java-builders]] -== Using Java Builders - -The Java High Level REST Client depends on the Elasticsearch core project which provides -different types of Java `Builders` objects, including: - -Query Builders:: - -The query builders are used to create the query to execute within a search request. There -is a query builder for every type of query supported by the Query DSL. Each query builder -implements the `QueryBuilder` interface and allows to set the specific options for a given -type of query. Once created, the `QueryBuilder` object can be set as the query parameter of -`SearchSourceBuilder`. The <> -page shows an example of how to build a full search request using `SearchSourceBuilder` and -`QueryBuilder` objects. The <> page -gives a list of all available search queries with their corresponding `QueryBuilder` objects -and `QueryBuilders` helper methods. - -Aggregation Builders:: - -Similarly to query builders, the aggregation builders are used to create the aggregations to -compute during a search request execution. There is an aggregation builder for every type of -aggregation (or pipeline aggregation) supported by Elasticsearch. All builders extend the -`AggregationBuilder` class (or `PipelineAggregationBuilder`class). Once created, `AggregationBuilder` -objects can be set as the aggregation parameter of `SearchSourceBuilder`. There is a example -of how `AggregationBuilder` objects are used with `SearchSourceBuilder` objects to define the aggregations -to compute with a search query in <> page. -The <> page gives a list of all available -aggregations with their corresponding `AggregationBuilder` objects and `AggregationBuilders` helper methods. - -include::query-builders.asciidoc[] -include::aggs-builders.asciidoc[] diff --git a/docs/java-rest/high-level/licensing/delete-license.asciidoc b/docs/java-rest/high-level/licensing/delete-license.asciidoc deleted file mode 100644 index d9aec6e57a14..000000000000 --- a/docs/java-rest/high-level/licensing/delete-license.asciidoc +++ /dev/null @@ -1,51 +0,0 @@ -[[java-rest-high-delete-license]] -=== Delete License - -[[java-rest-high-delete-license-execution]] -==== Execution - -The license can be deleted using the `deleteLicense()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[delete-license-execute] --------------------------------------------------- - -[[java-rest-high-delete-license-response]] -==== Response - -The returned `DeleteLicenseResponse` contains the `acknowledged` flag, which -returns true if the request was processed by all nodes. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[delete-license-response] --------------------------------------------------- -<1> Check the acknowledge flag. It should be true if license deletion is acknowledged. - -[[java-rest-high-delete-license-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[delete-license-execute-async] --------------------------------------------------- -<1> The `DeleteLicenseRequest` 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 `DeleteLicenseResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[delete-license-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 diff --git a/docs/java-rest/high-level/licensing/get-basic-status.asciidoc b/docs/java-rest/high-level/licensing/get-basic-status.asciidoc deleted file mode 100644 index ffca094a5922..000000000000 --- a/docs/java-rest/high-level/licensing/get-basic-status.asciidoc +++ /dev/null @@ -1,23 +0,0 @@ -[[java-rest-high-get-basic-status]] -=== Get Basic Status - -[[java-rest-high-get-basic-status-execution]] -==== Execution - -The basic status of the license can be retrieved as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-basic-status-execute] --------------------------------------------------- - -[[java-rest-high-get-basic-status-response]] -==== Response - -The returned `GetTrialStatusResponse` holds only a `boolean` flag: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-basic-status-response] --------------------------------------------------- -<1> Whether the license is eligible to start basic or not diff --git a/docs/java-rest/high-level/licensing/get-license.asciidoc b/docs/java-rest/high-level/licensing/get-license.asciidoc deleted file mode 100644 index 17eb89450fb1..000000000000 --- a/docs/java-rest/high-level/licensing/get-license.asciidoc +++ /dev/null @@ -1,50 +0,0 @@ -[[java-rest-high-get-license]] -=== Get License - -[[java-rest-high-get-license-execution]] -==== Execution - -The license can be added or updated using the `getLicense()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-execute] --------------------------------------------------- - -[[java-rest-high-get-license-response]] -==== Response - -The returned `GetLicenseResponse` contains the license in the JSON format. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-response] --------------------------------------------------- -<1> The text of the license. - -[[java-rest-high-get-license-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-execute-async] --------------------------------------------------- -<1> The `GetLicenseRequest` 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 `GetLicenseResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-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 diff --git a/docs/java-rest/high-level/licensing/get-trial-status.asciidoc b/docs/java-rest/high-level/licensing/get-trial-status.asciidoc deleted file mode 100644 index f117f9aa838a..000000000000 --- a/docs/java-rest/high-level/licensing/get-trial-status.asciidoc +++ /dev/null @@ -1,23 +0,0 @@ -[[java-rest-high-get-trial-status]] -=== Get Trial Status - -[[java-rest-high-get-trial-status-execution]] -==== Execution - -The trial status of the license can be retrieved as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-trial-status-execute] --------------------------------------------------- - -[[java-rest-high-get-trial-status-response]] -==== Response - -The returned `GetTrialStatusResponse` holds only a `boolean` flag: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-trial-status-response] --------------------------------------------------- -<1> Whether the license is eligible to start trial or not diff --git a/docs/java-rest/high-level/licensing/put-license.asciidoc b/docs/java-rest/high-level/licensing/put-license.asciidoc deleted file mode 100644 index 945d447317bc..000000000000 --- a/docs/java-rest/high-level/licensing/put-license.asciidoc +++ /dev/null @@ -1,65 +0,0 @@ -[[java-rest-high-put-license]] -=== Update License - -[[java-rest-high-put-license-execution]] -==== Execution - -The license can be added or updated using the `putLicense()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[put-license-execute] --------------------------------------------------- -<1> Set the categories of information to retrieve. The default is to -return no information which is useful for checking if {xpack} is installed -but not much else. -<2> A JSON document containing the license information. - -[[java-rest-high-put-license-response]] -==== Response - -The returned `PutLicenseResponse` contains the `LicensesStatus`, -`acknowledged` flag and possible acknowledge messages. The acknowledge messages -are present if you previously had a license with more features than one you -are trying to update and you didn't set the `acknowledge` flag to `true`. In this case -you need to display the messages to the end user and if they agree, resubmit the -license with the `acknowledge` flag set to `true`. Please note that the request will -still return a 200 return code even if requires an acknowledgement. So, it is -necessary to check the `acknowledged` flag. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[put-license-response] --------------------------------------------------- -<1> The status of the license -<2> Make sure that the license is valid. -<3> Check the acknowledge flag. It should be true if license is acknowledged. -<4> Otherwise we can see the acknowledge messages in `acknowledgeHeader()` -<5> and check component-specific messages in `acknowledgeMessages()`. - -[[java-rest-high-put-license-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[put-license-execute-async] --------------------------------------------------- -<1> The `PutLicenseRequest` 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 `PutLicenseResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[put-license-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 diff --git a/docs/java-rest/high-level/licensing/start-basic.asciidoc b/docs/java-rest/high-level/licensing/start-basic.asciidoc deleted file mode 100644 index 30f2c51a1c13..000000000000 --- a/docs/java-rest/high-level/licensing/start-basic.asciidoc +++ /dev/null @@ -1,67 +0,0 @@ -[[java-rest-high-start-basic]] -=== Start Basic License - -[[java-rest-high-start-basic-execution]] -==== Execution - -This API creates and enables a basic license using the `startBasic()` method. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-basic-execute] --------------------------------------------------- - -[[java-rest-high-start-basic-response]] -==== Response - -The returned `StartBasicResponse` returns a field indicating whether the -basic was started. If it was started, the response returns a the type of -license started. If it was not started, it returns an error message describing -why. - -Acknowledgement messages may also be returned if this API was called without -the `acknowledge` flag set to `true`. In this case you need to display the -messages to the end user and if they agree, resubmit the request with the -`acknowledge` flag set to `true`. Please note that the response will still -return a 200 return code even if it requires an acknowledgement. So, it is -necessary to check the `acknowledged` flag. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-basic-response] --------------------------------------------------- -<1> Whether or not the request had the `acknowledge` flag set -<2> Whether or not this request caused a basic to start -<3> If this request did not cause a basic to start, a message explaining why -<4> If the user's request did not have the `acknowledge` flag set, a summary -of the user's acknowledgement required for this API -<5> If the user's request did not have the `acknowledge` flag set, contains -keys of commercial features and values of messages describing how they will -be affected by licensing changes as the result of starting a basic - -[[java-rest-high-start-basic-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-basic-execute-async] --------------------------------------------------- -<1> The `StartBasicResponse` 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 `StartBasicResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-basic-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 diff --git a/docs/java-rest/high-level/licensing/start-trial.asciidoc b/docs/java-rest/high-level/licensing/start-trial.asciidoc deleted file mode 100644 index 30c75e10f0a1..000000000000 --- a/docs/java-rest/high-level/licensing/start-trial.asciidoc +++ /dev/null @@ -1,70 +0,0 @@ -[[java-rest-high-start-trial]] -=== Start Trial - -[[java-rest-high-start-trial-execution]] -==== Execution - -This API creates and enables a trial license using the `startTrial()` -method. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-trial-execute] ---------------------------------------------------- -<1> Sets the "acknowledge" parameter to true, indicating the user has -acknowledged that starting a trial license may affect commercial features - -[[java-rest-high-start-trial-response]] -==== Response - -The returned `StartTrialResponse` returns a field indicating whether the -trial was started. If it was started, the response returns a the type of -license started. If it was not started, it returns an error message describing -why. - -Acknowledgement messages may also be returned if this API was called without -the `acknowledge` flag set to `true`. In this case you need to display the -messages to the end user and if they agree, resubmit the request with the -`acknowledge` flag set to `true`. Please note that the response will still -return a 200 return code even if it requires an acknowledgement. So, it is -necessary to check the `acknowledged` flag. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-trial-response] --------------------------------------------------- -<1> Whether or not the request had the `acknowledge` flag set -<2> Whether or not this request caused a trial to start -<3> If this request caused a trial to start, which type of license it -registered -<4> If this request did not cause a trial to start, a message explaining why -<5> If the user's request did not have the `acknowledge` flag set, a summary -of the user's acknowledgement required for this API -<6> If the user's request did not have the `acknowledge` flag set, contains -keys of commercial features and values of messages describing how they will -be affected by licensing changes as the result of starting a trial - -[[java-rest-high-start-trial-async]] -==== Asynchronous execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-trial-execute-async] --------------------------------------------------- - -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 `StartTrialResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/LicensingDocumentationIT.java[start-trial-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 \ No newline at end of file diff --git a/docs/java-rest/high-level/migration.asciidoc b/docs/java-rest/high-level/migration.asciidoc deleted file mode 100644 index babc7681be63..000000000000 --- a/docs/java-rest/high-level/migration.asciidoc +++ /dev/null @@ -1,289 +0,0 @@ -[[java-rest-high-level-migration]] -== Migration Guide - -This section describes how to migrate existing code from the `TransportClient` -to the Java High Level REST Client released with the version 5.6.0 -of Elasticsearch. - -=== Motivations around a new Java client - -The existing `TransportClient` has been part of Elasticsearch since https://github.com/elastic/elasticsearch/blob/b3337c312765e51cec7bde5883bbc0a08f56fb65/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java[its very first commit]. - It is a special client as it uses the transport protocol to communicate with Elasticsearch, - which causes compatibility problems if the client is not on the same version as the - Elasticsearch instances it talks to. - -We released a low-level REST client in 2016, which is based on the well known Apache HTTP -client and it allows to communicate with an Elasticsearch cluster in any version using HTTP. -On top of that we released the high-level REST client which is based on the low-level client -but takes care of request marshalling and response un-marshalling. - -If you're interested in knowing more about these changes, we wrote a blog post about the -https://www.elastic.co/blog/state-of-the-official-elasticsearch-java-clients[state of the official Elasticsearch Java clients]. - -=== Prerequisite - -The Java High Level Rest Client requires Java `1.8` and can be used to send requests -to an <>. - -=== How to migrate - -Adapting existing code to use the `RestHighLevelClient` instead of the `TransportClient` -requires the following steps: - -- Update dependencies -- Update client initialization -- Update application code - -=== Updating the dependencies - -Java application that uses the `TransportClient` depends on the -`org.elasticsearch.client:transport` artifact. This dependency -must be replaced by a new dependency on the high-level client. - -The <> page shows - typical configurations for Maven and Gradle and presents the - <> brought by the - high-level client. - -// This ID is bad but it is the one we've had forever. -[[_changing_the_client_8217_s_initialization_code]] -=== Changing the client's initialization code - -The `TransportClient` is typically initialized as follows: -[source,java] --------------------------------------------------- -Settings settings = Settings.builder() - .put("cluster.name", "prod").build(); - -TransportClient transportClient = new PreBuiltTransportClient(settings) - .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300)) - .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9301)); --------------------------------------------------- - -The initialization of a `RestHighLevelClient` is different. It requires to provide -a <> as a constructor -argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[rest-high-level-client-init] --------------------------------------------------- - -NOTE: The `RestClient` uses Elasticsearch's HTTP service which is - bounded by default on `9200`. This port is different from the port - used to connect to Elasticsearch with a `TransportClient`. - -The `RestHighLevelClient` is thread-safe. It is typically instantiated by the -application at startup time or when the first request is executed. - -Once the `RestHighLevelClient` is initialized, it can be used to execute any -of the <>. - -As with the `TransportClient`, the `RestHighLevelClient` must be closed when it -is not needed anymore or when the application is stopped. - -The code that closes the `TransportClient`: - -[source,java] --------------------------------------------------- -transportClient.close(); --------------------------------------------------- - -must be replaced with: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[rest-high-level-client-close] --------------------------------------------------- - -// This ID is bad but it is the one we've had forever. -[[_changing_the_application_8217_s_code]] -=== Changing the application's code - -The `RestHighLevelClient` supports the same request and response objects -as the `TransportClient`, but exposes slightly different methods to -send the requests. - -More importantly, the high-level client: - -- does not support request builders. The legacy methods like -`client.prepareIndex()` must be changed to use - request constructors like `new IndexRequest()` to create requests - objects. The requests are then executed using synchronous or - asynchronous dedicated methods like `client.index()` or `client.indexAsync()`. - -==== How to migrate the way requests are built - -The Java API provides two ways to build a request: by using the request's constructor or by using -a request builder. Migrating from the `TransportClient` to the high-level client can be -straightforward if application's code uses the former, while changing usages of the latter can -require more work. - -[[java-rest-high-level-migration-request-ctor]] -===== With request constructors - -When request constructors are used, like in the following example: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-request-ctor] --------------------------------------------------- -<1> Create an `IndexRequest` using its constructor and id() setter. - -The migration is very simple. The execution using the `TransportClient`: - -[source,java] --------------------------------------------------- -IndexResponse response = transportClient.index(indexRequest).actionGet(); --------------------------------------------------- - -Can be easily replaced to use the `RestHighLevelClient`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-request-ctor-execution] --------------------------------------------------- - -[[java-rest-high-level-migration-request-builder]] -===== With request builders - -The Java API provides a request builder for every type of request. They are exposed by the -`TransportClient` through the many `prepare()` methods. Here are some examples: - -[source,java] --------------------------------------------------- -IndexRequestBuilder indexRequestBuilder = transportClient.prepareIndex(); // <1> -DeleteRequestBuilder deleteRequestBuilder = transportClient.prepareDelete(); // <2> -SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch(); // <3> --------------------------------------------------- -<1> Create a `IndexRequestBuilder` using the `prepareIndex()` method from the `TransportClient`. The -request builder encapsulates the `IndexRequest` to be executed. -<2> Create a `DeleteRequestBuilder` using the `prepareDelete()` method from the `TransportClient`. The -request builder encapsulates the `DeleteRequest` to be executed. -<3> Create a `SearchRequestBuilder` using the `prepareSearch()` method from the `TransportClient`. The -request builder encapsulates the `SearchRequest` to be executed. - -Since the Java High Level REST Client does not support request builders, applications that use -them must be changed to use <> instead. - -NOTE: While you are incrementally migrating your application and you have both the transport client -and the high level client available you can always get the `Request` object from the `Builder` object -by calling `Builder.request()`. We do not advise continuing to depend on the builders in the long run -but it should be possible to use them during the transition from the transport client to the high -level rest client. - -==== How to migrate the way requests are executed - -The `TransportClient` allows to execute requests in both synchronous and asynchronous ways. This is also -possible using the high-level client. - -===== Synchronous execution - -The following example shows how a `DeleteRequest` can be synchronously executed using the `TransportClient`: - -[source,java] --------------------------------------------------- -DeleteRequest request = new DeleteRequest("index", "doc", "id"); // <1> -DeleteResponse response = transportClient.delete(request).actionGet(); // <2> --------------------------------------------------- -<1> Create the `DeleteRequest` using its constructor -<2> Execute the `DeleteRequest`. The `actionGet()` method blocks until a -response is returned by the cluster. - -The same request synchronously executed using the high-level client is: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-request-sync-execution] --------------------------------------------------- -<1> Execute the `DeleteRequest`. The `delete()` method blocks until a -response is returned by the cluster. - -===== Asynchronous execution - -The following example shows how a `DeleteRequest` can be asynchronously executed using the `TransportClient`: - -[source,java] --------------------------------------------------- -DeleteRequest request = new DeleteRequest("index", "doc", "id"); // <1> -transportClient.delete(request, new ActionListener() { // <2> - @Override - public void onResponse(DeleteResponse deleteResponse) { - // <3> - } - - @Override - public void onFailure(Exception e) { - // <4> - } -}); --------------------------------------------------- -<1> Create the `DeleteRequest` using its constructor -<2> Execute the `DeleteRequest` by passing the request and an -`ActionListener` that gets called on execution completion or -failure. This method does not block and returns immediately. -<3> The `onResponse()` method is called when the response is -returned by the cluster. -<4> The `onFailure()` method is called when an error occurs -during the execution of the request. - -The same request asynchronously executed using the high-level client is: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-request-async-execution] --------------------------------------------------- -<1> Create the `DeleteRequest` using its constructor -<2> Execute the `DeleteRequest` by passing the request and an -`ActionListener` that gets called on execution completion or -failure. This method does not block and returns immediately. -<3> The `onResponse()` method is called when the response is -returned by the cluster. -<4> The `onFailure()` method is called when an error occurs -during the execution of the request. - -[[java-rest-high-level-migration-cluster-health]] -==== Checking Cluster Health using the Low-Level REST Client - -Another common need is to check the cluster's health using the Cluster API. With -the `TransportClient` it can be done this way: - -[source,java] --------------------------------------------------- -ClusterHealthResponse response = client.admin().cluster().prepareHealth().get(); // <1> - -ClusterHealthStatus healthStatus = response.getStatus(); // <2> -if (healthStatus != ClusterHealthStatus.GREEN) { - // <3> -} --------------------------------------------------- -<1> Execute a `ClusterHealth` with default parameters -<2> Retrieve the cluster's health status from the response -<3> Handle the situation where the cluster's health is not green - -With the low-level client, the code can be changed to: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-cluster-health] --------------------------------------------------- -<1> Set up the request to wait for the cluster's health to become green if it isn't already. -<2> Make the request and the get back a `Response` object. -<3> Retrieve an `InputStream` object in order to read the response's content -<4> Parse the response's content using Elasticsearch's helper class `XContentHelper`. This - helper requires the content type of the response to be passed as an argument and returns - a `Map` of objects. Values in the map can be of any type, including inner `Map` that are - used to represent the JSON object hierarchy. -<5> Retrieve the value of the `status` field in the response map, casts it as a `String` -object and use the `ClusterHealthStatus.fromString()` method to convert it as a `ClusterHealthStatus` -object. This method throws an exception if the value does not corresponds to a valid cluster -health status. -<6> Handle the situation where the cluster's health is not green - -Note that for convenience this example uses Elasticsearch's helpers to parse the JSON response -body, but any other JSON parser could have been use instead. - -=== Provide feedback - -We love to hear from you! Please give us your feedback about your migration -experience and how to improve the Java High Level Rest Client on https://discuss.elastic.co/[our forum]. diff --git a/docs/java-rest/high-level/migration/get-deprecation-info.asciidoc b/docs/java-rest/high-level/migration/get-deprecation-info.asciidoc deleted file mode 100644 index 3cda1c2f503d..000000000000 --- a/docs/java-rest/high-level/migration/get-deprecation-info.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: get-deprecation-info -:request: DeprecationInfoRequest -:response: DeprecationInfoResponse --- - -[id="{upid}-{api}"] -=== Get Deprecation Info - -[id="{upid}-{api}-request"] -==== Get Deprecation Info Request - -A +{request}+ can be applied to one or more indices: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Create a new request instance - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Deprecation Info Response - -The returned +{response}+ contains information about deprecated features currently -in use at the cluster, node, and index level. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> a List of Cluster deprecations -<2> a List of Node deprecations -<3> a Map of key IndexName, value List of deprecations for the index -<4> a list of Machine Learning related deprecations diff --git a/docs/java-rest/high-level/miscellaneous/main.asciidoc b/docs/java-rest/high-level/miscellaneous/main.asciidoc deleted file mode 100644 index 635fe6f3b99e..000000000000 --- a/docs/java-rest/high-level/miscellaneous/main.asciidoc +++ /dev/null @@ -1,22 +0,0 @@ -[[java-rest-high-main]] -=== Info API - -[[java-rest-high-main-request]] -==== Execution - -Cluster information can be retrieved using the `info()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[main-execute] --------------------------------------------------- - -[[java-rest-high-main-response]] -==== Response - -The returned `MainResponse` provides various kinds of information about the cluster: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[main-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/miscellaneous/ping.asciidoc b/docs/java-rest/high-level/miscellaneous/ping.asciidoc deleted file mode 100644 index 6cff46a62c5e..000000000000 --- a/docs/java-rest/high-level/miscellaneous/ping.asciidoc +++ /dev/null @@ -1,13 +0,0 @@ -[[java-rest-high-ping]] -=== Ping API - -[[java-rest-high-ping-request]] -==== Execution - -The `ping()` method checks if the cluster is up and available to -process requests and returns a boolean: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[ping-execute] --------------------------------------------------- diff --git a/docs/java-rest/high-level/miscellaneous/x-pack-info.asciidoc b/docs/java-rest/high-level/miscellaneous/x-pack-info.asciidoc deleted file mode 100644 index b432b10d3b8b..000000000000 --- a/docs/java-rest/high-level/miscellaneous/x-pack-info.asciidoc +++ /dev/null @@ -1,64 +0,0 @@ -[[java-rest-high-x-pack-info]] -=== X-Pack Info API - -[[java-rest-high-x-pack-info-execution]] -==== Execution - -General information about the installed {xpack} features can be retrieved -using the `xPackInfo()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-info-execute] --------------------------------------------------- -<1> Enable verbose mode. The default is `false` but `true` will return -more information. -<2> Set the categories of information to retrieve. The default is to -return no information which is useful for checking if {xpack} is installed -but not much else. - -[[java-rest-high-x-pack-info-response]] -==== Response - -The returned `XPackInfoResponse` can contain `BuildInfo`, `LicenseInfo`, -and `FeatureSetsInfo` depending on the categories requested. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-info-response] --------------------------------------------------- -<1> `BuildInfo` contains the commit hash from which Elasticsearch was -built and the timestamp that the x-pack module was created. -<2> `LicenseInfo` contains the type of license that the cluster is using -and its expiration date. -<3> Basic licenses do not expire and will return this constant. -<4> `FeatureSetsInfo` contains a `Map` from the name of a feature to -information about a feature like whether or not it is available under -the current license. - -[[java-rest-high-x-pack-info-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-info-execute-async] --------------------------------------------------- -<1> The `XPackInfoRequest` 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 `XPackInfoResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-info-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 diff --git a/docs/java-rest/high-level/miscellaneous/x-pack-usage.asciidoc b/docs/java-rest/high-level/miscellaneous/x-pack-usage.asciidoc deleted file mode 100644 index c1e5ccf13e22..000000000000 --- a/docs/java-rest/high-level/miscellaneous/x-pack-usage.asciidoc +++ /dev/null @@ -1,54 +0,0 @@ -[[java-rest-high-x-pack-usage]] -=== X-Pack Usage API - -[[java-rest-high-x-pack-usage-execution]] -==== Execution - -Detailed information about the usage of features from {xpack} can be -retrieved using the `usage()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-usage-execute] --------------------------------------------------- - -[[java-rest-high-x-pack-usage-response]] -==== Response - -The returned `XPackUsageResponse` contains a `Map` keyed by feature name. -Every feature map has an `available` key, indicating whether that -feature is available given the current license, and an `enabled` key, -indicating whether that feature is currently enabled. Other keys -are specific to each feature. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-usage-response] --------------------------------------------------- - -[[java-rest-high-x-pack-usage-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-usage-execute-async] --------------------------------------------------- -<1> The call to execute the usage api 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 `XPackUsageResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MiscellaneousDocumentationIT.java[x-pack-usage-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 diff --git a/docs/java-rest/high-level/ml/close-job.asciidoc b/docs/java-rest/high-level/ml/close-job.asciidoc deleted file mode 100644 index 83798b591c21..000000000000 --- a/docs/java-rest/high-level/ml/close-job.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: close-job -:request: CloseJobRequest -:response: CloseJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Close {anomaly-jobs} API - -Closes {anomaly-jobs} in the cluster. It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Close {anomaly-jobs} request - -A +{request}+ object gets created with an existing non-null `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing job IDs -<2> Optionally used to close a failed job, or to forcefully close a job -which has not responded to its initial close request. -<3> Optionally set to ignore if a wildcard expression matches no jobs. - (This includes `_all` string or when no jobs have been specified) -<4> Optionally setting the `timeout` value for how long the -execution should wait for the job to be closed. - -[id="{upid}-{api}-response"] -==== Close {anomaly-jobs} response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isClosed()` from the +{response}+ indicates if the job was successfully -closed or not. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-calendar-event.asciidoc b/docs/java-rest/high-level/ml/delete-calendar-event.asciidoc deleted file mode 100644 index e58797264574..000000000000 --- a/docs/java-rest/high-level/ml/delete-calendar-event.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: delete-calendar-event -:request: DeleteCalendarEventRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete calendar events API - -Removes a scheduled event from an existing {ml} calendar. -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Delete calendar events request - -A +{request}+ is constructed referencing a non-null -calendar ID, and eventId which to remove from the calendar - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The ID of the calendar from which to remove the jobs -<2> The eventId to remove from the calendar - -[id="{upid}-{api}-response"] -==== Delete calendar events response - -The returned +{response}+ acknowledges the success of the request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Acknowledgement of the request and its success - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-calendar-job.asciidoc b/docs/java-rest/high-level/ml/delete-calendar-job.asciidoc deleted file mode 100644 index cbfd2f40a8bd..000000000000 --- a/docs/java-rest/high-level/ml/delete-calendar-job.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: delete-calendar-job -:request: DeleteCalendarJobRequest -:response: PutCalendarResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete {anomaly-jobs} from calendar API - -Removes {anomaly-jobs} from an existing {ml} calendar. -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Delete {anomaly-jobs} from calendar request - -A +{request}+ is constructed referencing a non-null -calendar ID, and JobIDs which to remove from the calendar - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The ID of the calendar from which to remove the jobs -<2> The JobIds to remove from the calendar - -[id="{upid}-{api}-response"] -==== Delete {anomaly-jobs} from calendar response - -The returned +{response}+ contains the updated Calendar: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The updated calendar with the jobs removed - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-calendar.asciidoc b/docs/java-rest/high-level/ml/delete-calendar.asciidoc deleted file mode 100644 index 1c35164ad576..000000000000 --- a/docs/java-rest/high-level/ml/delete-calendar.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: delete-calendar -:request: DeleteCalendarRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete calendars API - -Deletes a {ml} calendar. -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Delete calendars request - -A `DeleteCalendar` object requires a non-null `calendarId`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new request referencing an existing calendar - -[id="{upid}-{api}-response"] -==== Delete calendars response - -The returned +{response}+ object indicates the acknowledgement of the request: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] ---------------------------------------------------- -<1> `isAcknowledged` was the deletion request acknowledged or not - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-data-frame-analytics.asciidoc b/docs/java-rest/high-level/ml/delete-data-frame-analytics.asciidoc deleted file mode 100644 index 0516564b3c49..000000000000 --- a/docs/java-rest/high-level/ml/delete-data-frame-analytics.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ --- -:api: delete-data-frame-analytics -:request: DeleteDataFrameAnalyticsRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete {dfanalytics-jobs} API - - -Delete an existing {dfanalytics-job}. -The API accepts a +{request}+ object as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Delete {dfanalytics-jobs} request - -A +{request}+ object requires a {dfanalytics-job} ID. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new request referencing an existing {dfanalytics-job}. - -==== Optional arguments - -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] ---------------------------------------------------- -<1> Use to forcefully delete a job that is not stopped. This method is quicker than stopping -and deleting the job. Defaults to `false`. -<2> Use to set the time to wait until the job is deleted. Defaults to 1 minute. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ object acknowledges the {dfanalytics-job} deletion. diff --git a/docs/java-rest/high-level/ml/delete-datafeed.asciidoc b/docs/java-rest/high-level/ml/delete-datafeed.asciidoc deleted file mode 100644 index d2b81d1e8b7f..000000000000 --- a/docs/java-rest/high-level/ml/delete-datafeed.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ --- -:api: delete-datafeed -:request: DeleteDatafeedRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-delete-datafeed"] -=== Delete datafeeds API - -Deletes an existing datafeed. - -[id="{upid}-{api}-request"] -==== Delete datafeeds request - -A +{request}+ object requires a non-null `datafeedId` and can optionally set `force`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Use to forcefully delete a started datafeed. This method is quicker than -stopping and deleting the datafeed. Defaults to `false`. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete datafeeds response - -The returned +{response}+ object indicates the acknowledgement of the request: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] ---------------------------------------------------- -<1> `isAcknowledged` was the deletion request acknowledged or not. diff --git a/docs/java-rest/high-level/ml/delete-expired-data.asciidoc b/docs/java-rest/high-level/ml/delete-expired-data.asciidoc deleted file mode 100644 index b86cc3723e2b..000000000000 --- a/docs/java-rest/high-level/ml/delete-expired-data.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ - --- -:api: delete-expired-data -:request: DeleteExpiredRequest -:response: DeleteExpiredResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete expired data API - -Deletes expired {ml} data. -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Delete expired data request - -A `DeleteExpiredDataRequest` object does not require any arguments. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new request. -<2> Optionally set a job ID. Use `null` for the default wild card all `*`. -<3> Providing requests per second throttling for the - deletion processes. Default is no throttling. -<4> Setting how long the deletion processes will be allowed - to run before they are canceled. Default value is `8h` (8 hours). - -[id="{upid}-{api}-response"] -==== Delete expired data response - -The returned +{response}+ object indicates the acknowledgement of the request: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] ---------------------------------------------------- -<1> `getDeleted` acknowledges the deletion request. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-filter.asciidoc b/docs/java-rest/high-level/ml/delete-filter.asciidoc deleted file mode 100644 index 29659f8a51e3..000000000000 --- a/docs/java-rest/high-level/ml/delete-filter.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: delete-filter -:request: DeleteFilterRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete filters API - -Deletes a {ml} filter. -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Delete filters request - -A +{request}+ object requires a non-null `filterId`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new request referencing an existing filter - -[id="{upid}-{api}-response"] -==== Delete filters response - -The returned +{response}+ object indicates the acknowledgement of the request: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] ---------------------------------------------------- -<1> `isAcknowledged` was the deletion request acknowledged or not - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-forecast.asciidoc b/docs/java-rest/high-level/ml/delete-forecast.asciidoc deleted file mode 100644 index 499967520244..000000000000 --- a/docs/java-rest/high-level/ml/delete-forecast.asciidoc +++ /dev/null @@ -1,51 +0,0 @@ --- -:api: delete-forecast -:request: DeleteForecastRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete forecasts API - -Deletes forecasts from an {anomaly-job}. -It accepts a +{request}+ object and responds -with an +{response}+ object. - -[id="{upid}-{api}-request"] -==== Delete forecasts request - -A +{request}+ object gets created with an existing non-null `jobId`. -All other fields are optional for the request. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId` - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Sets the specific forecastIds to delete, can be set to `_all` to indicate ALL forecasts for the given -`jobId` -<2> Set the timeout for the request to respond, default is 30 seconds -<3> Set the `allow_no_forecasts` option. When `true` no error will be returned if an `_all` -request finds no forecasts. It defaults to `true` - -[id="{upid}-{api}-response"] -==== Delete forecasts response - -An +{response}+ contains an acknowledgement of the forecast(s) deletion - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isAcknowledged()` indicates if the forecast was successfully deleted or not. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-job.asciidoc b/docs/java-rest/high-level/ml/delete-job.asciidoc deleted file mode 100644 index ad4c147c4911..000000000000 --- a/docs/java-rest/high-level/ml/delete-job.asciidoc +++ /dev/null @@ -1,58 +0,0 @@ --- -:api: delete-job -:request: DeleteJobRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete {anomaly-jobs} API - -Deletes an {anomaly-job} that exists in the cluster. - -[id="{upid}-{api}-request"] -==== Delete {anomaly-jobs} request - -A +{request}+ object requires a non-null `jobId` and can optionally set `force`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId` - -==== Optional arguments - -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-force] ---------------------------------------------------- -<1> Use to forcefully delete an opened job. This method is quicker than closing -and deleting the job. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-wait-for-completion] ---------------------------------------------------- -<1> Use to set whether the request should wait until the operation has completed -before returning. Defaults to `true`. - - -[id="{upid}-{api}-response"] -==== Delete {anomaly-jobs} response - -The returned +{response}+ object indicates the acknowledgement of the job -deletion or the deletion task depending on whether the request was set to wait -for completion: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] ---------------------------------------------------- -<1> Whether job deletion was acknowledged or not. It will be `null` when set -to not wait for completion. -<2> The ID of the job deletion task. It will be `null` when set to wait for -completion. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/delete-model-snapshot.asciidoc b/docs/java-rest/high-level/ml/delete-model-snapshot.asciidoc deleted file mode 100644 index a1ad2884bdfb..000000000000 --- a/docs/java-rest/high-level/ml/delete-model-snapshot.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ --- -:api: delete-model-snapshot -:request: DeleteModelSnapshotRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete model snapshots API - -Deletes an existing model snapshot. - -[id="{upid}-{api}-request"] -==== Delete model snapshots request - -A +{request}+ object requires both a non-null `jobId` and a non-null `snapshotId`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new request referencing existing `jobId` and `snapshotId`. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete model snapshots response - -The returned +{response}+ object indicates the acknowledgement of the request: -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] ---------------------------------------------------- -<1> `isAcknowledged` was the deletion request acknowledged or not diff --git a/docs/java-rest/high-level/ml/delete-trained-model-alias.asciidoc b/docs/java-rest/high-level/ml/delete-trained-model-alias.asciidoc deleted file mode 100644 index dbd237e5c681..000000000000 --- a/docs/java-rest/high-level/ml/delete-trained-model-alias.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: delete-trained-model-alias -:request: DeleteTrainedModelAliasRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete trained model alias API - - -Deletes a trained model alias. -The API accepts a +{request}+ object as a request and returns a +{response}+. -If the model alias is not assigned to the provided model id, or if the model -alias does not exist, this API will result in an error. - -[id="{upid}-{api}-request"] -==== Delete trained model alias request - -A +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The trained model alias to delete -<2> The trained model id to which model alias is assigned - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/delete-trained-models.asciidoc b/docs/java-rest/high-level/ml/delete-trained-models.asciidoc deleted file mode 100644 index be741304f84b..000000000000 --- a/docs/java-rest/high-level/ml/delete-trained-models.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: delete-trained-models -:request: DeleteTrainedModelRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete trained models API - - -Deletes a previously saved trained model. -The API accepts a +{request}+ object and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Delete trained models request - -A +{request}+ requires a valid trained model ID. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new DELETE request referencing an existing trained model - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ object acknowledges the trained model deletion. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/estimate-model-memory.asciidoc b/docs/java-rest/high-level/ml/estimate-model-memory.asciidoc deleted file mode 100644 index 8e8b5f1befa3..000000000000 --- a/docs/java-rest/high-level/ml/estimate-model-memory.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ --- -:api: estimate-model-memory -:request: EstimateModelMemoryRequest -:response: EstimateModelMemoryResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Estimate {anomaly-job} model memory API - -Estimate the model memory an analysis config is likely to need for -the given cardinality of the fields it references. - -[id="{upid}-{api}-request"] -==== Estimate {anomaly-job} model memory request - -A +{request}+ can be set up as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Pass an `AnalysisConfig` to the constructor. -<2> For any `by_field_name`, `over_field_name` or - `partition_field_name` fields referenced by the - detectors, supply overall cardinality estimates - in a `Map`. -<3> For any `influencers`, supply a `Map` containing - estimates of the highest cardinality expected in - any single bucket. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Estimate {anomaly-job} model memory response - -The returned +{response}+ contains the model memory estimate: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The model memory estimate. diff --git a/docs/java-rest/high-level/ml/evaluate-data-frame.asciidoc b/docs/java-rest/high-level/ml/evaluate-data-frame.asciidoc deleted file mode 100644 index 6c1985c5d49e..000000000000 --- a/docs/java-rest/high-level/ml/evaluate-data-frame.asciidoc +++ /dev/null @@ -1,138 +0,0 @@ --- -:api: evaluate-data-frame -:request: EvaluateDataFrameRequest -:response: EvaluateDataFrameResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Evaluate {dfanalytics} API - - -Evaluates the {dfanalytics} for an annotated index. -The API accepts an +{request}+ object and returns an +{response}+. - -[id="{upid}-{api}-request"] -==== Evaluate {dfanalytics} request - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new evaluation request -<2> Reference to an existing index -<3> The query with which to select data from indices -<4> Evaluation to be performed - -==== Evaluation - -Evaluation to be performed. -Currently, supported evaluations include: +OutlierDetection+, +Classification+, +Regression+. - -===== Outlier detection - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-evaluation-outlierdetection] --------------------------------------------------- -<1> Constructing a new evaluation -<2> Name of the field in the index. Its value denotes the actual (i.e. ground truth) label for an example. Must be either true or false. -<3> Name of the field in the index. Its value denotes the probability (as per some ML algorithm) of the example being classified as positive. -<4> The remaining parameters are the metrics to be calculated based on the two fields described above -<5> {wikipedia}/Precision_and_recall#Precision[Precision] calculated at thresholds: 0.4, 0.5 and 0.6 -<6> {wikipedia}/Precision_and_recall#Recall[Recall] calculated at thresholds: 0.5 and 0.7 -<7> {wikipedia}/Confusion_matrix[Confusion matrix] calculated at threshold 0.5 -<8> {wikipedia}/Receiver_operating_characteristic#Area_under_the_curve[AuC ROC] calculated and the curve points returned - -===== Classification - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-evaluation-classification] --------------------------------------------------- -<1> Constructing a new evaluation -<2> Name of the field in the index. Its value denotes the actual (i.e. ground truth) class the example belongs to. -<3> Name of the field in the index. Its value denotes the predicted (as per some ML algorithm) class of the example. -<4> Name of the field in the index. Its value denotes the array of top classes. Must be nested. -<5> The remaining parameters are the metrics to be calculated based on the two fields described above -<6> Accuracy -<7> Precision -<8> Recall -<9> Multiclass confusion matrix of size 3 -<10> {wikipedia}/Receiver_operating_characteristic#Area_under_the_curve[AuC ROC] calculated for class "cat" treated as positive and the rest as negative - -===== Regression - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-evaluation-regression] --------------------------------------------------- -<1> Constructing a new evaluation -<2> Name of the field in the index. Its value denotes the actual (i.e. ground truth) value for an example. -<3> Name of the field in the index. Its value denotes the predicted (as per some ML algorithm) value for the example. -<4> The remaining parameters are the metrics to be calculated based on the two fields described above -<5> {wikipedia}/Mean_squared_error[Mean squared error] -<6> Mean squared logarithmic error -<7> {wikipedia}/Huber_loss#Pseudo-Huber_loss_function[Pseudo Huber loss] -<8> {wikipedia}/Coefficient_of_determination[R squared] - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the requested evaluation metrics. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Fetching all the calculated metrics results - -==== Results - -===== Outlier detection - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-results-outlierdetection] --------------------------------------------------- - -<1> Fetching precision metric by name -<2> Fetching precision at a given (0.4) threshold -<3> Fetching confusion matrix metric by name -<4> Fetching confusion matrix at a given (0.5) threshold - -===== Classification - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-results-classification] --------------------------------------------------- - -<1> Fetching accuracy metric by name -<2> Fetching the actual accuracy value -<3> Fetching precision metric by name -<4> Fetching the actual precision value -<5> Fetching recall metric by name -<6> Fetching the actual recall value -<7> Fetching multiclass confusion matrix metric by name -<8> Fetching the contents of the confusion matrix -<9> Fetching the number of classes that were not included in the matrix -<10> Fetching AucRoc metric by name -<11> Fetching the actual AucRoc score - -===== Regression - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-results-regression] --------------------------------------------------- - -<1> Fetching mean squared error metric by name -<2> Fetching the actual mean squared error value -<3> Fetching mean squared logarithmic error metric by name -<4> Fetching the actual mean squared logarithmic error value -<5> Fetching pseudo Huber loss metric by name -<6> Fetching the actual pseudo Huber loss value -<7> Fetching R squared metric by name -<8> Fetching the actual R squared value diff --git a/docs/java-rest/high-level/ml/explain-data-frame-analytics.asciidoc b/docs/java-rest/high-level/ml/explain-data-frame-analytics.asciidoc deleted file mode 100644 index 8bd734ba94e0..000000000000 --- a/docs/java-rest/high-level/ml/explain-data-frame-analytics.asciidoc +++ /dev/null @@ -1,49 +0,0 @@ --- -:api: explain-data-frame-analytics -:request: ExplainDataFrameAnalyticsRequest -:response: ExplainDataFrameAnalyticsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Explain {dfanalytics} API - - -Explains the following about a {dataframe-analytics-config}: - -* field selection: which fields are included or not in the analysis -* memory estimation: how much memory is estimated to be required. The estimate can be used when deciding the appropriate value for `model_memory_limit` setting later on. - -The API accepts an +{request}+ object and returns an +{response}+. - -[id="{upid}-{api}-request"] -==== Explain {dfanalytics} request - -The request can be constructed with the id of an existing {dfanalytics-job}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-id-request] --------------------------------------------------- -<1> Constructing a new request with the id of an existing {dfanalytics-job} - -It can also be constructed with a {dataframe-analytics-config} to explain it before creating it. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-request] --------------------------------------------------- -<1> Constructing a new request containing a {dataframe-analytics-config} - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the field selection and the memory usage estimation. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> A list where each item explains whether a field was selected for analysis or not -<2> The memory estimation for the {dfanalytics-job} diff --git a/docs/java-rest/high-level/ml/flush-job.asciidoc b/docs/java-rest/high-level/ml/flush-job.asciidoc deleted file mode 100644 index cc2dd11268c9..000000000000 --- a/docs/java-rest/high-level/ml/flush-job.asciidoc +++ /dev/null @@ -1,56 +0,0 @@ --- -:api: flush-job -:request: FlushJobRequest -:response: FlushJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Flush jobs API - -Flushes an anomaly detection job's datafeed in the cluster. -It accepts a +{request}+ object and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Flush jobs request - -A +{request}+ object gets created with an existing non-null `jobId`. -All other fields are optional for the request. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId` - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Set request to calculate the interim results -<2> Set the advanced time to flush to the particular time value -<3> Set the start time for the range of buckets on which -to calculate the interim results (requires `calc_interim` to be `true`) -<4> Set the end time for the range of buckets on which -to calculate interim results (requires `calc_interim` to be `true`) -<5> Set the skip time to skip a particular time value - -[id="{upid}-{api}-response"] -==== Flush jobs response - -A +{response}+ contains an acknowledgement and an optional end date for the -last finalized bucket - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isFlushed()` indicates if the job was successfully flushed or not. -<2> `getLastFinalizedBucketEnd()` provides the timestamp -(in milliseconds-since-the-epoch) of the end of the last bucket that was processed. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/forecast-job.asciidoc b/docs/java-rest/high-level/ml/forecast-job.asciidoc deleted file mode 100644 index 3cd4a263c5ca..000000000000 --- a/docs/java-rest/high-level/ml/forecast-job.asciidoc +++ /dev/null @@ -1,52 +0,0 @@ --- -:api: forecast-job -:request: ForecastJobRequest -:response: ForecastJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Forecast jobs API - -Forecasts a {ml} job's behavior based on historical data. It accepts a -+{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Forecast jobs request - -A +{request}+ object gets created with an existing non-null `jobId`. -All other fields are optional for the request. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId` - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Set when the forecast for the job should expire -<2> Set how far into the future should the forecast predict -<3> Set the maximum amount of memory the forecast is allowed to use. - Defaults to 20mb. Maximum is 500mb, minimum is 1mb. If set to - 40% or more of the job's configured memory limit, it is - automatically reduced to below that number. - -[id="{upid}-{api}-response"] -==== Forecast jobs response - -A +{response}+ contains an acknowledgement and the forecast ID - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isAcknowledged()` indicates if the forecast was successful -<2> `getForecastId()` provides the ID of the forecast that was created - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/get-buckets.asciidoc b/docs/java-rest/high-level/ml/get-buckets.asciidoc deleted file mode 100644 index 14c9406969e1..000000000000 --- a/docs/java-rest/high-level/ml/get-buckets.asciidoc +++ /dev/null @@ -1,95 +0,0 @@ --- -:api: get-buckets -:request: GetBucketsRequest -:response: GetBucketsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get buckets API - -Retrieves one or more bucket results. -It accepts a +{request}+ object and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get buckets request - -A +{request}+ object gets created with an existing non-null `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId`. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-timestamp] --------------------------------------------------- -<1> The timestamp of the bucket to get. Otherwise it will return all buckets. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-anomaly-score] --------------------------------------------------- -<1> Buckets with anomaly scores greater or equal than this value will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-desc] --------------------------------------------------- -<1> If `true`, the buckets are sorted in descending order. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-end] --------------------------------------------------- -<1> Buckets with timestamps earlier than this time will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-exclude-interim] --------------------------------------------------- -<1> If `true`, interim results will be excluded. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-expand] --------------------------------------------------- -<1> If `true`, buckets will include their anomaly records. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of buckets to skip. -`size` specifies the maximum number of buckets to get. Defaults to `0` and `100` respectively. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-sort] --------------------------------------------------- -<1> The field to sort buckets on. Defaults to `timestamp`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-start] --------------------------------------------------- -<1> Buckets with timestamps on or after this time will be returned. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get buckets response - -The returned +{response}+ contains the requested buckets: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of buckets that were matched. -<2> The buckets retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-calendar-events.asciidoc b/docs/java-rest/high-level/ml/get-calendar-events.asciidoc deleted file mode 100644 index 0a687517431c..000000000000 --- a/docs/java-rest/high-level/ml/get-calendar-events.asciidoc +++ /dev/null @@ -1,67 +0,0 @@ --- -:api: get-calendar-events -:request: GetCalendarEventsRequest -:response: GetCalendarEventsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get calendar events API - -Retrieves a calendar's events. -It accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get calendar events request - -A +{request}+ requires a non-null calendar ID. -Using the literal `_all` returns the events for all calendars. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request for the specified calendarId. - -==== Optional arguments -The following arguments are optional: - - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of events to skip. -`size` specifies the maximum number of events to get. Defaults to `0` and `100` respectively. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-start] --------------------------------------------------- -<1> Specifies to get events with timestamps after this time. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-end] --------------------------------------------------- -<1> Specifies to get events with timestamps earlier than this time. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-jobid] --------------------------------------------------- -<1> Get events for the job. When this option is used calendar_id must be `_all`. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get calendar events response - -The returned +{response}+ contains the requested events: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of events that were matched. -<2> The events retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-calendars.asciidoc b/docs/java-rest/high-level/ml/get-calendars.asciidoc deleted file mode 100644 index a2e30ce9394e..000000000000 --- a/docs/java-rest/high-level/ml/get-calendars.asciidoc +++ /dev/null @@ -1,56 +0,0 @@ --- -:api: get-calendars -:request: GetCalendarsRequest -:response: GetCalendarsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get calendars API - -Retrieves one or more calendar objects. -It accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get calendars request - -By default, a +{request}+ with no calendar ID set will return all -calendars. Using the literal `_all` also returns all calendars. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request for all calendars. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-id] --------------------------------------------------- -<1> Construct a request for the single calendar `holidays`. - - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of -calendars to skip. `size` specifies the maximum number of calendars to get. -Defaults to `0` and `100` respectively. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get calendars response - -The returned +{response}+ contains the requested calendars: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of calendars that were matched. -<2> The calendars retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-categories.asciidoc b/docs/java-rest/high-level/ml/get-categories.asciidoc deleted file mode 100644 index bcb5ed892536..000000000000 --- a/docs/java-rest/high-level/ml/get-categories.asciidoc +++ /dev/null @@ -1,53 +0,0 @@ --- -:api: get-categories -:request: GetCategoriesRequest -:response: GetCategoriesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get categories API - -Retrieves one or more category results. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get categories request - -A +{request}+ object gets created with an existing non-null `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId`. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-category-id] --------------------------------------------------- -<1> The ID of the category to get. Otherwise, it will return all categories. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of -categories to skip. `size` specifies the maximum number of categories to get. -Defaults to `0` and `100` respectively. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get categories response - -The returned +{response}+ contains the requested categories: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of categories that were matched. -<2> The categories retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-data-frame-analytics-stats.asciidoc b/docs/java-rest/high-level/ml/get-data-frame-analytics-stats.asciidoc deleted file mode 100644 index 1b75a3b2bca7..000000000000 --- a/docs/java-rest/high-level/ml/get-data-frame-analytics-stats.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: get-data-frame-analytics-stats -:request: GetDataFrameAnalyticsStatsRequest -:response: GetDataFrameAnalyticsStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get {dfanalytics-jobs} stats API - - -Retrieves the operational statistics of one or more {dfanalytics-jobs}. -The API accepts a +{request}+ object and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Get {dfanalytics-jobs} stats request - -A +{request}+ requires either a {dfanalytics-job} ID, a comma-separated list of -IDs, or the special wildcard `_all` to get the statistics for all -{dfanalytics-jobs}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new GET stats request referencing an existing -{dfanalytics-job} - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the requested {dfanalytics-job} statistics. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-data-frame-analytics.asciidoc b/docs/java-rest/high-level/ml/get-data-frame-analytics.asciidoc deleted file mode 100644 index 70857e4c8085..000000000000 --- a/docs/java-rest/high-level/ml/get-data-frame-analytics.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: get-data-frame-analytics -:request: GetDataFrameAnalyticsRequest -:response: GetDataFrameAnalyticsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get {dfanalytics-jobs} API - - -Retrieves one or more {dfanalytics-jobs}. -The API accepts a +{request}+ object and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Get {dfanalytics-jobs} request - -A +{request}+ requires either a {dfanalytics-job} ID, a comma-separated list of -IDs, or the special wildcard `_all` to get all {dfanalytics-jobs}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new GET request referencing an existing {dfanalytics-job} -<2> Optional boolean value for requesting the {dfanalytics-job} in a format that can -then be put into another cluster. Certain fields that can only be set when -the {dfanalytics-job} is created are removed. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the requested {dfanalytics-jobs}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/get-datafeed-stats.asciidoc b/docs/java-rest/high-level/ml/get-datafeed-stats.asciidoc deleted file mode 100644 index 160550981623..000000000000 --- a/docs/java-rest/high-level/ml/get-datafeed-stats.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: get-datafeed-stats -:request: GetDatafeedStatsRequest -:response: GetDatafeedStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get datafeed stats API - -Retrieves any number of {ml} datafeeds' statistics in the cluster. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get datafeed stats request - -A +{request}+ object can have any number of `datafeedId` entries. However, they -all must be non-null. An empty list is the same as requesting statistics for all -datafeeds. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing `datafeedIds`. It can -contain wildcards. -<2> Whether to ignore if a wildcard expression matches no datafeeds. - (This includes `_all` string or when no datafeeds have been specified). - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get datafeed stats response -The returned +{response}+ contains the requested datafeed statistics: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `count()` indicates the number of datafeeds statistics found. -<2> `datafeedStats()` is the collection of {ml} `DatafeedStats` objects found. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-datafeed.asciidoc b/docs/java-rest/high-level/ml/get-datafeed.asciidoc deleted file mode 100644 index c8383dcdaaa7..000000000000 --- a/docs/java-rest/high-level/ml/get-datafeed.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ --- -:api: get-datafeed -:request: GetDatafeedRequest -:response: GetDatafeedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get datafeeds API - -Retrieves configuration information about {ml} datafeeds in the cluster. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get datafeeds request - -A +{request}+ object gets can have any number of `datafeedId` entries. However, -they all must be non-null. An empty list is the same as requesting for all -datafeeds. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing `datafeedIds`. It can -contain wildcards. -<2> Whether to ignore if a wildcard expression matches no datafeeds. - (This includes `_all` string or when no datafeeds have been specified). -<3> Optional boolean value for requesting the datafeed in a format that can -then be put into another cluster. Certain fields that can only be set when -the datafeed is created are removed. - -[id="{upid}-{api}-response"] -==== Get datafeeds response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of retrieved datafeeds. -<2> The retrieved datafeeds. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/get-filters.asciidoc b/docs/java-rest/high-level/ml/get-filters.asciidoc deleted file mode 100644 index 5d33e1e2d198..000000000000 --- a/docs/java-rest/high-level/ml/get-filters.asciidoc +++ /dev/null @@ -1,52 +0,0 @@ --- -:api: get-filters -:request: GetFiltersRequest -:response: GetFiltersResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get filters API - -Retrieves one or more filter results. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get filters request - -A +{request}+ object gets created. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-filter-id] --------------------------------------------------- -<1> The ID of the filter to get. Otherwise, it will return all filters. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page-params] --------------------------------------------------- -<1> `from` specifies the number of filters to skip. Defaults to `0`. -<2> `size` specifies the maximum number of filters to get. Defaults to `100`. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get filters response - -The returned +{response}+ contains the requested filters: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of filters that were matched. -<2> The filters retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-influencers.asciidoc b/docs/java-rest/high-level/ml/get-influencers.asciidoc deleted file mode 100644 index 9096a1039113..000000000000 --- a/docs/java-rest/high-level/ml/get-influencers.asciidoc +++ /dev/null @@ -1,84 +0,0 @@ --- -:api: get-influencers -:request: GetInfluencersRequest -:response: GetInfluencersResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get influencers API - -Retrieves one or more influencer results. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get influencers request - -A +{request}+ object gets created with an existing non-null `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId`. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-desc] --------------------------------------------------- -<1> If `true`, the influencers are sorted in descending order. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-end] --------------------------------------------------- -<1> Influencers with timestamps earlier than this time will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-exclude-interim] --------------------------------------------------- -<1> If `true`, interim results will be excluded. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-influencer-score] --------------------------------------------------- -<1> Influencers with `influencer_score` greater than or equal to this value will -be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of -influencers to skip. `size` specifies the maximum number of influencers to get. -Defaults to `0` and `100` respectively. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-sort] --------------------------------------------------- -<1> The field to sort influencers on. Defaults to `influencer_score`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-start] --------------------------------------------------- -<1> Influencers with timestamps on or after this time will be returned. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get influencers response - -The returned +{response}+ contains the requested influencers: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of influencers that were matched. -<2> The influencers retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-info.asciidoc b/docs/java-rest/high-level/ml/get-info.asciidoc deleted file mode 100644 index 662a007f293a..000000000000 --- a/docs/java-rest/high-level/ml/get-info.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: get-ml-info -:request: MlInfoRequest -:response: MlInfoResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get {ml} info API - -Provides defaults and limits used internally by {ml}. -These may be useful to a user interface that needs to interpret machine learning -configurations where certain fields are missing because the end user was happy -with the default value. - -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get {ml} info request - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request. - -[id="{upid}-{api}-response"] -==== Get {ml} info response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `info` from the +{response}+ contains {ml} info details. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/get-job-stats.asciidoc b/docs/java-rest/high-level/ml/get-job-stats.asciidoc deleted file mode 100644 index cc391cace7fd..000000000000 --- a/docs/java-rest/high-level/ml/get-job-stats.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: get-job-stats -:request: GetJobStatsRequest -:response: GetJobStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get {anomaly-job} stats API - -Retrieves statistics for any number of {anomaly-jobs} in the cluster. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get {anomaly-job} stats request - -A `GetJobsStatsRequest` object can have any number of `jobId` -entries. However, they all must be non-null. An empty list is the same as -requesting statistics for all {anomaly-jobs}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing `jobIds`. It can contain -wildcards. -<2> Whether to ignore if a wildcard expression matches no {anomaly-jobs}. - (This includes `_all` string or when no jobs have been specified). - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get {anomaly-job} stats response -The returned +{response}+ contains the requested job statistics: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `getCount()` indicates the number of jobs statistics found. -<2> `getJobStats()` is the collection of {ml} `JobStats` objects found. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-job.asciidoc b/docs/java-rest/high-level/ml/get-job.asciidoc deleted file mode 100644 index e42995edcf8d..000000000000 --- a/docs/java-rest/high-level/ml/get-job.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ --- -:api: get-job -:request: GetJobRequest -:response: GetJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get {anomaly-jobs} API - -Retrieves configuration information for {anomaly-jobs} in the cluster. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get {anomaly-jobs} request - -A +{request}+ object gets can have any number of `jobId` or `groupName` -entries. However, they all must be non-null. An empty list is the same as -requesting for all {anomaly-jobs}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing `jobIds`. It can contain -wildcards. -<2> Whether to ignore if a wildcard expression matches no {anomaly-jobs}. - (This includes `_all` string or when no jobs have been specified). -<3> Optional boolean value for requesting the job in a format that can -then be put into another cluster. Certain fields that can only be set when -the job is created are removed. - -[id="{upid}-{api}-response"] -==== Get {anomaly-jobs} response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `getCount()` from the +{response}+ indicates the number of jobs found. -<2> `getJobs()` is the collection of {ml} `Job` objects found. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/get-model-snapshots.asciidoc b/docs/java-rest/high-level/ml/get-model-snapshots.asciidoc deleted file mode 100644 index d0cc7a3887fc..000000000000 --- a/docs/java-rest/high-level/ml/get-model-snapshots.asciidoc +++ /dev/null @@ -1,77 +0,0 @@ --- -:api: get-model-snapshots -:request: GetModelSnapshotsRequest -:response: GetModelSnapshotsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get model snapshots API - -Retrieves one or more model snapshot results. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get model snapshots request - -A +{request}+ object gets created with an existing non-null `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId`. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-snapshot-id] --------------------------------------------------- -<1> The ID of the snapshot to get. Otherwise, it will return all snapshots. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-desc] --------------------------------------------------- -<1> If `true`, the snapshots are sorted in descending order. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-end] --------------------------------------------------- -<1> Snapshots with timestamps earlier than this time will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-sort] --------------------------------------------------- -<1> The field to sort snapshots on. Defaults to `timestamp`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-start] --------------------------------------------------- -<1> Snapshots with timestamps on or after this time will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of -snapshots to skip. `size` specifies the maximum number of snapshots to retrieve. -Defaults to `0` and `100` respectively. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get model snapshots response - -The returned +{response}+ contains the requested snapshots: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of snapshots that were matched. -<2> The snapshots retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-overall-buckets.asciidoc b/docs/java-rest/high-level/ml/get-overall-buckets.asciidoc deleted file mode 100644 index 4fd7b806345f..000000000000 --- a/docs/java-rest/high-level/ml/get-overall-buckets.asciidoc +++ /dev/null @@ -1,82 +0,0 @@ --- -:api: get-overall-buckets -:request: GetOverallBucketsRequest -:response: GetOverallBucketsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get overall buckets API - -Retrieves overall bucket results that summarize the bucket results of multiple -{anomaly-jobs}. -It accepts a +{request}+ object and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get overall buckets request - -A +{request}+ object gets created with one or more `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing job IDs `jobId1` and `jobId2`. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-bucket-span] --------------------------------------------------- -<1> The span of the overall buckets. Must be greater or equal to the jobs' -largest `bucket_span`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-end] --------------------------------------------------- -<1> Overall buckets with timestamps earlier than this time will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-exclude-interim] --------------------------------------------------- -<1> If `true`, interim results will be excluded. Overall buckets are interim if -any of the job buckets within the overall bucket interval are interim. Defaults -to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-overall-score] --------------------------------------------------- -<1> Overall buckets with overall scores greater or equal than this value will be -returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-start] --------------------------------------------------- -<1> Overall buckets with timestamps on or after this time will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-top-n] --------------------------------------------------- -<1> The number of top job bucket scores to be used in the `overall_score` -calculation. Defaults to `1`. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get overall buckets response - -The returned +{response}+ contains the requested buckets: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of overall buckets that were matched. -<2> The overall buckets retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-records.asciidoc b/docs/java-rest/high-level/ml/get-records.asciidoc deleted file mode 100644 index cd71345b2ca8..000000000000 --- a/docs/java-rest/high-level/ml/get-records.asciidoc +++ /dev/null @@ -1,83 +0,0 @@ --- -:api: get-records -:request: GetRecordsRequest -:response: GetRecordsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get records API - -Retrieves one or more record results. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Get records request - -A +{request}+ object gets created with an existing non-null `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId`. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-desc] --------------------------------------------------- -<1> If `true`, the records are sorted in descending order. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-end] --------------------------------------------------- -<1> Records with timestamps earlier than this time will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-exclude-interim] --------------------------------------------------- -<1> If `true`, interim results will be excluded. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-page] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of -records to skip. `size` specifies the maximum number of records to get. Defaults -to `0` and `100` respectively. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-record-score] --------------------------------------------------- -<1> Records with record_score greater or equal than this value will be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-sort] --------------------------------------------------- -<1> The field to sort records on. Defaults to `record_score`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-start] --------------------------------------------------- -<1> Records with timestamps on or after this time will be returned. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get records response - -The returned +{response}+ contains the requested records: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The count of records that were matched. -<2> The records retrieved. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/get-trained-models-stats.asciidoc b/docs/java-rest/high-level/ml/get-trained-models-stats.asciidoc deleted file mode 100644 index 2ee647976a53..000000000000 --- a/docs/java-rest/high-level/ml/get-trained-models-stats.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ --- -:api: get-trained-models-stats -:request: GetTrainedModelsStatsRequest -:response: GetTrainedModelsStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get trained models stats API - - -Retrieves one or more trained model statistics. -The API accepts a +{request}+ object and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Get trained models stats request - -A +{request}+ requires either a trained model ID, a comma-separated list of -IDs, or the special wildcard `_all` to get stats for all trained models. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new GET request referencing an existing Trained Model -<2> Set the paging parameters -<3> Allow empty response if no trained models match the provided ID patterns. - If false, an error will be thrown if no trained models match the - ID patterns. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the statistics -for the requested trained model. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/get-trained-models.asciidoc b/docs/java-rest/high-level/ml/get-trained-models.asciidoc deleted file mode 100644 index db2e6b0120da..000000000000 --- a/docs/java-rest/high-level/ml/get-trained-models.asciidoc +++ /dev/null @@ -1,52 +0,0 @@ --- -:api: get-trained-models -:request: GetTrainedModelsRequest -:response: GetTrainedModelsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get trained models API - - -Retrieves one or more trained models. -The API accepts a +{request}+ object and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Get trained models request - -A +{request}+ requires either a trained model ID, a comma-separated list of -IDs, or the special wildcard `_all` to get all trained models. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new GET request referencing an existing trained model. -<2> Set the paging parameters. -<3> Indicate if the complete model definition should be included. -<4> Indicate if the total feature importance for the features used in training - should is included in the metadata. -<5> Indicate if the feature importance baselines that were used in training are - included in the metadata. -<6> Should the definition be fully decompressed on GET. -<7> Allow empty response if no trained models match the provided ID patterns. - If false, an error will be thrown if no trained models match the - ID patterns. -<8> An optional list of tags used to narrow the model search. A trained model - can have many tags or none. The trained models in the response will - contain all the provided tags. -<9> Optional boolean value for requesting the trained model in a format that can - then be put into another cluster. Certain fields that can only be set when - the model is imported are removed. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the requested trained model. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/open-job.asciidoc b/docs/java-rest/high-level/ml/open-job.asciidoc deleted file mode 100644 index d88933b4f8fb..000000000000 --- a/docs/java-rest/high-level/ml/open-job.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ --- -:api: open-job -:request: OpenJobRequest -:response: OpenJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Open {anomaly-jobs} API - -Opens {anomaly-jobs} in the cluster. It accepts a +{request}+ object and -responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Open {anomaly-jobs} request - -An +{request}+ object gets created with an existing non-null `jobId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `jobId` -<2> Optionally setting the `timeout` value for how long the -execution should wait for the job to be opened. - -[id="{upid}-{api}-response"] -==== Open {anomaly-jobs} response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isOpened()` from the +{response}+ is always `true` if the job was -opened successfully. (An exception would be thrown instead if the job -was not opened successfully.) -<2> `getNode()` returns the node that the job was assigned to. If the -job is allowed to open lazily and has not yet been assigned to a node -then an empty string is returned. If `getNode()` returns `null` then -the server is an old version that does not return node information. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/post-calendar-event.asciidoc b/docs/java-rest/high-level/ml/post-calendar-event.asciidoc deleted file mode 100644 index 5baf762362b7..000000000000 --- a/docs/java-rest/high-level/ml/post-calendar-event.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: post-calendar-event -:request: PostCalendarEventRequest -:response: PostCalendarEventResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Post calendar events API - -Adds new ScheduledEvents to an existing {ml} calendar. - -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Post calendar events request - -A +{request}+ is constructed with a calendar ID object -and a non-empty list of scheduled events. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Non-null existing calendar ID -<2> Non-null, non-empty collection of `ScheduledEvent` objects - - -[id="{upid}-{api}-response"] -==== Post calendar events response - -The returned +{response}+ contains the added `ScheduledEvent` objects: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The `ScheduledEvent` objects that were added to the calendar - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/post-data.asciidoc b/docs/java-rest/high-level/ml/post-data.asciidoc deleted file mode 100644 index 84e0200724f4..000000000000 --- a/docs/java-rest/high-level/ml/post-data.asciidoc +++ /dev/null @@ -1,59 +0,0 @@ --- -:api: post-data -:request: PostDataRequest -:response: PostDataResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Post data API - -Posts data to an open {ml} job in the cluster. -It accepts a +{request}+ object and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Post data request - -A +{request}+ object gets created with an existing non-null `jobId` -and the `XContentType` being sent. Individual docs can be added -incrementally via the `PostDataRequest.JsonBuilder#addDoc` method. -These are then serialized and sent in bulk when passed to the +{request}+. - -Alternatively, the serialized bulk content can be set manually, along with its `XContentType` -through one of the other +{request}+ constructors. - -Only `XContentType.JSON` and `XContentType.SMILE` are supported. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Create a new `PostDataRequest.JsonBuilder` object for incrementally adding documents -<2> Add a new document as a `Map` object -<3> Add a new document as a serialized JSON formatted String. -<4> Constructing a new request referencing an opened `jobId`, and a JsonBuilder - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Set the start of the bucket resetting time -<2> Set the end of the bucket resetting time - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Post data response - -A +{response}+ contains current data processing statistics. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `getDataCounts()` a `DataCounts` object containing the current -data processing counts. diff --git a/docs/java-rest/high-level/ml/preview-datafeed.asciidoc b/docs/java-rest/high-level/ml/preview-datafeed.asciidoc deleted file mode 100644 index 657c9f899fa5..000000000000 --- a/docs/java-rest/high-level/ml/preview-datafeed.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ --- -:api: preview-datafeed -:request: PreviewDatafeedRequest -:response: PreviewDatafeedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Preview datafeeds API - -Previews a {ml} datafeed's data in the cluster. It accepts a +{request}+ object -and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Preview datafeeds request - -A +{request}+ object is created referencing a non-null `datafeedId`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `datafeedId` - -[id="{upid}-{api}-response"] -==== Preview datafeeds response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The raw +BytesReference+ of the data preview -<2> A +List>+ that represents the previewed data - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/put-calendar-job.asciidoc b/docs/java-rest/high-level/ml/put-calendar-job.asciidoc deleted file mode 100644 index 3bb3f69344a1..000000000000 --- a/docs/java-rest/high-level/ml/put-calendar-job.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ --- -:api: put-calendar-job -:request: PutCalendarJobRequest -:response: PutCalendarResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Add {anomaly-jobs} to calendar API - -Adds {anomaly-jobs} jobs to an existing {ml} calendar. -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ is constructed referencing a non-null -calendar ID, and JobIDs to which to add to the calendar - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The ID of the calendar to which to add the jobs -<2> The JobIds to add to the calendar - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the updated calendar: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The updated calendar - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/put-calendar.asciidoc b/docs/java-rest/high-level/ml/put-calendar.asciidoc deleted file mode 100644 index 15ad58552115..000000000000 --- a/docs/java-rest/high-level/ml/put-calendar.asciidoc +++ /dev/null @@ -1,37 +0,0 @@ --- -:api: put-calendar -:request: PutCalendarRequest -:response: PutCalendarResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create calendars API - -Creates a new {ml} calendar. -The API accepts a +{request}+ and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ is constructed with a calendar object - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Create a request with the given calendar. - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the created calendar: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The created calendar. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/put-data-frame-analytics.asciidoc b/docs/java-rest/high-level/ml/put-data-frame-analytics.asciidoc deleted file mode 100644 index 54296d3e2f69..000000000000 --- a/docs/java-rest/high-level/ml/put-data-frame-analytics.asciidoc +++ /dev/null @@ -1,189 +0,0 @@ --- -:api: put-data-frame-analytics -:request: PutDataFrameAnalyticsRequest -:response: PutDataFrameAnalyticsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create {dfanalytics-jobs} API - - -Creates a new {dfanalytics-job}. -The API accepts a +{request}+ object as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The configuration of the {dfanalytics-job} to create - -[id="{upid}-{api}-config"] -==== {dfanalytics-cap} configuration - -The `DataFrameAnalyticsConfig` object contains all the details about the {dfanalytics-job} -configuration and contains the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> The {dfanalytics-job} ID -<2> The source index and query from which to gather data -<3> The destination index -<4> The analysis to be performed -<5> The fields to be included in / excluded from the analysis -<6> The memory limit for the model created as part of the analysis process -<7> Optionally, a human-readable description -<8> The maximum number of threads to be used by the analysis. Defaults to 1. - -[id="{upid}-{api}-query-config"] - -==== SourceConfig - -The index and the query from which to collect data. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-config] --------------------------------------------------- -<1> Constructing a new DataFrameAnalyticsSource -<2> The source index -<3> The query from which to gather the data. If query is not set, a `match_all` query is used by default. -<4> Runtime mappings that will be added to the destination index mapping. -<5> Source filtering to select which fields will exist in the destination index. - -===== QueryConfig - -The query with which to select data from the source. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-query-config] --------------------------------------------------- - -==== DestinationConfig - -The index to which data should be written by the {dfanalytics-job}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-dest-config] --------------------------------------------------- -<1> Constructing a new DataFrameAnalyticsDest -<2> The destination index - -==== Analysis - -The analysis to be performed. -Currently, the supported analyses include: +OutlierDetection+, +Classification+, +Regression+. - -===== Outlier detection - -+OutlierDetection+ analysis can be created in one of two ways: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-outlier-detection-default] --------------------------------------------------- -<1> Constructing a new OutlierDetection object with default strategy to determine outliers - -or -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-outlier-detection-customized] --------------------------------------------------- -<1> Constructing a new OutlierDetection object -<2> The method used to perform the analysis -<3> Number of neighbors taken into account during analysis -<4> The min `outlier_score` required to compute feature influence -<5> Whether to compute feature influence -<6> The proportion of the data set that is assumed to be outlying prior to outlier detection -<7> Whether to apply standardization to feature values - -===== Classification - -+Classification+ analysis requires to set which is the +dependent_variable+ and -has a number of other optional parameters: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-classification] --------------------------------------------------- -<1> Constructing a new Classification builder object with the required dependent variable -<2> The lambda regularization parameter. A non-negative double. -<3> The gamma regularization parameter. A non-negative double. -<4> The applied shrinkage. A double in [0.001, 1]. -<5> The maximum number of trees the forest is allowed to contain. An integer in [1, 2000]. -<6> The fraction of features which will be used when selecting a random bag for each candidate split. A double in (0, 1]. -<7> If set, feature importance for the top most important features will be computed. -<8> The name of the prediction field in the results object. -<9> The percentage of training-eligible rows to be used in training. Defaults to 100%. -<10> The seed to be used by the random generator that picks which rows are used in training. -<11> The optimization objective to target when assigning class labels. Defaults to maximize_minimum_recall. -<12> The number of top classes (or -1 which denotes all classes) to be reported in the results. Defaults to 2. -<13> Custom feature processors that will create new features for analysis from the included document - fields. Note, automatic categorical {ml-docs}/ml-feature-encoding.html[feature encoding] still occurs for all features. -<14> The alpha regularization parameter. A non-negative double. -<15> The growth rate of the shrinkage parameter. A double in [0.5, 2.0]. -<16> The soft tree depth limit. A non-negative double. -<17> The soft tree depth tolerance. Controls how much the soft tree depth limit is respected. A double greater than or equal to 0.01. -<18> The amount by which to downsample the data for stochastic gradient estimates. A double in (0, 1.0]. -<19> The maximum number of optimisation rounds we use for hyperparameter optimisation per parameter. An integer in [0, 20]. -<20> Whether to enable early stopping to finish training process if it is not finding better models. - -===== Regression - -+Regression+ analysis requires to set which is the +dependent_variable+ and -has a number of other optional parameters: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-regression] --------------------------------------------------- -<1> Constructing a new Regression builder object with the required dependent variable -<2> The lambda regularization parameter. A non-negative double. -<3> The gamma regularization parameter. A non-negative double. -<4> The applied shrinkage. A double in [0.001, 1]. -<5> The maximum number of trees the forest is allowed to contain. An integer in [1, 2000]. -<6> The fraction of features which will be used when selecting a random bag for each candidate split. A double in (0, 1]. -<7> If set, feature importance for the top most important features will be computed. -<8> The name of the prediction field in the results object. -<9> The percentage of training-eligible rows to be used in training. Defaults to 100%. -<10> The seed to be used by the random generator that picks which rows are used in training. -<11> The loss function used for regression. Defaults to `mse`. -<12> An optional parameter to the loss function. -<13> Custom feature processors that will create new features for analysis from the included document -fields. Note, automatic categorical {ml-docs}/ml-feature-encoding.html[feature encoding] still occurs for all features. -<14> The alpha regularization parameter. A non-negative double. -<15> The growth rate of the shrinkage parameter. A double in [0.5, 2.0]. -<16> The soft tree depth limit. A non-negative double. -<17> The soft tree depth tolerance. Controls how much the soft tree depth limit is respected. A double greater than or equal to 0.01. -<18> The amount by which to downsample the data for stochastic gradient estimates. A double in (0, 1.0]. -<19> The maximum number of optimisation rounds we use for hyperparameter optimisation per parameter. An integer in [0, 20]. -<20> Whether to enable early stopping to finish training process if it is not finding better models. - -==== Analyzed fields - -FetchContext object containing fields to be included in / excluded from the analysis - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-analyzed-fields] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the newly created {dfanalytics-job}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/put-datafeed.asciidoc b/docs/java-rest/high-level/ml/put-datafeed.asciidoc deleted file mode 100644 index 3348bfa441c5..000000000000 --- a/docs/java-rest/high-level/ml/put-datafeed.asciidoc +++ /dev/null @@ -1,112 +0,0 @@ --- -:api: put-datafeed -:request: PutDatafeedRequest -:response: PutDatafeedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create datafeeds API - -Creates a new {ml} datafeed in the cluster. The API accepts a +{request}+ object -as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The configuration of the {ml} datafeed to create. - -[id="{upid}-{api}-config"] -==== Datafeed configuration - -The `DatafeedConfig` object contains all the details about the {ml} datafeed -configuration. - -A `DatafeedConfig` requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> The datafeed ID and the {anomaly-job} ID. -<2> The indices that contain the data to retrieve and feed into the {anomaly-job}. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-chunking-config] --------------------------------------------------- -<1> Specifies how data searches are split into time chunks. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-frequency] --------------------------------------------------- -<1> The interval at which scheduled queries are made while the datafeed runs in -real time. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-query] --------------------------------------------------- -<1> A query to filter the search results by. Defaults to the `match_all` query. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-query-delay] --------------------------------------------------- -<1> The time interval behind real time that data is queried. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-delayed-data-check-config] --------------------------------------------------- -<1> Sets the delayed data check configuration. -The window must be larger than the Job's bucket size, but smaller than 24 hours, -and span less than 10,000 buckets. -Defaults to `null`, which causes an appropriate window span to be calculated when -the datafeed runs. -The default `check_window` span calculation is the max between `2h` or -`8 * bucket_span`. To explicitly disable, pass -`DelayedDataCheckConfig.disabledDelayedDataCheckConfig()`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-script-fields] --------------------------------------------------- -<1> Allows the use of script fields. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-scroll-size] --------------------------------------------------- -<1> The `size` parameter used in the searches. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-set-runtime-mappings] --------------------------------------------------- -<1> The runtime fields used in the datafeed. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ returns the full representation of -the new {ml} datafeed if it has been successfully created. This will -contain the creation time and other fields initialized using -default values: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The created datafeed. diff --git a/docs/java-rest/high-level/ml/put-filter.asciidoc b/docs/java-rest/high-level/ml/put-filter.asciidoc deleted file mode 100644 index 1a8328e6930b..000000000000 --- a/docs/java-rest/high-level/ml/put-filter.asciidoc +++ /dev/null @@ -1,53 +0,0 @@ --- -:api: put-filter -:request: PutFilterRequest -:response: PutFilterResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create filters API - -Creates a new {ml} filter in the cluster. The API accepts a +{request}+ object -as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The configuration of the {ml} filter to create as a `MlFilter` - -[id="{upid}-{api}-config"] -==== Filter configuration - -The `MlFilter` object contains all the details about the {ml} filter -configuration. - -A `MlFilter` contains the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> Required, the filter ID -<2> Optional, the filter description -<3> Optional, the items of the filter. A wildcard * can be used at the beginning or the end of an item. -Up to 10000 items are allowed in each filter. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ returns the full representation of -the new {ml} filter if it has been successfully created. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The newly created `MlFilter` diff --git a/docs/java-rest/high-level/ml/put-job.asciidoc b/docs/java-rest/high-level/ml/put-job.asciidoc deleted file mode 100644 index ee0e0995911f..000000000000 --- a/docs/java-rest/high-level/ml/put-job.asciidoc +++ /dev/null @@ -1,129 +0,0 @@ --- -:api: put-job -:request: PutJobRequest -:response: PutJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create {anomaly-jobs} API - -Creates a new {anomaly-job} in the cluster. The API accepts a +{request}+ object -as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The configuration of the {anomaly-job} to create as a `Job` - -[id="{upid}-{api}-config"] -==== Job configuration - -The `Job` object contains all the details about the {anomaly-job} -configuration. - -A `Job` requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> The job ID -<2> An analysis configuration -<3> A data description -<4> Optionally, a human-readable description - -[id="{upid}-{api}-analysis-config"] -==== Analysis configuration - -The analysis configuration of the {anomaly-job} is defined in the `AnalysisConfig`. -`AnalysisConfig` reflects all the configuration -settings that can be defined using the REST API. - -Using the REST API, we could define this analysis configuration: - -[source,js] --------------------------------------------------- -"analysis_config" : { - "bucket_span" : "10m", - "detectors" : [ - { - "detector_description" : "Sum of total", - "function" : "sum", - "field_name" : "total" - } - ] -} --------------------------------------------------- -// NOTCONSOLE - -Using the `AnalysisConfig` object and the high level REST client, the list -of detectors must be built first. - -An example of building a `Detector` instance is as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-detector] --------------------------------------------------- -<1> The function to use -<2> The field to apply the function to -<3> Optionally, a human-readable description - -Then the same configuration would be: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-analysis-config] --------------------------------------------------- -<1> Create a list of detectors -<2> Pass the list of detectors to the analysis config builder constructor -<3> The bucket span - -[id="{upid}-{api}-data-description"] -==== Data description - -After defining the analysis config, the next thing to define is the -data description, using a `DataDescription` instance. `DataDescription` -reflects all the configuration settings that can be defined using the -REST API. - -Using the REST API, we could define this metrics configuration: - -[source,js] --------------------------------------------------- -"data_description" : { - "time_field" : "timestamp" -} --------------------------------------------------- -// NOTCONSOLE - -Using the `DataDescription` object and the high level REST client, the same -configuration would be: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-data-description] --------------------------------------------------- -<1> The time field - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ returns the full representation of -the new {ml} job if it has been successfully created. This will -contain the creation time and other fields initialized using -default values: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The creation time is a field that was not passed in the `Job` object in the request diff --git a/docs/java-rest/high-level/ml/put-trained-model-alias.asciidoc b/docs/java-rest/high-level/ml/put-trained-model-alias.asciidoc deleted file mode 100644 index cb4e4e440125..000000000000 --- a/docs/java-rest/high-level/ml/put-trained-model-alias.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: put-trained-model-alias -:request: PutTrainedModelAliasRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create or update trained model alias API - - -Creates or reassigns a trained model alias. -The API accepts a +{request}+ object as a request and returns a +{response}+. -The created trained model alias can then be used for other APIs in the stack -instead of the referenced model id. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The trained model alias to create or reassign -<2> The trained model id to which to assign the alias -<3> (Optional) whether or not to reassign the model alias if it -is already pointing to a model. Defaults to false. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/put-trained-model.asciidoc b/docs/java-rest/high-level/ml/put-trained-model.asciidoc deleted file mode 100644 index c1104f7ebaa3..000000000000 --- a/docs/java-rest/high-level/ml/put-trained-model.asciidoc +++ /dev/null @@ -1,59 +0,0 @@ --- -:api: put-trained-model -:request: PutTrainedModelRequest -:response: PutTrainedModelResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create trained models API - - -Creates a new trained model for inference. -The API accepts a +{request}+ object as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The configuration of the {infer} trained model to create - -[id="{upid}-{api}-config"] -==== Trained model configuration - -The `TrainedModelConfig` object contains all the details about the trained model -configuration and contains the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> The {infer} definition for the model -<2> Optionally, if the {infer} definition is large, you may choose to compress it for transport. - Do not supply both the compressed and uncompressed definitions. -<3> The unique model id -<4> The type of model being configured. If not set the type is inferred from the model definition -<5> The input field names for the model definition -<6> Optionally, a human-readable description -<7> Optionally, an object map contain metadata about the model -<8> Optionally, an array of tags to organize the model -<9> The default inference config to use with the model. Must match the underlying - definition target_type. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the newly created trained model. -The +{response}+ will omit the model definition as a precaution against -streaming large model definitions back to the client. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/revert-model-snapshot.asciidoc b/docs/java-rest/high-level/ml/revert-model-snapshot.asciidoc deleted file mode 100644 index b6785299b52d..000000000000 --- a/docs/java-rest/high-level/ml/revert-model-snapshot.asciidoc +++ /dev/null @@ -1,48 +0,0 @@ --- -:api: revert-model-snapshot -:request: RevertModelSnapshotRequest -:response: RevertModelSnapshotResponse --- -[role="xpack"] - -[id="{upid}-{api}"] -=== Revert model snapshots API - -Reverts to a previous {ml} model snapshot. -It accepts a +{request}+ object and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Revert model snapshots request - -A +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing `jobId` and `snapshotId` values. - -==== Optional arguments - -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-delete-intervening-results] --------------------------------------------------- -<1> A flag indicating whether or not results in the period between the timestamp on the reverted snapshot and the latest results should be deleted - - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Revert job response - -A +{response}+ contains the full representation of the reverted `ModelSnapshot`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The reverted `ModelSnapshot` diff --git a/docs/java-rest/high-level/ml/set-upgrade-mode.asciidoc b/docs/java-rest/high-level/ml/set-upgrade-mode.asciidoc deleted file mode 100644 index d19a0d663605..000000000000 --- a/docs/java-rest/high-level/ml/set-upgrade-mode.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ --- -:api: set-upgrade-mode -:request: SetUpgradeModeRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Set upgrade mode API - -Temporarily halts all {ml} job and {dfeed} tasks when `enabled=true`. Their -reported states remain unchanged. Consequently, when exiting upgrade mode the halted {ml} jobs and -{dfeeds} will return to their previous state. - -It accepts a +{request}+ object and responds with a +{response}+ object. - -When `enabled=true`, no new jobs can be opened, and no job or {dfeed} tasks will -be running. Be sure to set `enabled=false` once upgrade actions are completed. - -[id="{upid}-{api}-request"] -==== Set upgrade mode request - -A +{request}+ object gets created setting the desired `enabled` state. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing enabling upgrade mode -<2> Optionally setting the `timeout` value for how long the -execution should wait. - -[id="{upid}-{api}-response"] -==== Set upgrade mode response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isAcknowledged()` from the +{response}+ indicates if the setting was set successfully. - -include::../execution.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/start-data-frame-analytics.asciidoc b/docs/java-rest/high-level/ml/start-data-frame-analytics.asciidoc deleted file mode 100644 index 1c97b52c52c7..000000000000 --- a/docs/java-rest/high-level/ml/start-data-frame-analytics.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: start-data-frame-analytics -:request: StartDataFrameAnalyticsRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Start {dfanalytics-jobs} API - - -Starts an existing {dfanalytics-job}. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Start {dfanalytics-jobs} request - -A +{request}+ object requires a {dfanalytics-job} ID. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new start request referencing an existing {dfanalytics-job} - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Start {dfanalytics-jobs} response - -The returned +{response}+ object acknowledges the {dfanalytics-job} has started. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `getNode()` returns the node that the job was assigned to. If the -job is allowed to open lazily and has not yet been assigned to a node -then an empty string is returned. If `getNode()` returns `null` then -the server is an old version that does not return node information. diff --git a/docs/java-rest/high-level/ml/start-datafeed.asciidoc b/docs/java-rest/high-level/ml/start-datafeed.asciidoc deleted file mode 100644 index a54695bf821f..000000000000 --- a/docs/java-rest/high-level/ml/start-datafeed.asciidoc +++ /dev/null @@ -1,58 +0,0 @@ --- -:api: start-datafeed -:request: StartDatafeedRequest -:response: StartDatafeedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Start {dfeeds} API - -Starts a {ml} {dfeed} in the cluster. It accepts a +{request}+ object and -responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Start {dfeeds} request - -A +{request}+ object is created referencing a non-null `datafeedId`. -All other fields are optional for the request. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing an existing `datafeedId`. - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Set when the {dfeed} should end, the value is exclusive. -May be an epoch seconds, epoch millis or an ISO 8601 string. -"now" is a special value that indicates the current time. -If you do not specify an end time, the {dfeed} runs continuously. -<2> Set when the {dfeed} should start, the value is inclusive. -May be an epoch seconds, epoch millis or an ISO 8601 string. -If you do not specify a start time and the {dfeed} is associated with a new job, -the analysis starts from the earliest time for which data is available. -<3> Set the timeout for the request - -[id="{upid}-{api}-response"] -==== Start {dfeeds} response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `isStarted()` from the +{response}+ is always `true` if the {dfeed} was -started successfully. (An exception would be thrown instead if the {dfeed} -was not started successfully.) -<2> `getNode()` returns the node that the {dfeed} was assigned to. If the -{dfeed} is allowed to open lazily and has not yet been assigned to a node -then an empty string is returned. If `getNode()` returns `null` then -the server is an old version that does not return node information. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/ml/stop-data-frame-analytics.asciidoc b/docs/java-rest/high-level/ml/stop-data-frame-analytics.asciidoc deleted file mode 100644 index 069244a14172..000000000000 --- a/docs/java-rest/high-level/ml/stop-data-frame-analytics.asciidoc +++ /dev/null @@ -1,31 +0,0 @@ --- -:api: stop-data-frame-analytics -:request: StopDataFrameAnalyticsRequest -:response: StopDataFrameAnalyticsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Stop {dfanalytics-jobs} API - - -Stops a running {dfanalytics-job}. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Stop {dfanalytics-jobs} request - -A +{request}+ object requires a {dfanalytics-job} ID. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new stop request referencing an existing {dfanalytics-job} -<2> Optionally used to stop a failed task - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ object acknowledges the {dfanalytics-job} has stopped. \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/stop-datafeed.asciidoc b/docs/java-rest/high-level/ml/stop-datafeed.asciidoc deleted file mode 100644 index 8b94bea8713e..000000000000 --- a/docs/java-rest/high-level/ml/stop-datafeed.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: stop-datafeed -:request: StopDatafeedRequest -:response: StopDatafeedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Stop datafeeds API - -Stops a {ml} datafeed in the cluster. -It accepts a +{request}+ object and responds -with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Stop datafeeds request - -A +{request}+ object is created referencing any number of non-null `datafeedId` entries. -Wildcards and `_all` are also accepted. -All other fields are optional for the request. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing `datafeedId` entries. - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string) -<2> If true, the datafeed is stopped forcefully. -<3> Controls the amount of time to wait until a datafeed stops. The default value is 20 seconds. - -include::../execution.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/high-level/ml/update-data-frame-analytics.asciidoc b/docs/java-rest/high-level/ml/update-data-frame-analytics.asciidoc deleted file mode 100644 index 3d20ec38552f..000000000000 --- a/docs/java-rest/high-level/ml/update-data-frame-analytics.asciidoc +++ /dev/null @@ -1,53 +0,0 @@ --- -:api: update-data-frame-analytics -:request: UpdateDataFrameAnalyticsRequest -:response: UpdateDataFrameAnalyticsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Update {dfanalytics-jobs} API - - -Updates an existing {dfanalytics-job}. -The API accepts an +{request}+ object as a request and returns an +{response}+. - -[id="{upid}-{api}-request"] -==== Update {dfanalytics-jobs} request - -An +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The configuration of the {dfanalytics-job} update to perform - -[id="{upid}-{api}-config"] -==== {dfanalytics-cap} configuration update - -The `DataFrameAnalyticsConfigUpdate` object contains all the details about the {dfanalytics-job} -configuration update and contains the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config-update] --------------------------------------------------- -<1> The {dfanalytics-job} ID -<2> The human-readable description -<3> The memory limit for the model created as part of the analysis process -<4> The maximum number of threads to be used by the analysis - -[id="{upid}-{api}-query-config"] - - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the updated {dfanalytics-job}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/ml/update-datafeed.asciidoc b/docs/java-rest/high-level/ml/update-datafeed.asciidoc deleted file mode 100644 index f72b78f62969..000000000000 --- a/docs/java-rest/high-level/ml/update-datafeed.asciidoc +++ /dev/null @@ -1,60 +0,0 @@ --- -:api: update-datafeed -:request: UpdateDatafeedRequest -:response: PutDatafeedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Update datafeeds API - -Updates a {ml} datafeed in the cluster. The API accepts a +{request}+ object -as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Update datafeeds request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The updated configuration of the {ml} datafeed - -[id="{upid}-{api}-config"] -==== Updated datafeeds arguments - -A `DatafeedUpdate` requires an existing non-null `datafeedId` and -allows updating various settings. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> Mandatory, non-null `datafeedId` referencing an existing {ml} datafeed. -<2> Optional, set the datafeed aggregations for data gathering. -<3> Optional, the indices that contain the data to retrieve and feed into the -{anomaly-job}. -<4> Optional, specifies how data searches are split into time chunks. -<5> Optional, the interval at which scheduled queries are made while the -datafeed runs in real time. -<6> Optional, a query to filter the search results by. Defaults to the -`match_all` query. -<7> Optional, the time interval behind real time that data is queried. -<8> Optional, allows the use of script fields. -<9> Optional, the `size` parameter used in the searches. -<10> Optional, the runtime fields used in the datafeed. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ returns the full representation of -the updated {ml} datafeed if it has been successfully updated. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The updated datafeed. diff --git a/docs/java-rest/high-level/ml/update-filter.asciidoc b/docs/java-rest/high-level/ml/update-filter.asciidoc deleted file mode 100644 index d73560500f1e..000000000000 --- a/docs/java-rest/high-level/ml/update-filter.asciidoc +++ /dev/null @@ -1,57 +0,0 @@ --- -:api: update-filter -:request: UpdateFilterRequest -:response: PutFilterResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Update filters API - -Updates an existing {ml} filter in the cluster. The API accepts a +{request}+ -object as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Update filters request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The id of the existing {ml} filter. - -==== Optional arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-description] --------------------------------------------------- -<1> The updated description of the {ml} filter. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-add-items] --------------------------------------------------- -<1> The list of items to add to the {ml} filter. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-remove-items] --------------------------------------------------- -<1> The list of items to remove from the {ml} filter. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ returns the full representation of -the updated {ml} filter if it has been successfully updated. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The updated `MlFilter`. diff --git a/docs/java-rest/high-level/ml/update-job.asciidoc b/docs/java-rest/high-level/ml/update-job.asciidoc deleted file mode 100644 index 4bca1d298958..000000000000 --- a/docs/java-rest/high-level/ml/update-job.asciidoc +++ /dev/null @@ -1,66 +0,0 @@ --- -:api: update-job -:request: UpdateJobRequest -:response: PutJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Update {anomaly-jobs} API - -Provides the ability to update an {anomaly-job}. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Update {anomaly-jobs} request - -An +{request}+ object gets created with a `JobUpdate` object. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing a `JobUpdate` object. - -==== Optional arguments - -The `JobUpdate` object has many optional arguments with which to update an -existing {anomaly-job}. An existing, non-null `jobId` must be referenced in its -creation. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-options] --------------------------------------------------- -<1> Mandatory, non-null `jobId` referencing an existing {anomaly-job}. -<2> Updated description. -<3> Updated analysis limits. -<4> Updated background persistence interval. -<5> Updated detectors through the `JobUpdate.DetectorUpdate` object. -<6> Updated group membership. -<7> Updated result retention. -<8> Updated model plot configuration. -<9> Updated model snapshot retention setting. -<10> Updated custom settings. -<11> Updated renormalization window. - -Included with these options are specific optional `JobUpdate.DetectorUpdate` updates. -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-detector-options] --------------------------------------------------- -<1> The index of the detector. `O` means unknown. -<2> The optional description of the detector. -<3> The `DetectionRule` rules that apply to this detector. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Update {anomaly-jobs} response - -A +{response}+ contains the updated `Job` object - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `getResponse()` returns the updated `Job` object. diff --git a/docs/java-rest/high-level/ml/update-model-snapshot.asciidoc b/docs/java-rest/high-level/ml/update-model-snapshot.asciidoc deleted file mode 100644 index a38462e15036..000000000000 --- a/docs/java-rest/high-level/ml/update-model-snapshot.asciidoc +++ /dev/null @@ -1,54 +0,0 @@ --- -:api: update-model-snapshot -:request: UpdateModelSnapshotRequest -:response: UpdateModelSnapshotResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Update model snapshots API - -Updates a {ml} model snapshot. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Update model snapshots request - -A +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new request referencing existing `jobId` and `snapshotId` -values. - -==== Optional arguments - -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-description] --------------------------------------------------- -<1> The updated description of the {ml} model snapshot. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-retain] --------------------------------------------------- -<1> The updated `retain` property of the {ml} model snapshot. - - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Update model snapshots response - -A +{response}+ contains an acknowledgement of the update request and the full representation of the updated `ModelSnapshot` object - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> An acknowledgement of the request. -<2> The updated `ModelSnapshot`. diff --git a/docs/java-rest/high-level/ml/upgrade-job-model-snapshot.asciidoc b/docs/java-rest/high-level/ml/upgrade-job-model-snapshot.asciidoc deleted file mode 100644 index 36a72dbd4b2a..000000000000 --- a/docs/java-rest/high-level/ml/upgrade-job-model-snapshot.asciidoc +++ /dev/null @@ -1,44 +0,0 @@ --- -:api: upgrade-job-model-snapshot -:request: UpgradeJobModelSnapshotRequest -:response: UpgradeJobModelSnapshotResponse --- -[role="xpack"] - -[id="{upid}-{api}"] -=== Upgrade job snapshot API - -Upgrades a previously stored {ml} model snapshot to the -current major version. -It accepts an +{request}+ object and responds -with an +{response}+ object. - -[id="{upid}-{api}-request"] -==== Upgrade job snapshots request - -A +{request}+ requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The job that owns the snapshot -<2> The snapshot id to upgrade -<3> The time out of the request. When `wait_for_completion` is `false` the timeout value is - applied to the time it takes for the task to be assigned to a node. When `wait_for_completion` - is `true` this timeout applies for the whole upgrade process. The default value is `30m` -<4> When true, this causes the request to not return until the upgrade is complete. - Otherwise, the response returns as soon as the task - is assigned to a node. The default is false. - -[id="{upid}-{api}-response"] -==== Upgrade job snapshot response - -A +{response}+ contains information on if the request was completed and its assigned node. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Was the upgrade completed -<2> What is the assigned node if the task is not completed diff --git a/docs/java-rest/high-level/query-builders.asciidoc b/docs/java-rest/high-level/query-builders.asciidoc deleted file mode 100644 index 3c749a442e6d..000000000000 --- a/docs/java-rest/high-level/query-builders.asciidoc +++ /dev/null @@ -1,102 +0,0 @@ -[[java-rest-high-query-builders]] -=== Building Queries - -This page lists all the available search queries with their corresponding `QueryBuilder` class name and helper method name in the -`QueryBuilders` utility class. - -:query-ref: {elasticsearch-javadoc}/org/elasticsearch/index/query -:mapper-extras-ref: {mapper-extras-client-javadoc}/org/elasticsearch/index/query -:parentjoin-ref: {parent-join-client-javadoc}/org/elasticsearch/join/query -:percolate-ref: {percolator-client-javadoc}/org/elasticsearch/percolator - -==== Match All Query -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-match-all-query.html[Match All] | {query-ref}/MatchAllQueryBuilder.html[MatchAllQueryBuilder] | {query-ref}/QueryBuilders.html#matchAllQuery--[QueryBuilders.matchAllQuery()] -|====== - -==== Full Text Queries -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-match-query.html[Match] | {query-ref}/MatchQueryBuilder.html[MatchQueryBuilder] | {query-ref}/QueryBuilders.html#matchQuery-java.lang.String-java.lang.Object-[QueryBuilders.matchQuery()] -| {ref}/query-dsl-match-query-phrase.html[Match Phrase] | {query-ref}/MatchPhraseQueryBuilder.html[MatchPhraseQueryBuilder] | {query-ref}/QueryBuilders.html#matchPhraseQuery-java.lang.String-java.lang.Object-[QueryBuilders.matchPhraseQuery()] -| {ref}/query-dsl-match-query-phrase-prefix.html[Match Phrase Prefix] | {query-ref}/MatchPhrasePrefixQueryBuilder.html[MatchPhrasePrefixQueryBuilder] | {query-ref}/QueryBuilders.html#matchPhrasePrefixQuery-java.lang.String-java.lang.Object-[QueryBuilders.matchPhrasePrefixQuery()] -| {ref}/query-dsl-multi-match-query.html[Multi Match] | {query-ref}/MultiMatchQueryBuilder.html[MultiMatchQueryBuilder] | {query-ref}/QueryBuilders.html#multiMatchQuery-java.lang.Object-java.lang.String\…-[QueryBuilders.multiMatchQuery()] -| {ref}/query-dsl-query-string-query.html[Query String] | {query-ref}/QueryStringQueryBuilder.html[QueryStringQueryBuilder] | {query-ref}/QueryBuilders.html#queryStringQuery-java.lang.String-[QueryBuilders.queryStringQuery()] -| {ref}/query-dsl-simple-query-string-query.html[Simple Query String] | {query-ref}/SimpleQueryStringBuilder.html[SimpleQueryStringBuilder] | {query-ref}/QueryBuilders.html#simpleQueryStringQuery-java.lang.String-[QueryBuilders.simpleQueryStringQuery()] -|====== - -==== Term-level queries -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-term-query.html[Term] | {query-ref}/TermQueryBuilder.html[TermQueryBuilder] | {query-ref}/QueryBuilders.html#termQuery-java.lang.String-java.lang.String-[QueryBuilders.termQuery()] -| {ref}/query-dsl-terms-query.html[Terms] | {query-ref}/TermsQueryBuilder.html[TermsQueryBuilder] | {query-ref}/QueryBuilders.html#termsQuery-java.lang.String-java.util.Collection-[QueryBuilders.termsQuery()] -| {ref}/query-dsl-range-query.html[Range] | {query-ref}/RangeQueryBuilder.html[RangeQueryBuilder] | {query-ref}/QueryBuilders.html#rangeQuery-java.lang.String-[QueryBuilders.rangeQuery()] -| {ref}/query-dsl-exists-query.html[Exists] | {query-ref}/ExistsQueryBuilder.html[ExistsQueryBuilder] | {query-ref}/QueryBuilders.html#existsQuery-java.lang.String-[QueryBuilders.existsQuery()] -| {ref}/query-dsl-prefix-query.html[Prefix] | {query-ref}/PrefixQueryBuilder.html[PrefixQueryBuilder] | {query-ref}/QueryBuilders.html#prefixQuery-java.lang.String-java.lang.String-[QueryBuilders.prefixQuery()] -| {ref}/query-dsl-wildcard-query.html[Wildcard] | {query-ref}/WildcardQueryBuilder.html[WildcardQueryBuilder] | {query-ref}/QueryBuilders.html#wildcardQuery-java.lang.String-java.lang.String-[QueryBuilders.wildcardQuery()] -| {ref}/query-dsl-regexp-query.html[Regexp] | {query-ref}/RegexpQueryBuilder.html[RegexpQueryBuilder] | {query-ref}/QueryBuilders.html#regexpQuery-java.lang.String-java.lang.String-[QueryBuilders.regexpQuery()] -| {ref}/query-dsl-fuzzy-query.html[Fuzzy] | {query-ref}/FuzzyQueryBuilder.html[FuzzyQueryBuilder] | {query-ref}/QueryBuilders.html#fuzzyQuery-java.lang.String-java.lang.String-[QueryBuilders.fuzzyQuery()] -| {ref}/query-dsl-ids-query.html[Ids] | {query-ref}/IdsQueryBuilder.html[IdsQueryBuilder] | {query-ref}/QueryBuilders.html#idsQuery--[QueryBuilders.idsQuery()] -|====== - -==== Compound queries -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-constant-score-query.html[Constant Score] | {query-ref}/ConstantScoreQueryBuilder.html[ConstantScoreQueryBuilder] | {query-ref}/QueryBuilders.html#constantScoreQuery-org.elasticsearch.index.query.QueryBuilder-[QueryBuilders.constantScoreQuery()] -| {ref}/query-dsl-bool-query.html[Bool] | {query-ref}/BoolQueryBuilder.html[BoolQueryBuilder] | {query-ref}/QueryBuilders.html#boolQuery--[QueryBuilders.boolQuery()] -| {ref}/query-dsl-dis-max-query.html[Dis Max] | {query-ref}/DisMaxQueryBuilder.html[DisMaxQueryBuilder] | {query-ref}/QueryBuilders.html#disMaxQuery--[QueryBuilders.disMaxQuery()] -| {ref}/query-dsl-function-score-query.html[Function Score] | {query-ref}/functionscore/FunctionScoreQueryBuilder.html[FunctionScoreQueryBuilder] | {query-ref}/QueryBuilders.html#functionScoreQuery-org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder:A-[QueryBuilders.functionScoreQuery()] -| {ref}/query-dsl-boosting-query.html[Boosting] | {query-ref}/BoostingQueryBuilder.html[BoostingQueryBuilder] | {query-ref}/QueryBuilders.html#boostingQuery-org.elasticsearch.index.query.QueryBuilder-org.elasticsearch.index.query.QueryBuilder-[QueryBuilders.boostingQuery()] -|====== - -==== Joining queries -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-nested-query.html[Nested] | {query-ref}/NestedQueryBuilder.html[NestedQueryBuilder] | {query-ref}/QueryBuilders.html#nestedQuery-java.lang.String-org.elasticsearch.index.query.QueryBuilder-org.apache.lucene.search.join.ScoreMode-[QueryBuilders.nestedQuery()] -| {ref}/query-dsl-has-child-query.html[Has Child] | {parentjoin-ref}/HasChildQueryBuilder.html[HasChildQueryBuilder] | -| {ref}/query-dsl-has-parent-query.html[Has Parent] | {parentjoin-ref}/HasParentQueryBuilder.html[HasParentQueryBuilder] | -| {ref}/query-dsl-parent-id-query.html[Parent Id] | {parentjoin-ref}/ParentIdQueryBuilder.html[ParentIdQueryBuilder] | -|====== - -==== Geo queries -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-geo-shape-query.html[GeoShape] | {query-ref}/GeoShapeQueryBuilder.html[GeoShapeQueryBuilder] | {query-ref}/QueryBuilders.html#geoShapeQuery-java.lang.String-java.lang.String-java.lang.String-[QueryBuilders.geoShapeQuery()] -| {ref}/query-dsl-geo-bounding-box-query.html[Geo Bounding Box] | {query-ref}/GeoBoundingBoxQueryBuilder.html[GeoBoundingBoxQueryBuilder] | {query-ref}/QueryBuilders.html#geoBoundingBoxQuery-java.lang.String-[QueryBuilders.geoBoundingBoxQuery()] -| {ref}/query-dsl-geo-distance-query.html[Geo Distance] | {query-ref}/GeoDistanceQueryBuilder.html[GeoDistanceQueryBuilder] | {query-ref}/QueryBuilders.html#geoDistanceQuery-java.lang.String-[QueryBuilders.geoDistanceQuery()] -| {ref}/query-dsl-geo-polygon-query.html[Geo Polygon] | {query-ref}/GeoPolygonQueryBuilder.html[GeoPolygonQueryBuilder] | {query-ref}/QueryBuilders.html#geoPolygonQuery-java.lang.String-java.util.List-[QueryBuilders.geoPolygonQuery()] -|====== - -==== Specialized queries -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-mlt-query.html[More Like This] | {query-ref}/MoreLikeThisQueryBuilder.html[MoreLikeThisQueryBuilder] | {query-ref}/QueryBuilders.html#moreLikeThisQuery-org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item:A-[QueryBuilders.moreLikeThisQuery()] -| {ref}/query-dsl-script-query.html[Script] | {query-ref}/ScriptQueryBuilder.html[ScriptQueryBuilder] | {query-ref}/QueryBuilders.html#scriptQuery-org.elasticsearch.script.Script-[QueryBuilders.scriptQuery()] -| {ref}/query-dsl-percolate-query.html[Percolate] | {percolate-ref}/PercolateQueryBuilder.html[PercolateQueryBuilder] | -| {ref}/query-dsl-wrapper-query.html[Wrapper] | {query-ref}/WrapperQueryBuilder.html[WrapperQueryBuilder] | {query-ref}/QueryBuilders.html#wrapperQuery-java.lang.String-[QueryBuilders.wrapperQuery()] -| {ref}/query-dsl-rank-feature-query.html[Rank Feature] | {mapper-extras-ref}/RankFeatureQuery.html[RankFeatureQueryBuilder] | -| {ref}/query-dsl-pinned-query.html[Pinned Query] | The PinnedQueryBuilder is packaged as part of the xpack-core module | -|====== - -==== Span queries -[options="header"] -|====== -| Search Query | QueryBuilder Class | Method in QueryBuilders -| {ref}/query-dsl-span-term-query.html[Span Term] | {query-ref}/SpanTermQueryBuilder.html[SpanTermQueryBuilder] | {query-ref}/QueryBuilders.html#spanTermQuery-java.lang.String-double-[QueryBuilders.spanTermQuery()] -| {ref}/query-dsl-span-multi-term-query.html[Span Multi Term] | {query-ref}/SpanMultiTermQueryBuilder.html[SpanMultiTermQueryBuilder] | {query-ref}/QueryBuilders.html#spanMultiTermQueryBuilder-org.elasticsearch.index.query.MultiTermQueryBuilder-[QueryBuilders.spanMultiTermQueryBuilder()] -| {ref}/query-dsl-span-first-query.html[Span First] | {query-ref}/SpanFirstQueryBuilder.html[SpanFirstQueryBuilder] | {query-ref}/QueryBuilders.html#spanFirstQuery-org.elasticsearch.index.query.SpanQueryBuilder-int-[QueryBuilders.spanFirstQuery()] -| {ref}/query-dsl-span-near-query.html[Span Near] | {query-ref}/SpanNearQueryBuilder.html[SpanNearQueryBuilder] | {query-ref}/QueryBuilders.html#spanNearQuery-org.elasticsearch.index.query.SpanQueryBuilder-int-[QueryBuilders.spanNearQuery()] -| {ref}/query-dsl-span-or-query.html[Span Or] | {query-ref}/SpanOrQueryBuilder.html[SpanOrQueryBuilder] | {query-ref}/QueryBuilders.html#spanOrQuery-org.elasticsearch.index.query.SpanQueryBuilder-[QueryBuilders.spanOrQuery()] -| {ref}/query-dsl-span-not-query.html[Span Not] | {query-ref}/SpanNotQueryBuilder.html[SpanNotQueryBuilder] | {query-ref}/QueryBuilders.html#spanNotQuery-org.elasticsearch.index.query.SpanQueryBuilder-org.elasticsearch.index.query.SpanQueryBuilder-[QueryBuilders.spanNotQuery()] -| {ref}/query-dsl-span-containing-query.html[Span Containing] | {query-ref}/SpanContainingQueryBuilder.html[SpanContainingQueryBuilder] | {query-ref}/QueryBuilders.html#spanContainingQuery-org.elasticsearch.index.query.SpanQueryBuilder-org.elasticsearch.index.query.SpanQueryBuilder-[QueryBuilders.spanContainingQuery()] -| {ref}/query-dsl-span-within-query.html[Span Within] | {query-ref}/SpanWithinQueryBuilder.html[SpanWithinQueryBuilder] | {query-ref}/QueryBuilders.html#spanWithinQuery-org.elasticsearch.index.query.SpanQueryBuilder-org.elasticsearch.index.query.SpanQueryBuilder-[QueryBuilders.spanWithinQuery()] -| {ref}/query-dsl-span-field-masking-query.html[Span Field Masking] | {query-ref}/FieldMaskingSpanQueryBuilder.html[FieldMaskingSpanQueryBuilder] | {query-ref}/QueryBuilders.html#fieldMaskingSpanQuery-org.elasticsearch.index.query.SpanQueryBuilder-java.lang.String-[QueryBuilders.fieldMaskingSpanQuery()] -|====== diff --git a/docs/java-rest/high-level/rollup/delete_job.asciidoc b/docs/java-rest/high-level/rollup/delete_job.asciidoc deleted file mode 100644 index 22b8787799ab..000000000000 --- a/docs/java-rest/high-level/rollup/delete_job.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: rollup-delete-job -:request: DeleteRollupJobRequest -:response: DeleteRollupJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Rollup Job API - -experimental::[] - -[id="{upid}-{api}-request"] -==== Request - -The Delete Rollup Job API allows you to delete a job by ID. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The ID of the job to delete. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the delete command was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the delete job request was received. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/rollup/get_job.asciidoc b/docs/java-rest/high-level/rollup/get_job.asciidoc deleted file mode 100644 index 5ed65ebfaec0..000000000000 --- a/docs/java-rest/high-level/rollup/get_job.asciidoc +++ /dev/null @@ -1,74 +0,0 @@ -[role="xpack"] -[[java-rest-high-x-pack-rollup-get-job]] -=== Get Rollup Job API - -experimental::[] - -The Get Rollup Job API can be used to get one or all rollup jobs from the -cluster. It accepts a `GetRollupJobRequest` object as a request and returns -a `GetRollupJobResponse`. - -[[java-rest-high-x-pack-rollup-get-rollup-job-request]] -==== Get Rollup Job Request - -A `GetRollupJobRequest` can be built without any parameters to get all of the -rollup jobs or with a job name to get a single job: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-job-request] --------------------------------------------------- -<1> Gets all jobs. -<2> Gets `job_1`. - -[[java-rest-high-x-pack-rollup-get-rollup-job-execution]] -==== Execution - -The Get Rollup Job API can be executed through a `RollupClient` -instance. Such instance can be retrieved from a `RestHighLevelClient` -using the `rollup()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-job-execute] --------------------------------------------------- - -[[java-rest-high-x-pack-rollup-get-rollup-job-response]] -==== Response - -The returned `GetRollupJobResponse` includes a `JobWrapper` per returned job -which contains the configuration of the job, the job's current status, and -statistics about the job's past execution. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-job-response] --------------------------------------------------- -<1> We only asked for a single job - -[[java-rest-high-x-pack-rollup-get-rollup-job-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-job-execute-async] --------------------------------------------------- -<1> The `GetRollupJobRequest` 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 `GetRollupJobResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-job-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 diff --git a/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc b/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc deleted file mode 100644 index 681ea25a18f8..000000000000 --- a/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc +++ /dev/null @@ -1,85 +0,0 @@ --- -:api: rollup-get-rollup-caps -:request: GetRollupCapsRequest -:response: GetRollupCapsResponse --- -[role="xpack"] -[id="{upid}-x-pack-{api}"] -=== Get Rollup Capabilities API - -experimental::[] - -The Get Rollup Capabilities API allows the user to query a target index pattern (`logstash-*`, etc) -and determine if there are any rollup jobs that are/were configured to rollup that pattern. -The API accepts a `GetRollupCapsRequest` object as a request and returns a `GetRollupCapsResponse`. - -[id="{upid}-x-pack-{api}-request"] -==== Get Rollup Capabilities Request - -A +{request}+ requires a single parameter: the target index or index pattern (e.g. `logstash-*`): - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-request] --------------------------------------------------- - -[id="{upid}-x-pack-{api}-execution"] -==== Execution - -The Get Rollup Capabilities API can be executed through a `RollupClient` -instance. Such instance can be retrieved from a `RestHighLevelClient` -using the `rollup()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-execute] --------------------------------------------------- - -[id="{upid}-x-pack-{api}-response"] -==== Response - -The returned +{response}+ holds lists and maps of values which correspond to the capabilities -of the target index/index pattern (what jobs were configured for the pattern, where the data is stored, what -aggregations are available, etc). It provides essentially the same data as the original job configuration, -just presented in a different manner. - -For example, if we had created a job with the following config: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-setup] --------------------------------------------------- - -The +{response}+ object would contain the same information, laid out in a slightly different manner: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-response] --------------------------------------------------- - -[id="{upid}-x-pack-{api}-async"] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-execute-async] --------------------------------------------------- -<1> The +{request}+ 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 +{response}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-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 diff --git a/docs/java-rest/high-level/rollup/get_rollup_index_caps.asciidoc b/docs/java-rest/high-level/rollup/get_rollup_index_caps.asciidoc deleted file mode 100644 index 06d546fb3c58..000000000000 --- a/docs/java-rest/high-level/rollup/get_rollup_index_caps.asciidoc +++ /dev/null @@ -1,86 +0,0 @@ --- -:api: rollup-get-rollup-index-caps -:request: GetRollupIndexCapsRequest -:response: GetRollupIndexCapsResponse --- -[role="xpack"] -[id="{upid}-x-pack-{api}"] -=== Get Rollup Index Capabilities API - -experimental::[] - -The Get Rollup Index Capabilities API allows the user to determine if a concrete index or index pattern contains -stored rollup jobs and data. If it contains data stored from rollup jobs, the capabilities of those jobs -are returned. The API accepts a `GetRollupIndexCapsRequest` object as a request and returns a `GetRollupIndexCapsResponse`. - -[id="{upid}-x-pack-{api}-request"] -==== Get Rollup Index Capabilities Request - -A +{request}+ requires a single parameter: the target index or index pattern (e.g. `rollup-foo`): - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-request] --------------------------------------------------- - -[id="{upid}-x-pack-{api}-execution"] -==== Execution - -The Get Rollup Index Capabilities API can be executed through a `RollupClient` -instance. Such instance can be retrieved from a `RestHighLevelClient` -using the `rollup()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-execute] --------------------------------------------------- - -[id="{upid}-x-pack-{api}-response"] -==== Response - -The returned +{response}+ holds lists and maps of values which correspond to the capabilities -of the rollup index/index pattern (what jobs are stored in the index, their capabilities, what -aggregations are available, etc). Because multiple jobs can be stored in one index, the -response may include several jobs with different configurations. - -The capabilities are essentially the same as the original job configuration, just presented in a different -manner. For example, if we had created a job with the following config: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-setup] --------------------------------------------------- - -The +{response}+ object would contain the same information, laid out in a slightly different manner: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-response] --------------------------------------------------- - -[id="{upid}-x-pack-{api}-async"] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-execute-async] --------------------------------------------------- -<1> The +{request}+ 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 +{response}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-{api}-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 diff --git a/docs/java-rest/high-level/rollup/put_job.asciidoc b/docs/java-rest/high-level/rollup/put_job.asciidoc deleted file mode 100644 index 74884aa1ecf4..000000000000 --- a/docs/java-rest/high-level/rollup/put_job.asciidoc +++ /dev/null @@ -1,175 +0,0 @@ -[role="xpack"] -[[java-rest-high-x-pack-rollup-put-job]] -=== Create or update rollup job API - -experimental::[] - -Creates a new Rollup job or updates an existing one. -The API accepts a `PutRollupJobRequest` object -as a request and returns a `PutRollupJobResponse`. - -[[java-rest-high-x-pack-rollup-put-rollup-job-request]] -==== Request - -A `PutRollupJobRequest` requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-request] --------------------------------------------------- -<1> The configuration of the Rollup job to create as a `RollupJobConfig` - -[[java-rest-high-x-pack-rollup-put-rollup-job-config]] -==== Rollup Job Configuration - -The `RollupJobConfig` object contains all the details about the rollup job -configuration. See {ref}/rollup-put-job.html[create rollup job API] to learn more -about the various configuration settings. - -A `RollupJobConfig` requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-config] --------------------------------------------------- -<1> The name of the Rollup job -<2> The index (or index pattern) to rollup -<3> The index to store rollup results into -<4> A cron expression which defines when the Rollup job should be executed -<5> The page size to use for the Rollup job -<6> The grouping configuration of the Rollup job as a `GroupConfig` -<7> The metrics configuration of the Rollup job as a list of `MetricConfig` -<8> The timeout value to use for the Rollup job as a `TimeValue` - - -[[java-rest-high-x-pack-rollup-put-rollup-job-group-config]] -==== Grouping Configuration - -The grouping configuration of the Rollup job is defined in the `RollupJobConfig` -using a `GroupConfig` instance. `GroupConfig` reflects all the configuration -settings that can be defined using the REST API. See {ref}/rollup-put-job.html#rollup-groups-config[Grouping config] -to learn more about these settings. - -Using the REST API, we could define this grouping configuration: - -[source,js] --------------------------------------------------- -"groups" : { - "date_histogram": { - "field": "timestamp", - "calendar_interval": "1h", - "delay": "7d", - "time_zone": "UTC" - }, - "terms": { - "fields": ["hostname", "datacenter"] - }, - "histogram": { - "fields": ["load", "net_in", "net_out"], - "interval": 5 - } -} --------------------------------------------------- -// NOTCONSOLE - -Using the `GroupConfig` object and the high level REST client, the same -configuration would be: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-group-config] --------------------------------------------------- -<1> The date histogram aggregation to use to rollup up documents, as a `DateHistogramGroupConfig` -<2> The terms aggregation to use to rollup up documents, as a `TermsGroupConfig` -<3> The histogram aggregation to use to rollup up documents, as a `HistogramGroupConfig` -<4> The grouping configuration as a `GroupConfig` - - -[[java-rest-high-x-pack-rollup-put-rollup-job-metrics-config]] -==== Metrics Configuration - -After defining which groups should be generated for the data, you next configure -which metrics should be collected. The list of metrics is defined in the `RollupJobConfig` -using a `List` instance. `MetricConfig` reflects all the configuration -settings that can be defined using the REST API. See {ref}/rollup-put-job.html#rollup-metrics-config[Metrics config] -to learn more about these settings. - -Using the REST API, we could define this metrics configuration: - -[source,js] --------------------------------------------------- -"metrics": [ - { - "field": "temperature", - "metrics": ["min", "max", "sum"] - }, - { - "field": "voltage", - "metrics": ["avg", "value_count"] - } -] --------------------------------------------------- -// NOTCONSOLE - -Using the `MetricConfig` object and the high level REST client, the same -configuration would be: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-metrics-config] --------------------------------------------------- -<1> The list of `MetricConfig` to configure in the `RollupJobConfig` -<2> Adds the metrics to compute on the `temperature` field -<3> Adds the metrics to compute on the `voltage` field - - -[[java-rest-high-x-pack-rollup-put-rollup-job-execution]] -==== Execution - -The API can be called through a `RollupClient` -instance. Such instance can be retrieved from a `RestHighLevelClient` -using the `rollup()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute] --------------------------------------------------- - -[[java-rest-high-x-pack-rollup-put-rollup-job-response]] -==== Response - -The returned `PutRollupJobResponse` indicates if the new Rollup job -has been successfully created: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-response] --------------------------------------------------- -<1> `acknowledged` is a boolean indicating whether the job was successfully created - -[[java-rest-high-x-pack-rollup-put-rollup-job-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute-async] --------------------------------------------------- -<1> The `PutRollupJobRequest` 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 `PutRollupJobResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-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 diff --git a/docs/java-rest/high-level/rollup/search.asciidoc b/docs/java-rest/high-level/rollup/search.asciidoc deleted file mode 100644 index 58b45a4d7e96..000000000000 --- a/docs/java-rest/high-level/rollup/search.asciidoc +++ /dev/null @@ -1,47 +0,0 @@ --- -:api: search -:request: SearchRequest -:response: SearchResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Rollup Search API - -experimental::[] - -The Rollup Search endpoint allows searching rolled-up data using the standard -Query DSL. The Rollup Search endpoint is needed because, internally, -rolled-up documents utilize a different document structure than the original -data. The Rollup Search endpoint rewrites standard Query DSL into a format that -matches the rollup documents, then takes the response and rewrites it back to -what a client would expect given the original query. - -[id="{upid}-{api}-request"] -==== Request - -Rollup Search uses the same +{request}+ that is used by the <<{mainid}-search>> -but it is mostly for aggregations you should set the `size` to 0 and add -aggregations like this: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -NOTE:: Rollup Search is limited in many ways because only some query elements -can be translated into queries against the rollup indices. See the main -{ref}/rollup-search.html[Rollup Search] documentation for more. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -Rollup Search returns the same +{response}+ that is used by the -<<{mainid}-search>> and everything can be accessed in exactly the same way. -This will access the aggregation built by the example request above: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/rollup/start_job.asciidoc b/docs/java-rest/high-level/rollup/start_job.asciidoc deleted file mode 100644 index 0e0fc073ac61..000000000000 --- a/docs/java-rest/high-level/rollup/start_job.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: rollup-start-job -:request: StartRollupJobRequest -:response: StartRollupJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Start Rollup Job API - -experimental::[] - -[id="{upid}-{api}-request"] -==== Request - -The Start Rollup Job API allows you to start a job by ID. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The ID of the job to start. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the start command was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the start job request was received. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/rollup/stop_job.asciidoc b/docs/java-rest/high-level/rollup/stop_job.asciidoc deleted file mode 100644 index 9ebd97dc837a..000000000000 --- a/docs/java-rest/high-level/rollup/stop_job.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ --- -:api: rollup-stop-job -:request: StopRollupJobRequest -:response: StopRollupJobResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Stop Rollup Job API - -experimental::[] - -[id="{upid}-{api}-request"] -==== Request - -The Stop Rollup Job API allows you to stop a job by ID. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The ID of the job to stop. -<2> Whether the request should wait that the stop operation has completed -before returning (optional, defaults to `false`) -<3> If `wait_for_completion=true`, this parameter controls how long to wait -before giving up and throwing an error (optional, defaults to 30 seconds). - - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the stop command was received. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Whether or not the stop job request was received. - -include::../execution.asciidoc[] - - diff --git a/docs/java-rest/high-level/script/delete_script.asciidoc b/docs/java-rest/high-level/script/delete_script.asciidoc deleted file mode 100644 index fe146ece579f..000000000000 --- a/docs/java-rest/high-level/script/delete_script.asciidoc +++ /dev/null @@ -1,81 +0,0 @@ -[[java-rest-high-delete-stored-script]] - -=== Delete Stored Script API - -[[java-rest-high-delete-stored-script-request]] -==== Delete Stored Script Request - -A `DeleteStoredScriptRequest` requires an `id`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-request] --------------------------------------------------- -<1> The id of the script - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the stored script is deleted as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the stored script is deleted as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-delete-stored-script-sync]] -==== Synchronous Execution -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-execute] --------------------------------------------------- - -[[java-rest-high-delete-stored-script-async]] -==== Asynchronous Execution - -The asynchronous execution of a delete stored script request requires both the `DeleteStoredScriptRequest` -instance and an `ActionListener` instance to be passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-execute-async] --------------------------------------------------- -<1> The `DeleteStoredScriptRequest` to execute and the `ActionListener` to use when -the execution completes - -[[java-rest-high-delete-stored-script-listener]] -===== Action Listener - -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 `AcknowledgedResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-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 - -[[java-rest-high-delete-stored-script-response]] -==== Delete Stored Script Response - -The returned `AcknowledgedResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/script/get_script.asciidoc b/docs/java-rest/high-level/script/get_script.asciidoc deleted file mode 100644 index a38bdad2bd6a..000000000000 --- a/docs/java-rest/high-level/script/get_script.asciidoc +++ /dev/null @@ -1,77 +0,0 @@ -[[java-rest-high-get-stored-script]] - -=== Get Stored Script API - -[[java-rest-high-get-stored-script-request]] -==== Get Stored Script Request - -A `GetStoredScriptRequest` requires an `id`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-request] --------------------------------------------------- -<1> The id of the script - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-get-stored-script-sync]] -==== Synchronous Execution -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute] --------------------------------------------------- - -[[java-rest-high-get-stored-script-async]] -==== Asynchronous Execution - -The asynchronous execution of a get stored script request requires both the `GetStoredScriptRequest` -instance and an `ActionListener` instance to be passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute-async] --------------------------------------------------- -<1> The `GetStoredScriptRequest` to execute and the `ActionListener` to use when -the execution completes - -[[java-rest-high-get-stored-script-listener]] -===== Action Listener - -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 `GetStoredScriptResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-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 - -[[java-rest-high-get-stored-script-response]] -==== Get Stored Script Response - -The returned `GetStoredScriptResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-response] --------------------------------------------------- -<1> The script object consists of a content and a metadata -<2> The language the script is written in, which defaults to `painless`. -<3> The content of the script -<4> Any named options that should be passed into the script. \ No newline at end of file diff --git a/docs/java-rest/high-level/script/put_script.asciidoc b/docs/java-rest/high-level/script/put_script.asciidoc deleted file mode 100644 index e3c54e3cad2c..000000000000 --- a/docs/java-rest/high-level/script/put_script.asciidoc +++ /dev/null @@ -1,107 +0,0 @@ -[[java-rest-high-put-stored-script]] -=== Create or update stored script API - -[[java-rest-high-put-stored-script-request]] -==== Request - -A `PutStoredScriptRequest` requires an `id` and `content`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-request] --------------------------------------------------- -<1> The id of the script -<2> The content of the script - -[[java-rest-high-put-stored-script-content]] -==== Content -The content of a script can be written in different languages and provided in -different ways: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-content-painless] --------------------------------------------------- -<1> Specify a painless script and provided as `XContentBuilder` object. -Note that the builder needs to be passed as a `BytesReference` object - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-content-mustache] --------------------------------------------------- -<1> Specify a mustache script and provided as `XContentBuilder` object. -Note that value of source can be directly provided as a JSON string - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-context] --------------------------------------------------- -<1> The context the script should be executed in. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the script creation as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the script creation as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-put-stored-script-sync]] -==== Synchronous Execution -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-execute] --------------------------------------------------- - -[[java-rest-high-put-stored-script-async]] -==== Asynchronous Execution - -The asynchronous execution of a create or update stored script request requires -both the `PutStoredScriptRequest` instance and an `ActionListener` instance to -be passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-execute-async] --------------------------------------------------- -<1> The `PutStoredScriptRequest` to execute and the `ActionListener` to use when -the execution completes - -[[java-rest-high-put-stored-script-listener]] -===== Action Listener - -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 `AcknowledgedResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-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 - -[[java-rest-high-put-stored-script-response]] -==== Response - -The returned `AcknowledgedResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[put-stored-script-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request \ No newline at end of file diff --git a/docs/java-rest/high-level/search/count.asciidoc b/docs/java-rest/high-level/search/count.asciidoc deleted file mode 100644 index 2796d34ab36a..000000000000 --- a/docs/java-rest/high-level/search/count.asciidoc +++ /dev/null @@ -1,96 +0,0 @@ --- -:api: count -:request: CountRequest -:response: CountResponse --- -[id="{upid}-{api}"] - -=== Count API - -[id="{upid}-{api}-request"] - -==== Count Request - -The +{request}+ is used to execute a query and get the number of matches for the query. The query to use in +{request}+ can be -set in similar way as query in `SearchRequest` using `SearchSourceBuilder`. - -In its most basic form, we can add a query to the request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-basic] --------------------------------------------------- - -<1> Creates the +{request}+. Without arguments this runs against all indices. -<2> Most search parameters are added to the `SearchSourceBuilder`. -<3> Add a `match_all` query to the `SearchSourceBuilder`. -<4> Add the `SearchSourceBuilder` to the +{request}+. - -[[java-rest-high-count-request-optional]] -===== Count Request optional arguments - -A +{request}+ also takes the following optional arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-args] --------------------------------------------------- -<1> Restricts the request to an index -<2> Set a routing parameter -<3> Setting `IndicesOptions` controls how unavailable indices are resolved and how wildcard expressions are expanded -<4> Use the preference parameter e.g. to execute the search to prefer local shards. The default is to randomize across shards. - -===== Using the SearchSourceBuilder in CountRequest - -Both in search and count API calls, most options controlling the search behavior can be set on the `SearchSourceBuilder`, -which contains more or less the equivalent of the options in the search request body of the Rest API. - -Here are a few examples of some common options: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-basics] --------------------------------------------------- -<1> Create a `SearchSourceBuilder` with default options. -<2> Set the query. Can be any type of `QueryBuilder` - -After this, the `SearchSourceBuilder` only needs to be added to the -+{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-setter] --------------------------------------------------- - -Note subtle difference when using `SearchSourceBuilder` in `SearchRequest` and using `SearchSourceBuilder` in +{request}+ - using -`SearchSourceBuilder` in `SearchRequest` one can use `SearchSourceBuilder.size()` and `SearchSourceBuilder.from()` methods to set the -number of search hits to return, and the starting index. In +{request}+ we're interested in total number of matches and these methods -have no meaning. - -The <> page gives a list of all available search queries with -their corresponding `QueryBuilder` objects and `QueryBuilders` helper methods. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== CountResponse - -The +{response}+ that is returned by executing the count API call provides total count of hits and details about the count execution -itself, like the HTTP status code, or whether the request terminated early: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-1] --------------------------------------------------- - -The response also provides information about the execution on the -shard level by offering statistics about the total number of shards that were -affected by the underlying search, and the successful vs. unsuccessful shards. Possible -failures can also be handled by iterating over an array off -`ShardSearchFailures` like in the following example: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-2] --------------------------------------------------- - diff --git a/docs/java-rest/high-level/search/explain.asciidoc b/docs/java-rest/high-level/search/explain.asciidoc deleted file mode 100644 index fd23bf1b80c8..000000000000 --- a/docs/java-rest/high-level/search/explain.asciidoc +++ /dev/null @@ -1,112 +0,0 @@ -[[java-rest-high-explain]] -=== Explain API - -The explain api computes a score explanation for a query and a specific document. -This can give useful feedback whether a document matches or didn’t match a specific query. - -[[java-rest-high-explain-request]] -==== Explain Request - -An `ExplainRequest` expects an `index` and an `id` to specify a certain document, -and a query represented by `QueryBuilder` to run against it (the way of <>). - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-request] --------------------------------------------------- - -===== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-request-routing] --------------------------------------------------- -<1> Set a routing parameter - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-request-preference] --------------------------------------------------- -<1> Use the preference parameter e.g. to execute the search to prefer local -shards. The default is to randomize across shards. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-request-source] --------------------------------------------------- -<1> Set to true to retrieve the _source of the document explained. You can also -retrieve part of the document by using _source_include & _source_exclude -(see <> for more details) - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-request-stored-field] --------------------------------------------------- -<1> Allows to control which stored fields to return as part of the document explained -(requires the field to be stored separately in the mappings). - -[[java-rest-high-explain-sync]] -==== Synchronous Execution - -The `explain` method executes the request synchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-execute] --------------------------------------------------- - -[[java-rest-high-explain-async]] -==== Asynchronous Execution - -The `explainAsync` method executes the request asynchronously, -calling the provided `ActionListener` when the response is ready: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-execute-async] --------------------------------------------------- -<1> The `ExplainRequest` to execute and the `ActionListener` to use when -the execution completes. - -The asynchronous method does not block and returns immediately. Once the request -completes, 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 `ExplainResponse` is constructed as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the whole `ExplainRequest` fails. - -[[java-rest-high-explain-response]] -==== ExplainResponse - -The `ExplainResponse` contains the following information: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[explain-response] --------------------------------------------------- -<1> The index name of the explained document. -<2> The id of the explained document. -<3> Indicates whether or not the explained document exists. -<4> Indicates whether or not there is a match between the explained document and -the provided query (the `match` is retrieved from the lucene `Explanation` behind the scenes -if the lucene `Explanation` models a match, it returns `true`, otherwise it returns `false`). -<5> Indicates whether or not there exists a lucene `Explanation` for this request. -<6> Get the lucene `Explanation` object if there exists. -<7> Get the `GetResult` object if the `_source` or the stored fields are retrieved. - -The `GetResult` contains two maps internally to store the fetched `_source` and stored fields. -You can use the following methods to get them: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[get-result] --------------------------------------------------- -<1> Retrieve the `_source` as a map. -<2> Retrieve the specified stored fields as a map. diff --git a/docs/java-rest/high-level/search/field-caps.asciidoc b/docs/java-rest/high-level/search/field-caps.asciidoc deleted file mode 100644 index c717c45843fd..000000000000 --- a/docs/java-rest/high-level/search/field-caps.asciidoc +++ /dev/null @@ -1,82 +0,0 @@ -[[java-rest-high-field-caps]] -=== Field Capabilities API - -The field capabilities API allows for retrieving the capabilities of fields across multiple indices. - -[[java-rest-high-field-caps-request]] -==== Field Capabilities Request - -A `FieldCapabilitiesRequest` contains a list of fields to get capabilities for, -plus an optional list of target indices. If no indices are provided, the request -runs on all indices. - -Note that fields parameter supports wildcard notation. For example, providing `text_*` -will cause all fields that match the expression to be returned. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[field-caps-request] --------------------------------------------------- - -[[java-rest-high-field-caps-request-optional]] -===== Optional arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[field-caps-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded. - -[[java-rest-high-field-caps-sync]] -==== Synchronous Execution - -The `fieldCaps` method executes the request synchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[field-caps-execute] --------------------------------------------------- - -[[java-rest-high-field-caps-async]] -==== Asynchronous Execution - -The `fieldCapsAsync` method executes the request asynchronously, -calling the provided `ActionListener` when the response is ready: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[field-caps-execute-async] --------------------------------------------------- -<1> The `FieldCapabilitiesRequest` to execute and the `ActionListener` to use when -the execution completes. - -The asynchronous method does not block and returns immediately. Once the request -completes, 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 `FieldCapabilitiesResponse` is constructed as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[field-caps-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the whole `FieldCapabilitiesRequest` fails. - -[[java-rest-high-field-caps-response]] -==== FieldCapabilitiesResponse - -For each requested field, the returned `FieldCapabilitiesResponse` contains its type -and whether or not it can be searched or aggregated on. The response also gives -information about how each index contributes to the field's capabilities. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[field-caps-response] --------------------------------------------------- -<1> A map with entries for the field's possible types, in this case `keyword` and `text`. -<2> All indices where the `user` field has type `keyword`. -<3> The subset of these indices where the `user` field isn't searchable, or null if it's always searchable. -<4> Another subset of these indices where the `user` field isn't aggregatable, or null if it's always aggregatable. diff --git a/docs/java-rest/high-level/search/multi-search-template.asciidoc b/docs/java-rest/high-level/search/multi-search-template.asciidoc deleted file mode 100644 index c5133f6614ee..000000000000 --- a/docs/java-rest/high-level/search/multi-search-template.asciidoc +++ /dev/null @@ -1,81 +0,0 @@ -[[java-rest-high-multi-search-template]] -=== Multi-Search-Template API - -The `multiSearchTemplate` API executes multiple <> -requests in a single http request in parallel. - -[[java-rest-high-multi-search-template-request]] -==== Multi-Search-Template Request - -The `MultiSearchTemplateRequest` is built empty and you add all of the searches that -you wish to execute to it: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-template-request-inline] --------------------------------------------------- -<1> Create an empty `MultiSearchTemplateRequest`. -<2> Create one or more `SearchTemplateRequest` objects and populate them just like you -would for a regular <>. -<3> Add the `SearchTemplateRequest` to the `MultiSearchTemplateRequest`. - -===== Optional arguments - -The multiSearchTemplate's `max_concurrent_searches` request parameter can be used to control -the maximum number of concurrent searches the multi search api will execute. -This default is based on the number of data nodes and the default search thread pool size. - -[[java-rest-high-multi-search-template-sync]] -==== Synchronous Execution - -The `multiSearchTemplate` method executes `MultiSearchTemplateRequest`s synchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-template-request-sync] --------------------------------------------------- - -[[java-rest-high-multi-search-template-async]] -==== Asynchronous Execution - -The `multiSearchTemplateAsync` method executes `MultiSearchTemplateRequest`s asynchronously, -calling the provided `ActionListener` when the response is ready. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-template-execute-async] --------------------------------------------------- -The parameters are the `MultiSearchTemplateRequest` 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 `MultiSearchTemplateResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-template-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the whole `MultiSearchTemplateRequest` fails. - -==== MultiSearchTemplateResponse - -The `MultiSearchTemplateResponse` that is returned by executing the `multiSearchTemplate` method contains -a `MultiSearchTemplateResponse.Item` for each `SearchTemplateRequest` in the -`MultiSearchTemplateRequest`. Each `MultiSearchTemplateResponse.Item` contains an -exception in `getFailure` if the request failed or a -<> in `getResponse` if -the request succeeded: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-template-response] --------------------------------------------------- -<1> An array of responses is returned - one response for each request -<2> Failed search template requests have error messages -<3> Successful requests contain a <> in -`getResponse`. diff --git a/docs/java-rest/high-level/search/multi-search.asciidoc b/docs/java-rest/high-level/search/multi-search.asciidoc deleted file mode 100644 index 205fe4bfe93e..000000000000 --- a/docs/java-rest/high-level/search/multi-search.asciidoc +++ /dev/null @@ -1,89 +0,0 @@ -[[java-rest-high-multi-search]] -=== Multi-Search API - -The `multiSearch` API executes multiple <> -requests in a single http request in parallel. - -[[java-rest-high-multi-search-request]] -==== Multi-Search Request - -The `MultiSearchRequest` is built empty and you add all of the searches that -you wish to execute to it: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-request-basic] --------------------------------------------------- -<1> Create an empty `MultiSearchRequest`. -<2> Create an empty `SearchRequest` and populate it just like you -would for a regular <>. -<3> Add the `SearchRequest` to the `MultiSearchRequest`. -<4> Build a second `SearchRequest` and add it to the `MultiSearchRequest`. - -===== Optional arguments - -The `SearchRequest`s inside of `MultiSearchRequest` support all of -<>'s optional arguments. -For example: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-request-indices] --------------------------------------------------- -<1> Restricts the request to an index - -[[java-rest-high-multi-search-sync]] -==== Synchronous Execution - -The `multiSearch` method executes `MultiSearchRequest`s synchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-execute] --------------------------------------------------- - -[[java-rest-high-multi-search-async]] -==== Asynchronous Execution - -The `multiSearchAsync` method executes `MultiSearchRequest`s asynchronously, -calling the provided `ActionListener` when the response is ready. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-execute-async] --------------------------------------------------- -<1> The `MultiSearchRequest` 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 `MultiSearchResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the whole `SearchRequest` fails. - -==== MultiSearchResponse - -The `MultiSearchResponse` that is returned by executing the `multiSearch` method contains -a `MultiSearchResponse.Item` for each `SearchRequest` in the -`MultiSearchRequest`. Each `MultiSearchResponse.Item` contains an -exception in `getFailure` if the request failed or a -<> in `getResponse` if -the request succeeded: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[multi-search-response] --------------------------------------------------- -<1> The item for the first search. -<2> It succeeded so `getFailure` returns null. -<3> And there is a <> in -`getResponse`. -<4> The item for the second search. diff --git a/docs/java-rest/high-level/search/point-in-time.asciidoc b/docs/java-rest/high-level/search/point-in-time.asciidoc deleted file mode 100644 index f0321689dc7b..000000000000 --- a/docs/java-rest/high-level/search/point-in-time.asciidoc +++ /dev/null @@ -1,67 +0,0 @@ -[[java-rest-high-point-in-time]] - -=== Open a point in time - -A point in time must be opened before being used in search requests. -An OpenPointInTimeRequest requires an `index` and `keepAlive` arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[open-point-in-time] --------------------------------------------------- -<1> Create an `OpenPointInTimeRequest` with the target indices -<2> Set the `keep_alive` - a required parameter, which tells -Elasticsearch how long it should keep a point in time around. -<3> Read the returned point in time id, which points to the search context that's -being kept alive and will be used in the search requests. - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[open-point-in-time-indices-option] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[open-point-in-time-routing] --------------------------------------------------- -<1> Set a routing parameter - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[open-point-in-time-preference] --------------------------------------------------- -<1> Use the preference parameter e.g. to execute the search to prefer local -shards. The default is to randomize across shards. - -=== Search with point in time -A point in time can be passed to a search request via a PointInTimeBuilder, -which requires a point in time ID returned from the open API. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-point-in-time] --------------------------------------------------- -<1> Create a PointInTimeBuilder with a PIT id -<2> (Optional) Set the keep alive of a point in time -<3> Pass a point in time to a search request - -A search request with a point in time does not accept these parameters: -`indices`, `indicesOptions` `routing`, `preference`, and `ccsMinimizeRoundtrips`. - -A point in time can be used in search after requests to paginate search results. - -=== Close point in time - -Point in time should be closed as soon as they are no longer used in search requests. -A ClosePointInTime request requires a point in time id argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[close-point-in-time] --------------------------------------------------- -<1> Create a close point in time request with a PIT id diff --git a/docs/java-rest/high-level/search/rank-eval.asciidoc b/docs/java-rest/high-level/search/rank-eval.asciidoc deleted file mode 100644 index 195e1f92f3bf..000000000000 --- a/docs/java-rest/high-level/search/rank-eval.asciidoc +++ /dev/null @@ -1,89 +0,0 @@ -[[java-rest-high-rank-eval]] -=== Ranking Evaluation API - -The `rankEval` method allows to evaluate the quality of ranked search -results over a set of search request. Given sets of manually rated -documents for each search request, ranking evaluation performs a -<> request and calculates -information retrieval metrics like _mean reciprocal rank_, _precision_ -or _discounted cumulative gain_ on the returned results. - -[[java-rest-high-rank-eval-request]] -==== Ranking Evaluation Request - -In order to build a `RankEvalRequest`, you first need to create an -evaluation specification (`RankEvalSpec`). This specification requires -to define the evaluation metric that is going to be calculated, as well -as a list of rated documents per search requests. Creating the ranking -evaluation request then takes the specification and a list of target -indices as arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-request-basic] --------------------------------------------------- -<1> Define the metric used in the evaluation -<2> Add rated documents, specified by index name, id and rating -<3> Create the search query to evaluate -<4> Combine the three former parts into a `RatedRequest` -<5> Create the ranking evaluation specification -<6> Create the ranking evaluation request - -[[java-rest-high-rank-eval-sync]] -==== Synchronous Execution - -The `rankEval` method executes `RankEvalRequest`s synchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-execute] --------------------------------------------------- - -[[java-rest-high-rank-eval-async]] -==== Asynchronous Execution - -The `rankEvalAsync` method executes `RankEvalRequest`s asynchronously, -calling the provided `ActionListener` when the response is ready. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-execute-async] --------------------------------------------------- -<1> The `RankEvalRequest` 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 `RankEvalResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the whole `RankEvalRequest` fails. - -==== RankEvalResponse - -The `RankEvalResponse` that is returned by executing the request -contains information about the overall evaluation score, the -scores of each individual search request in the set of queries and -detailed information about search hits and details about the metric -calculation per partial result. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-response] --------------------------------------------------- -<1> The overall evaluation result -<2> Partial results that are keyed by their query id -<3> The metric score for each partial result -<4> Rated search hits contain a fully fledged `SearchHit` -<5> Rated search hits also contain an `Optional` rating that -is not present if the document did not get a rating in the request -<6> Metric details are named after the metric used in the request -<7> After casting to the metric used in the request, the -metric details offers insight into parts of the metric calculation \ No newline at end of file diff --git a/docs/java-rest/high-level/search/scroll.asciidoc b/docs/java-rest/high-level/search/scroll.asciidoc deleted file mode 100644 index 8285243103ab..000000000000 --- a/docs/java-rest/high-level/search/scroll.asciidoc +++ /dev/null @@ -1,220 +0,0 @@ -[[java-rest-high-search-scroll]] -=== Search Scroll API - -The Scroll API can be used to retrieve a large number of results from -a search request. - -In order to use scrolling, the following steps need to be executed in the -given order. - - -==== Initialize the search scroll context - -An initial search request with a `scroll` parameter must be executed to -initialize the scroll session through the <>. -When processing this `SearchRequest`, Elasticsearch detects the presence of -the `scroll` parameter and keeps the search context alive for the -corresponding time interval. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-init] --------------------------------------------------- -<1> Create the `SearchRequest` and its corresponding `SearchSourceBuilder`. -Also optionally set the `size` to control how many results to retrieve at -a time. -<2> Set the scroll interval -<3> Read the returned scroll id, which points to the search context that's -being kept alive and will be needed in the following search scroll call -<4> Retrieve the first batch of search hits - -==== Retrieve all the relevant documents - -As a second step, the received scroll identifier must be set to a -`SearchScrollRequest` along with a new scroll interval and sent through the -`searchScroll` method. Elasticsearch returns another batch of results with -a new scroll identifier. This new scroll identifier can then be used in a -subsequent `SearchScrollRequest` to retrieve the next batch of results, -and so on. This process should be repeated in a loop until no more results are -returned, meaning that the scroll has been exhausted and all the matching -documents have been retrieved. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll2] --------------------------------------------------- -<1> Create the `SearchScrollRequest` by setting the required scroll id and -the scroll interval -<2> Read the new scroll id, which points to the search context that's -being kept alive and will be needed in the following search scroll call -<3> Retrieve another batch of search hits -<4> - -==== Clear the scroll context - -Finally, the last scroll identifier can be deleted using the <> -in order to release the search context. This happens automatically when the -scroll expires, but it's good practice to do it as soon as the scroll session -is completed. - -==== Optional arguments - -The following arguments can optionally be provided when constructing -the `SearchScrollRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[scroll-request-arguments] --------------------------------------------------- -<1> Scroll interval as a `TimeValue` -<2> Scroll interval as a `String` - -If no `scroll` value is set for the `SearchScrollRequest`, the search context will -expire once the initial scroll time expired (ie, the scroll time set in the -initial search request). - -[[java-rest-high-search-scroll-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-execute-sync] --------------------------------------------------- - -[[java-rest-high-search-scroll-async]] -==== Asynchronous Execution - -The asynchronous execution of a search scroll request requires both the `SearchScrollRequest` -instance and an `ActionListener` instance to be passed to the asynchronous -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-execute-async] --------------------------------------------------- -<1> The `SearchScrollRequest` 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 `SearchResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-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 - -[[java-rest-high-search-scroll-response]] -==== Response - -The search scroll API returns a `SearchResponse` object, same as the -Search API. - -[[java-rest-high-search-scroll-example]] -==== Full example - -The following is a complete example of a scrolled search. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-example] --------------------------------------------------- -<1> Initialize the search context by sending the initial `SearchRequest` -<2> Retrieve all the search hits by calling the Search Scroll api in a loop -until no documents are returned -<3> Process the returned search results -<4> Create a new `SearchScrollRequest` holding the last returned scroll -identifier and the scroll interval -<5> Clear the scroll context once the scroll is completed - -[[java-rest-high-clear-scroll]] -=== Clear Scroll API - -The search contexts used by the Search Scroll API are automatically deleted when the scroll -times out. But it is advised to release search contexts as soon as they are not -necessary anymore using the Clear Scroll API. - -[[java-rest-high-clear-scroll-request]] -==== Clear Scroll Request - -A `ClearScrollRequest` can be created as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[clear-scroll-request] --------------------------------------------------- -<1> Create a new `ClearScrollRequest` -<2> Adds a scroll id to the list of scroll identifiers to clear - -==== Providing the scroll identifiers -The `ClearScrollRequest` allows to clear one or more scroll identifiers in a single request. - -The scroll identifiers can be added to the request one by one: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[clear-scroll-add-scroll-id] --------------------------------------------------- - -Or all together using: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[clear-scroll-add-scroll-ids] --------------------------------------------------- - -[[java-rest-high-clear-scroll-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[clear-scroll-execute] --------------------------------------------------- - -[[java-rest-high-clear-scroll-async]] -==== Asynchronous Execution - -The asynchronous execution of a clear scroll request requires both the `ClearScrollRequest` -instance and an `ActionListener` instance to be passed to the asynchronous -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[clear-scroll-execute-async] --------------------------------------------------- -<1> The `ClearScrollRequest` 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 `ClearScrollResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[clear-scroll-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 - -[[java-rest-high-clear-scroll-response]] -==== Clear Scroll Response - -The returned `ClearScrollResponse` allows to retrieve information about the released - search contexts: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[clear-scroll-response] --------------------------------------------------- -<1> Return true if the request succeeded -<2> Return the number of released search contexts diff --git a/docs/java-rest/high-level/search/search-template.asciidoc b/docs/java-rest/high-level/search/search-template.asciidoc deleted file mode 100644 index 3f0dfb8ab28e..000000000000 --- a/docs/java-rest/high-level/search/search-template.asciidoc +++ /dev/null @@ -1,117 +0,0 @@ -[[java-rest-high-search-template]] -=== Search Template API - -The search template API allows for searches to be executed from a template based -on the mustache language, and also for previewing rendered templates. - -[[java-rest-high-search-template-request]] -==== Search Template Request - -===== Inline Templates - -In the most basic form of request, the search template is specified inline: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-template-request-inline] --------------------------------------------------- -<1> The search is executed against the `posts` index. -<2> The template defines the structure of the search source. It is passed -as a string because mustache templates are not always valid JSON. -<3> Before running the search, the template is rendered with the provided parameters. - -===== Registered Templates - -Search templates can be registered in advance through stored scripts API. Note that -the stored scripts API is not yet available in the high-level REST client, so in this -example we use the low-level REST client. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[register-script] --------------------------------------------------- - -Instead of providing an inline script, we can refer to this registered template in the request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-template-request-stored] --------------------------------------------------- - -===== Rendering Templates - -Given parameter values, a template can be rendered without executing a search: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[render-search-template-request] --------------------------------------------------- -<1> Setting `simulate` to `true` causes the search template to only be rendered. - -Both inline and pre-registered templates can be rendered. - -===== Optional Arguments - -As in standard search requests, the `explain` and `profile` options are supported: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-template-request-options] --------------------------------------------------- - -===== Additional References - -The {ref}/search-template.html[Search Template documentation] contains further examples of how search requests can be templated. - -[[java-rest-high-search-template-sync]] -==== Synchronous Execution - -The `searchTemplate` method executes the request synchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-template-execute] --------------------------------------------------- - -==== Asynchronous Execution - -A search template request can be executed asynchronously through the `searchTemplateAsync` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-template-execute-async] --------------------------------------------------- -<1> The `SearchTemplateRequest` to execute and the `ActionListener` to call when the execution completes. - -The asynchronous method does not block and returns immediately. Once the request completes, the -`ActionListener` is called back using the `onResponse` method if the execution completed successfully, -or using the `onFailure` method if it failed. - -A typical listener for `SearchTemplateResponse` is constructed as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-template-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. -<2> Called when the whole `SearchTemplateRequest` fails. - -==== Search Template Response - -For a standard search template request, the response contains a `SearchResponse` object -with the result of executing the search: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-template-response] --------------------------------------------------- - -If `simulate` was set to `true` in the request, then the response -will contain the rendered search source instead of a `SearchResponse`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SearchDocumentationIT.java[render-search-template-response] --------------------------------------------------- -<1> The rendered source in bytes, in our example `{"query": { "match" : { "title" : "elasticsearch" }}, "size" : 5}`. diff --git a/docs/java-rest/high-level/search/search.asciidoc b/docs/java-rest/high-level/search/search.asciidoc deleted file mode 100644 index ea439d7d4191..000000000000 --- a/docs/java-rest/high-level/search/search.asciidoc +++ /dev/null @@ -1,464 +0,0 @@ --- -:api: search -:request: SearchRequest -:response: SearchResponse --- - -[id="{upid}-{api}"] -=== Search API - -[id="{upid}-{api}-request"] -==== Search Request - -The +{request}+ is used for any operation that has to do with searching -documents, aggregations, suggestions and also offers ways of requesting -highlighting on the resulting documents. - -In its most basic form, we can add a query to the request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-basic] --------------------------------------------------- - -<1> Creates the `SearchRequest`. Without arguments this runs against all indices. -<2> Most search parameters are added to the `SearchSourceBuilder`. It offers setters for everything that goes into the search request body. -<3> Add a `match_all` query to the `SearchSourceBuilder`. -<4> Add the `SearchSourceBuilder` to the `SearchRequest`. - -[id="{upid}-{api}-request-optional"] -===== Optional arguments - -Let's first look at some of the optional arguments of a +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indices] --------------------------------------------------- -<1> Restricts the request to an index - -There are a couple of other interesting optional parameters: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Set a routing parameter - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-preference] --------------------------------------------------- -<1> Use the preference parameter e.g. to execute the search to prefer local -shards. The default is to randomize across shards. - -===== Using the SearchSourceBuilder - -Most options controlling the search behavior can be set on the -`SearchSourceBuilder`, -which contains more or less the equivalent of the options in the search request -body of the Rest API. - -Here are a few examples of some common options: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-basics] --------------------------------------------------- -<1> Create a `SearchSourceBuilder` with default options. -<2> Set the query. Can be any type of `QueryBuilder` -<3> Set the `from` option that determines the result index to start searching -from. Defaults to 0. -<4> Set the `size` option that determines the number of search hits to return. -Defaults to 10. -<5> Set an optional timeout that controls how long the search is allowed to -take. - -After this, the `SearchSourceBuilder` only needs to be added to the -+{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-setter] --------------------------------------------------- - -[id="{upid}-{api}-request-building-queries"] -===== Building queries - -Search queries are created using `QueryBuilder` objects. A `QueryBuilder` exists - for every search query type supported by Elasticsearch's {ref}/query-dsl.html[Query DSL]. - -A `QueryBuilder` can be created using its constructor: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-query-builder-ctor] --------------------------------------------------- -<1> Create a full text {ref}/query-dsl-match-query.html[Match Query] that matches -the text "kimchy" over the field "user". - -Once created, the `QueryBuilder` object provides methods to configure the options -of the search query it creates: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-query-builder-options] --------------------------------------------------- -<1> Enable fuzzy matching on the match query -<2> Set the prefix length option on the match query -<3> Set the max expansion options to control the fuzzy - process of the query - -`QueryBuilder` objects can also be created using the `QueryBuilders` utility class. -This class provides helper methods that can be used to create `QueryBuilder` objects - using a fluent programming style: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-query-builders] --------------------------------------------------- - -Whatever the method used to create it, the `QueryBuilder` object must be added -to the `SearchSourceBuilder` as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-query-setter] --------------------------------------------------- - -The <<{upid}-query-builders, Building Queries>> page gives a list of all available search queries with -their corresponding `QueryBuilder` objects and `QueryBuilders` helper methods. - - -===== Specifying Sorting - -The `SearchSourceBuilder` allows to add one or more `SortBuilder` instances. There are four special implementations (Field-, Score-, GeoDistance- and ScriptSortBuilder). - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-sorting] --------------------------------------------------- -<1> Sort descending by `_score` (the default) -<2> Also sort ascending by `_id` field - -===== Source filtering - -By default, search requests return the contents of the document `_source` but like in the Rest API you can overwrite this behavior. For example, you can turn off `_source` retrieval completely: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-filtering-off] --------------------------------------------------- - -The method also accepts an array of one or more wildcard patterns to control which fields get included or excluded in a more fine grained way: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-filtering-includes] --------------------------------------------------- - -[id="{upid}-{api}-request-highlighting"] -===== Requesting Highlighting - -Highlighting search results can be achieved by setting a `HighlightBuilder` on the -`SearchSourceBuilder`. Different highlighting behaviour can be defined for each -fields by adding one or more `HighlightBuilder.Field` instances to a `HighlightBuilder`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-highlighting] --------------------------------------------------- -<1> Creates a new `HighlightBuilder` -<2> Create a field highlighter for the `title` field -<3> Set the field highlighter type -<4> Add the field highlighter to the highlight builder - -There are many options which are explained in detail in the Rest API documentation. The Rest -API parameters (e.g. `pre_tags`) are usually changed by -setters with a similar name (e.g. `#preTags(String ...)`). - -Highlighted text fragments can <<{upid}-{api}-response-highlighting,later be retrieved>> from the +{response}+. - -[id="{upid}-{api}-request-building-aggs"] -===== Requesting Aggregations - -Aggregations can be added to the search by first creating the appropriate -`AggregationBuilder` and then setting it on the `SearchSourceBuilder`. In the -following example we create a `terms` aggregation on company names with a -sub-aggregation on the average age of employees in the company: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aggregations] --------------------------------------------------- - -The <<{upid}-aggregation-builders, Building Aggregations>> page gives a list of all available aggregations with -their corresponding `AggregationBuilder` objects and `AggregationBuilders` helper methods. - -We will later see how to <<{upid}-{api}-response-aggs,access aggregations>> in the +{response}+. - -===== Requesting Suggestions - -To add Suggestions to the search request, use one of the `SuggestionBuilder` implementations -that are easily accessible from the `SuggestBuilders` factory class. Suggestion builders -need to be added to the top level `SuggestBuilder`, which itself can be set on the `SearchSourceBuilder`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-suggestion] --------------------------------------------------- -<1> Creates a new `TermSuggestionBuilder` for the `user` field and -the text `kmichy` -<2> Adds the suggestion builder and names it `suggest_user` - -We will later see how to <<{upid}-{api}-response-suggestions,retrieve suggestions>> from the -+{response}+. - -===== Profiling Queries and Aggregations - -The {ref}/search-profile.html[Profile API] can be used to profile the execution of queries and aggregations for -a specific search request. in order to use it, the profile flag must be set to true on the `SearchSourceBuilder`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-profiling] --------------------------------------------------- - -Once the +{request}+ is executed the corresponding +{response}+ will -<<{upid}-{api}-response-profile,contain the profiling results>>. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== {response} - -The +{response}+ that is returned by executing the search provides details -about the search execution itself as well as access to the documents returned. -First, there is useful information about the request execution itself, like the -HTTP status code, execution time or whether the request terminated early or timed -out: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-1] --------------------------------------------------- - -Second, the response also provides information about the execution on the -shard level by offering statistics about the total number of shards that were -affected by the search, and the successful vs. unsuccessful shards. Possible -failures can also be handled by iterating over an array off -`ShardSearchFailures` like in the following example: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response-2] --------------------------------------------------- - -[id="{upid}-{api}-response-search-hits"] -===== Retrieving SearchHits - -To get access to the returned documents, we need to first get the `SearchHits` -contained in the response: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-hits-get] --------------------------------------------------- - -The `SearchHits` provides global information about all hits, like total number -of hits or the maximum score: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-hits-info] --------------------------------------------------- - -Nested inside the `SearchHits` are the individual search results that can -be iterated over: - - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-hits-singleHit] --------------------------------------------------- - -The `SearchHit` provides access to basic information like index, document ID -and score of each search hit: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-hits-singleHit-properties] --------------------------------------------------- - -Furthermore, it lets you get back the document source, either as a simple -JSON-String or as a map of key/value pairs. In this map, regular fields -are keyed by the field name and contain the field value. Multi-valued fields are -returned as lists of objects, nested objects as another key/value map. These -cases need to be cast accordingly: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-hits-singleHit-source] --------------------------------------------------- - -[id="{upid}-{api}-response-highlighting"] -===== Retrieving Highlighting - -If <<{upid}-{api}-request-highlighting,requested>>, highlighted text fragments can be retrieved from each `SearchHit` in the result. The hit object offers -access to a map of field names to `HighlightField` instances, each of which contains one -or many highlighted text fragments: - - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-highlighting-get] --------------------------------------------------- -<1> Get the highlighting for the `title` field -<2> Get one or many fragments containing the highlighted field content - -[id="{upid}-{api}-response-aggs"] -===== Retrieving Aggregations - -Aggregations can be retrieved from the +{response}+ by first getting the -root of the aggregation tree, the `Aggregations` object, and then getting the -aggregation by name. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aggregations-get] --------------------------------------------------- -<1> Get the `by_company` terms aggregation -<2> Get the buckets that is keyed with `Elastic` -<3> Get the `average_age` sub-aggregation from that bucket - -Note that if you access aggregations by name, you need to specify the -aggregation interface according to the type of aggregation you requested, -otherwise a `ClassCastException` will be thrown: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[search-request-aggregations-get-wrongCast] --------------------------------------------------- -<1> This will throw an exception because "by_company" is a `terms` aggregation -but we try to retrieve it as a `range` aggregation - -It is also possible to access all aggregations as a map that is keyed by the -aggregation name. In this case, the cast to the proper aggregation interface -needs to happen explicitly: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aggregations-asMap] --------------------------------------------------- - -There are also getters that return all top level aggregations as a list: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aggregations-asList] --------------------------------------------------- - -And last but not least you can iterate over all aggregations and then e.g. -decide how to further process them based on their type: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-aggregations-iterator] --------------------------------------------------- - -[id="{upid}-{api}-response-suggestions"] -===== Retrieving Suggestions - -To get back the suggestions from a +{response}+, use the `Suggest` object as an entry point and then retrieve the nested suggestion objects: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-suggestion-get] --------------------------------------------------- -<1> Use the `Suggest` class to access suggestions -<2> Suggestions can be retrieved by name. You need to assign them to the correct -type of Suggestion class (here `TermSuggestion`), otherwise a `ClassCastException` is thrown -<3> Iterate over the suggestion entries -<4> Iterate over the options in one entry - -[id="{upid}-{api}-response-profile"] -===== Retrieving Profiling Results - -Profiling results are retrieved from a +{response}+ using the `getProfileResults()` method. This - method returns a `Map` containing a `ProfileShardResult` object for every shard involved in the - +{request}+ execution. `ProfileShardResult` are stored in the `Map` using a key that uniquely - identifies the shard the profile result corresponds to. - -Here is a sample code that shows how to iterate over all the profiling results of every shard: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-profiling-get] --------------------------------------------------- -<1> Retrieve the `Map` of `ProfileShardResult` from the +{response}+ -<2> Profiling results can be retrieved by shard's key if the key is known, otherwise it might be simpler - to iterate over all the profiling results -<3> Retrieve the key that identifies which shard the `ProfileShardResult` belongs to -<4> Retrieve the `ProfileShardResult` for the given shard - -The `ProfileShardResult` object itself contains one or more query profile results, one for each query -executed against the underlying Lucene index: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-profiling-queries] --------------------------------------------------- -<1> Retrieve the list of `QueryProfileShardResult` -<2> Iterate over each `QueryProfileShardResult` - -Each `QueryProfileShardResult` gives access to the detailed query tree execution, returned as a list of -`ProfileResult` objects: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-profiling-queries-results] --------------------------------------------------- -<1> Iterate over the profile results -<2> Retrieve the name of the Lucene query -<3> Retrieve the time in millis spent executing the Lucene query -<4> Retrieve the profile results for the sub-queries (if any) - -The Rest API documentation contains more information about {ref}/search-profile.html#profiling-queries[Profiling Queries] with -a description of the query profiling information. - -The `QueryProfileShardResult` also gives access to the profiling information for the Lucene collectors: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-profiling-queries-collectors] --------------------------------------------------- -<1> Retrieve the profiling result of the Lucene collector -<2> Retrieve the name of the Lucene collector -<3> Retrieve the time in millis spent executing the Lucene collector -<4> Retrieve the profile results for the sub-collectors (if any) - -The Rest API documentation contains more information about profiling information -for Lucene collectors. See {ref}/search-profile.html#profiling-queries[Profiling queries]. - -In a very similar manner to the query tree execution, the `QueryProfileShardResult` objects gives access -to the detailed aggregations tree execution: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-profiling-aggs] --------------------------------------------------- -<1> Retrieve the `AggregationProfileShardResult` -<2> Iterate over the aggregation profile results -<3> Retrieve the type of the aggregation (corresponds to Java class used to execute the aggregation) -<4> Retrieve the time in millis spent executing the Lucene collector -<5> Retrieve the profile results for the sub-aggregations (if any) - -The Rest API documentation contains more information about -{ref}/search-profile.html#profiling-aggregations[Profiling aggregations]. diff --git a/docs/java-rest/high-level/searchable_snapshots/caches_stats.asciidoc b/docs/java-rest/high-level/searchable_snapshots/caches_stats.asciidoc deleted file mode 100644 index a0d99107b8dc..000000000000 --- a/docs/java-rest/high-level/searchable_snapshots/caches_stats.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ --- -:api: searchable-snapshots-caches-stats -:request: CachesStatsRequest -:response: CachesStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Cache Stats API - -[id="{upid}-{api}-request"] -==== Request - -Retrieves statistics about the shared cache for -{ref}/searchable-snapshots.html#partially-mounted[partially mounted indices]. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Example of a request targeting all data nodes. -<2> Example of a request targeting two specific nodes. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ provides the following statistics: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The list of cache statistics for all nodes involved in the request. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/searchable_snapshots/mount_snapshot.asciidoc b/docs/java-rest/high-level/searchable_snapshots/mount_snapshot.asciidoc deleted file mode 100644 index 888c50d59686..000000000000 --- a/docs/java-rest/high-level/searchable_snapshots/mount_snapshot.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: searchable-snapshots-mount-snapshot -:request: MountSnapshotRequest -:response: MountSnapshotResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Mount Snapshot API - -[id="{upid}-{api}-request"] -==== Request - -The Mount Snapshot API mounts a snapshot as a searchable snapshot. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The name of the repository. -<2> The name of the snapshot. -<3> The name of the index in the snapshot to mount. -<4> (optional) The period to wait for a connection to the master node. -<5> (optional) If true, the request blocks until the operation is complete. -<6> (optional) The type of local storage to use for the mounted snapshot. -<7> (optional) The name of the index that will be created. -<8> (optional) Settings that should be added to the mounted index. -<9> (optional) Names of settings that should be unset when the index is mounted. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ indicates if the mounted snapshot was restored. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The restore info of the mounted snapshot. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/security/authenticate.asciidoc b/docs/java-rest/high-level/security/authenticate.asciidoc deleted file mode 100644 index 4843d0c290f9..000000000000 --- a/docs/java-rest/high-level/security/authenticate.asciidoc +++ /dev/null @@ -1,79 +0,0 @@ - --- -:api: authenticate -:response: AuthenticateResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Authenticate API - -[id="{upid}-{api}-sync"] -==== Execution - -Authenticating and retrieving information about a user can be performed -using the `security().authenticate()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute] --------------------------------------------------- - -This method does not require a request object. The client waits for the -+{response}+ to be returned before continuing with code execution. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains four fields. The `user` field -, accessed with `getUser`, contains all the information about this -authenticated user. The field `enabled`, tells if this user is actually -usable or has been temporarily deactivated. The field `authentication_realm`, -accessed with `getAuthenticationRealm` contains the name and type of the -Realm that has authenticated the user and the field `lookup_realm`, -accessed with `getLookupRealm` contains the name and type of the Realm where -the user information were retrieved from. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `getUser` retrieves the `User` instance containing the information, -see {javadoc-client}/security/user/User.html. -<2> `enabled` tells if this user is usable or is deactivated. -<3> `getAuthenticationRealm().getName()` retrieves the name of the realm that authenticated the user. -<4> `getAuthenticationRealm().getType()` retrieves the type of the realm that authenticated the user. -<5> `getLookupRealm().getName()` retrieves the name of the realm from where the user information is looked up. -<6> `getLookupRealm().getType()` retrieves the type of the realm from where the user information is looked up. -<7> `getAuthenticationType()` retrieves the authentication type of the authenticated user. -<8> `getMetadata()` retrieves metadata relevant to this authentication. -Note this is different from `user.getMetadata()`. -For <<{upid}-create-service-account-token,service account token>> authentication, it contains -a key of `_token_name` with the value being the token name. - -[id="{upid}-{api}-async"] -==== Asynchronous Execution - -This request can also be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] --------------------------------------------------- -<1> The `ActionListener` to use when the execution completes. This method does -not require a request object. - -The asynchronous method does not block and returns immediately. Once the request -has completed the `ActionListener` is called back using the `onResponse` method -if the execution completed successfully or using the `onFailure` method if -it failed. - -A typical listener for a +{response}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-listener] --------------------------------------------------- -<1> Called when the execution completed successfully. The response is -provided as an argument. -<2> Called in case of a failure. The exception is provided as an argument. - diff --git a/docs/java-rest/high-level/security/change-password.asciidoc b/docs/java-rest/high-level/security/change-password.asciidoc deleted file mode 100644 index 6593e8105981..000000000000 --- a/docs/java-rest/high-level/security/change-password.asciidoc +++ /dev/null @@ -1,46 +0,0 @@ -[role="xpack"] -[[java-rest-high-security-change-password]] -=== Change Password API - -[[java-rest-high-security-change-password-execution]] -==== Execution - -A user's password can be changed using the `security().changePassword()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[change-password-execute] --------------------------------------------------- - -[[java-rest-high-change-password-response]] -==== Response - -The returned `Boolean` indicates the request status. - -[[java-rest-high-x-pack-security-change-password-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[change-password-execute-async] --------------------------------------------------- -<1> The `ChangePassword` request to execute and the `ActionListener` to use when -the execution completes. - -The asynchronous method does not block and returns immediately. Once the request -has 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 a `Boolean` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[change-password-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. diff --git a/docs/java-rest/high-level/security/clear-api-key-cache.asciidoc b/docs/java-rest/high-level/security/clear-api-key-cache.asciidoc deleted file mode 100644 index 2d680145496e..000000000000 --- a/docs/java-rest/high-level/security/clear-api-key-cache.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ - --- -:api: clear-api-key-cache -:request: ClearApiKeyCacheRequest -:response: ClearSecurityCacheResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Clear API Key Cache API - -[id="{upid}-{api}-request"] -==== Clear API Key Cache Request - -A +{request}+ supports clearing API key cache for the given IDs. -It can also clear the entire cache if no ID is specified. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> the IDs(s) for the API keys to be evicted from the cache - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Clear API Key Cache Response - -The returned +{response}+ allows to retrieve information about where the cache was cleared. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> the list of nodes that the cache was cleared on diff --git a/docs/java-rest/high-level/security/clear-privileges-cache.asciidoc b/docs/java-rest/high-level/security/clear-privileges-cache.asciidoc deleted file mode 100644 index 2376c6a5bd88..000000000000 --- a/docs/java-rest/high-level/security/clear-privileges-cache.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ - --- -:api: clear-privileges-cache -:request: ClearPrivilegesCacheRequest -:response: ClearPrivilegesCacheResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Clear Privileges Cache API - -[id="{upid}-{api}-request"] -==== Clear Privileges Cache Request - -A +{request}+ supports defining the name of applications that the cache should be cleared for. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> the name of the application(s) for which the cache should be cleared - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Clear Privileges Cache Response - -The returned +{response}+ allows to retrieve information about where the cache was cleared. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> the list of nodes that the cache was cleared on diff --git a/docs/java-rest/high-level/security/clear-realm-cache.asciidoc b/docs/java-rest/high-level/security/clear-realm-cache.asciidoc deleted file mode 100644 index 41c100e1ec88..000000000000 --- a/docs/java-rest/high-level/security/clear-realm-cache.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ - --- -:api: clear-realm-cache -:request: ClearRealmCacheRequest -:response: ClearRealmCacheResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Clear Realm Cache API - -[id="{upid}-{api}-request"] -==== Clear Realm Cache Request - -A +{request}+ supports defining the name of realms and usernames that the cache should be cleared -for. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Clear Roles Cache Response - -The returned +{response}+ allows to retrieve information about where the cache was cleared. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> the list of nodes that the cache was cleared on diff --git a/docs/java-rest/high-level/security/clear-roles-cache.asciidoc b/docs/java-rest/high-level/security/clear-roles-cache.asciidoc deleted file mode 100644 index 39e344f6ce98..000000000000 --- a/docs/java-rest/high-level/security/clear-roles-cache.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ - --- -:api: clear-roles-cache -:request: ClearRolesCacheRequest -:response: ClearRolesCacheResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Clear Roles Cache API - -[id="{upid}-{api}-request"] -==== Clear Roles Cache Request - -A +{request}+ supports defining the name of roles that the cache should be cleared for. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Clear Roles Cache Response - -The returned +{response}+ allows to retrieve information about where the cache was cleared. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> the list of nodes that the cache was cleared on diff --git a/docs/java-rest/high-level/security/clear-service-account-token-cache.asciidoc b/docs/java-rest/high-level/security/clear-service-account-token-cache.asciidoc deleted file mode 100644 index 2a1af06033c1..000000000000 --- a/docs/java-rest/high-level/security/clear-service-account-token-cache.asciidoc +++ /dev/null @@ -1,37 +0,0 @@ - --- -:api: clear-service-account-token-cache -:request: ClearServiceAccountTokenCacheRequest -:response: ClearSecurityCacheResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Clear Service Account Token Cache API - -[id="{upid}-{api}-request"] -==== Clear Service Account Token Cache Request - -A +{request}+ supports clearing service account token cache for the given -namespace, service name and token names. -It can also clear the entire cache if a `*` is specified for the token name. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Namespace of the service account -<2> Service name of the service account -<3> Name(s) for the service account token to be evicted from the cache - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Clear Service Account Token Cache Response - -The returned +{response}+ allows to retrieve information about where the cache was cleared. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> the list of nodes that the cache was cleared on diff --git a/docs/java-rest/high-level/security/create-api-key.asciidoc b/docs/java-rest/high-level/security/create-api-key.asciidoc deleted file mode 100644 index 77487cbd440d..000000000000 --- a/docs/java-rest/high-level/security/create-api-key.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: create-api-key -:request: CreateApiKeyRequest -:response: CreateApiKeyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create API Key API - -API Key can be created using this API. - -[id="{upid}-{api}-request"] -==== Create API Key Request - -A +{request}+ contains an optional name for the API key, -an optional list of role descriptors to define permissions and -optional expiration for the generated API key. -If expiration is not provided then by default the API -keys do not expire. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Create API Key Response - -The returned +{response}+ contains an id, -API key, name for the API key and optional -expiration. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> the API key credentials that can be used to authenticate to Elasticsearch. -<2> expiration if the API keys expire diff --git a/docs/java-rest/high-level/security/create-service-account-token.asciidoc b/docs/java-rest/high-level/security/create-service-account-token.asciidoc deleted file mode 100644 index e0f451257d7f..000000000000 --- a/docs/java-rest/high-level/security/create-service-account-token.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ --- -:api: create-service-account-token -:request: CreateServiceAccountTokenRequest -:response: CreateServiceAccountTokenResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create Service Account Token API - -Index-based service account token can be created using this API. - -[id="{upid}-{api}-request"] -==== Create Service Account Token Request - -A +{request}+ contains the namespace and service-name of a -service account and an optional name for the service account token. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -A token name will be auto generated if the +{request}+ does not specify it: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-auto-name] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Create Service Account Token Response - -The returned +{response}+ contains the name and value of the service account token. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Name of the service account token -<2> Value of the service account token to be used as the bearer authentication header diff --git a/docs/java-rest/high-level/security/create-token.asciidoc b/docs/java-rest/high-level/security/create-token.asciidoc deleted file mode 100644 index b20242220479..000000000000 --- a/docs/java-rest/high-level/security/create-token.asciidoc +++ /dev/null @@ -1,88 +0,0 @@ -[role="xpack"] -[[java-rest-high-security-create-token]] -=== Create Token API - -[[java-rest-high-security-create-token-request]] -==== Request -The `CreateTokenRequest` supports three different OAuth2 _grant types_: - -===== Password Grants - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[create-token-password-request] --------------------------------------------------- - -===== Refresh Token Grants -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[create-token-refresh-request] --------------------------------------------------- - -===== Client Credential Grants -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[create-token-client-credentials-request] --------------------------------------------------- - -[[java-rest-high-security-create-token-execution]] -==== Execution - -Creating a OAuth2 security token can be performed by passing the appropriate request to the - `security().createToken()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[create-token-execute] --------------------------------------------------- - -[[java-rest-high-security-create-token-response]] -==== Response - -The returned `CreateTokenResponse` contains the following properties: - -`accessToken`:: This is the newly created access token. - It can be used to authenticate to the Elasticsearch cluster. -`type`:: The type of the token, this is always `"Bearer"`. -`expiresIn`:: The length of time until the token will expire. - The token will be considered invalid after that time. -`scope`:: The scope of the token. May be `null`. -`refreshToken`:: A secondary "refresh" token that may be used to extend - the life of an access token. May be `null`. -`authentication`:: This is the authentication object for the newly created token. See also -<<{upid}-authenticate-response, authenticate response>> for details. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[create-token-response] --------------------------------------------------- -<1> The `accessToken` can be used to authentication to Elasticsearch. -<2> The `refreshToken` can be used in to create a new `CreateTokenRequest` with a `refresh_token` grant. - -[[java-rest-high-security-create-token-async]] -==== Asynchronous Execution - -This request can be executed asynchronously using the `security().createTokenAsync()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[create-token-execute-async] --------------------------------------------------- -<1> The `CreateTokenRequest` to execute and the `ActionListener` to use when -the execution completes - -The asynchronous method does not block and returns immediately. Once the request -has 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 a `CreateTokenResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[create-token-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 diff --git a/docs/java-rest/high-level/security/delegate-pki-authentication.asciidoc b/docs/java-rest/high-level/security/delegate-pki-authentication.asciidoc deleted file mode 100644 index 189318d15000..000000000000 --- a/docs/java-rest/high-level/security/delegate-pki-authentication.asciidoc +++ /dev/null @@ -1,64 +0,0 @@ --- -:api: delegate-pki -:request: DelegatePkiAuthenticationRequest -:response: DelegatePkiAuthenticationResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delegate PKI Authentication API - -This API is called by *smart* proxies to Elasticsearch, such as Kibana, that -terminate the user's TLS session but that still wish to authenticate the user -on the Elasticsearch side using a PKI realm, which normally requires users to -authenticate over TLS directly to Elasticsearch. It implements the exchange of -the client's {@code X509Certificate} chain from the TLS authentication into an -Elasticsearch access token. - -IMPORTANT: The association between the subject public key in the target -certificate and the corresponding private key is *not* validated. This is part -of the TLS authentication process and it is delegated to the proxy calling this -API. The proxy is *trusted* to have performed the TLS authentication, and this -API translates that authentication into an Elasticsearch access token. - -[id="{upid}-{api}-request"] -==== Delegate PKI Authentication Request - -The request contains the client's {@code X509Certificate} chain. The -certificate chain is represented as a list where the first element is the -target certificate containing the subject distinguished name that is requesting -access. This may be followed by additional certificates, with each subsequent -certificate being the one used to certify the previous one. The certificate -chain is validated according to RFC 5280, by sequentially considering the trust -configuration of every installed {@code PkiRealm} that has {@code -PkiRealmSettings#DELEGATION_ENABLED_SETTING} set to {@code true} (default is -{@code false}). A successfully trusted target certificate is also subject to -the validation of the subject distinguished name according to that respective's -realm {@code PkiRealmSettings#USERNAME_PATTERN_SETTING}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[delegate-pki-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delegate PKI Authentication Response - -The returned +{response}+ contains the following properties: - -`accessToken`:: This is the newly created access token. - It can be used to authenticate to the Elasticsearch cluster. -`type`:: The type of the token, this is always `"Bearer"`. -`expiresIn`:: The length of time (in seconds) until the token will expire. - The token will be considered invalid after that time. -`authentication`:: This is the authentication object for the newly created token. See also -<<{upid}-authenticate-response, authenticate response>> for details. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[delegate-pki-response] --------------------------------------------------- -<1> The `accessToken` can be used to authentication to Elasticsearch. - - diff --git a/docs/java-rest/high-level/security/delete-privileges.asciidoc b/docs/java-rest/high-level/security/delete-privileges.asciidoc deleted file mode 100644 index 827ccf5b1e52..000000000000 --- a/docs/java-rest/high-level/security/delete-privileges.asciidoc +++ /dev/null @@ -1,37 +0,0 @@ --- -:api: delete-privileges -:request: DeletePrivilegesRequest -:response: DeletePrivilegesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Privileges API - -This API can be used to delete application privileges. - -[id="{upid}-{api}-request"] -==== Delete Application Privileges Request - -A +{request}+ has two arguments - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> the name of application -<2> the name(s) of the privileges to delete that belong to the given application - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete Application Privileges Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> the name of the application -<2> whether the given privilege was found and deleted diff --git a/docs/java-rest/high-level/security/delete-role-mapping.asciidoc b/docs/java-rest/high-level/security/delete-role-mapping.asciidoc deleted file mode 100644 index 5279d9536885..000000000000 --- a/docs/java-rest/high-level/security/delete-role-mapping.asciidoc +++ /dev/null @@ -1,52 +0,0 @@ -[role="xpack"] -[[java-rest-high-security-delete-role-mapping]] -=== Delete Role Mapping API - -[[java-rest-high-security-delete-role-mapping-execution]] -==== Execution -Deletion of a role mapping can be performed using the `security().deleteRoleMapping()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[delete-role-mapping-execute] --------------------------------------------------- - -[[java-rest-high-security-delete-role-mapping-response]] -==== Response -The returned `DeleteRoleMappingResponse` contains a single field, `found`. If the mapping -is successfully found and deleted, found is set to true. Otherwise, found is set to false. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[delete-role-mapping-response] --------------------------------------------------- -<1> `found` is a boolean indicating whether the role mapping was found and deleted - -[[java-rest-high-security-delete-role-mapping-async]] -==== Asynchronous Execution - -This request can be executed asynchronously using the `security().deleteRoleMappingAsync()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[delete-role-mapping-execute-async] --------------------------------------------------- -<1> The `DeleteRoleMappingRequest` to execute and the `ActionListener` to use when -the execution completes - -The asynchronous method does not block and returns immediately. Once the request -has 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 a `DeleteRoleMappingResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[delete-role-mapping-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 diff --git a/docs/java-rest/high-level/security/delete-role.asciidoc b/docs/java-rest/high-level/security/delete-role.asciidoc deleted file mode 100644 index d2f4ef6f88ad..000000000000 --- a/docs/java-rest/high-level/security/delete-role.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ --- -:api: delete-role -:request: DeleteRoleRequest -:response: DeleteRoleResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Role API - -[id="{upid}-{api}-request"] -==== Delete Role Request - -A +{request}+ has a single argument - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> role to delete - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> whether the given role was found diff --git a/docs/java-rest/high-level/security/delete-service-account-token.asciidoc b/docs/java-rest/high-level/security/delete-service-account-token.asciidoc deleted file mode 100644 index e066b47de58e..000000000000 --- a/docs/java-rest/high-level/security/delete-service-account-token.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ --- -:api: delete-service-account-token -:request: DeleteServiceAccountTokenRequest -:response: DeleteServiceAccountTokenResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete Service Account Token API - -Index-based service account token can be deleted using this API. - -[id="{upid}-{api}-request"] -==== Delete Service Account Token Request - -A +{request}+ contains the namespace, service-name and token name of a -service account token. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Delete Service Account Token Response - -The returned +{response}+ allows to retrieve information about the executed -operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> whether the given service account token was found diff --git a/docs/java-rest/high-level/security/delete-user.asciidoc b/docs/java-rest/high-level/security/delete-user.asciidoc deleted file mode 100644 index 43d65fc4e976..000000000000 --- a/docs/java-rest/high-level/security/delete-user.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ --- -:api: delete-user -:request: DeleteUserRequest -:response: DeleteUserResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete User API - -[id="{upid}-{api}-request"] -==== Delete User Request - -A user can be deleted as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Delete Response - -The returned +{response}+ allows to retrieve information about the executed - operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> whether the given user was found - -include::../execution.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/high-level/security/disable-user.asciidoc b/docs/java-rest/high-level/security/disable-user.asciidoc deleted file mode 100644 index 90b89c2779fb..000000000000 --- a/docs/java-rest/high-level/security/disable-user.asciidoc +++ /dev/null @@ -1,46 +0,0 @@ -[role="xpack"] -[[java-rest-high-security-disable-user]] -=== Disable User API - -[[java-rest-high-security-disable-user-execution]] -==== Execution - -Disabling a user can be performed using the `security().disableUser()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[disable-user-execute] --------------------------------------------------- - -[[java-rest-high-security-disable-user-response]] -==== Response - -The returned `Boolean` indicates the request status. - -[[java-rest-high-security-disable-user-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[disable-user-execute-async] --------------------------------------------------- -<1> The `DisableUser` request to execute and the `ActionListener` to use when -the execution completes. - -The asynchronous method does not block and returns immediately. Once the request -has 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 a `Boolean` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[disable-user-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. diff --git a/docs/java-rest/high-level/security/enable-user.asciidoc b/docs/java-rest/high-level/security/enable-user.asciidoc deleted file mode 100644 index 7e8bac12e270..000000000000 --- a/docs/java-rest/high-level/security/enable-user.asciidoc +++ /dev/null @@ -1,46 +0,0 @@ -[role="xpack"] -[[java-rest-high-security-enable-user]] -=== Enable User API - -[[java-rest-high-security-enable-user-execution]] -==== Execution - -Enabling a disabled user can be performed using the `security().enableUser()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[enable-user-execute] --------------------------------------------------- - -[[java-rest-high-security-enable-user-response]] -==== Response - -The returned `Boolean` indicates the request status. - -[[java-rest-high-security-enable-user-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[enable-user-execute-async] --------------------------------------------------- -<1> The `EnableUser` request to execute and the `ActionListener` to use when -the execution completes. - -The asynchronous method does not block and returns immediately. Once the request -has 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 a `Boolean` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[enable-user-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. diff --git a/docs/java-rest/high-level/security/enroll_kibana.asciidoc b/docs/java-rest/high-level/security/enroll_kibana.asciidoc deleted file mode 100644 index c6a7da354d06..000000000000 --- a/docs/java-rest/high-level/security/enroll_kibana.asciidoc +++ /dev/null @@ -1,51 +0,0 @@ --- -:api: kibana-enrollment -:request: KibanaEnrollmentRequest -:response: KibanaEnrollmentResponse --- - -[id="{upid}-{api}"] -=== Enroll Kibana API - -Allows a kibana instance to configure itself to communicate with a secured {es} cluster. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Enroll Kibana Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/EnrollmentDocumentationIT.java[{api}-response] --------------------------------------------------- -<1> The bearer token for the `elastic/kibana` service account. -Use this token to {ref}/service-accounts.html#authenticate-with-service-account-token[authenticate the service account] with {es}. -<2> The value of the bearer token for the `elastic/kibana` service account. -<3> The CA certificate used to sign the node certificates that {es} uses for TLS -on the HTTP layer. The certificate is returned as a Base64 encoded string of the -ASN.1 DER encoding of the certificate. - - -[id="{upid}-{api}-execute-async"] -==== Asynchronous Execution - -This request can be executed asynchronously using the `security().enrollClientAsync()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/EnrollmentDocumentationIT.java[{api}-execute-async] --------------------------------------------------- - -A typical listener for a `KibanaEnrollmentResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/EnrollmentDocumentationIT.java[{api}-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 diff --git a/docs/java-rest/high-level/security/enroll_node.asciidoc b/docs/java-rest/high-level/security/enroll_node.asciidoc deleted file mode 100644 index 7fb945c54b59..000000000000 --- a/docs/java-rest/high-level/security/enroll_node.asciidoc +++ /dev/null @@ -1,65 +0,0 @@ --- -:api: node-enrollment -:request: NodeEnrollmentRequest -:response: NodeEnrollmentResponse --- - -[id="{upid}-{api}"] -=== Enroll Node API - -Allows a new node to join an existing cluster with security features enabled. - -The purpose of the enroll node API is to allow a new node to join an existing cluster -where security is enabled. The enroll node API response contains all the necessary information -for the joining node to bootstrap discovery and security related settings so that it -can successfully join the cluster. - -NOTE: The response contains key and certificate material that allows the -caller to generate valid signed certificates for the HTTP layer of all nodes in the cluster. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Enroll Node Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/EnrollmentDocumentationIT.java[{api}-response] --------------------------------------------------- -<1> The CA private key that can be used by the new node in order to sign its certificate -for the HTTP layer, as a Base64 encoded string of the ASN.1 DER encoding of the key. -<2> The CA certificate that can be used by the new node in order to sign its certificate -for the HTTP layer, as a Base64 encoded string of the ASN.1 DER encoding of the certificate. -<3> The CA certificate that is used to sign the TLS certificate for the transport layer, as -a Base64 encoded string of the ASN.1 DER encoding of the certificate. -<4> The private key that the node can use for TLS for its transport layer, as a Base64 -encoded string of the ASN.1 DER encoding of the key. -<5> The certificate that the node can use for TLS for its transport layer, as a Base64 -encoded string of the ASN.1 DER encoding of the certificate. -<6> A list of transport addresses in the form of `host:port` for the nodes that are already -members of the cluster. - - -[id="{upid}-{api}-execute-async"] -==== Asynchronous Execution - -This request can be executed asynchronously using the `security().enrollNodeAsync()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/EnrollmentDocumentationIT.java[{api}-execute-async] --------------------------------------------------- - -A typical listener for a `NodeEnrollmentResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/EnrollmentDocumentationIT.java[{api}-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 diff --git a/docs/java-rest/high-level/security/get-api-key.asciidoc b/docs/java-rest/high-level/security/get-api-key.asciidoc deleted file mode 100644 index e8dad80b59b0..000000000000 --- a/docs/java-rest/high-level/security/get-api-key.asciidoc +++ /dev/null @@ -1,83 +0,0 @@ --- -:api: get-api-key -:request: GetApiKeyRequest -:response: GetApiKeyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get API Key information API - -API Key(s) information can be retrieved using this API. - -[id="{upid}-{api}-request"] -==== Get API Key Request -The +{request}+ supports retrieving API key information for - -. A specific API key - -. All API keys for a specific realm - -. All API keys for a specific user - -. All API keys for a specific user in a specific realm - -. A specific key or all API keys owned by the current authenticated user - -. All API keys if the user is authorized to do so - -===== Retrieve a specific API key by its id -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-api-key-id-request] --------------------------------------------------- - -===== Retrieve a specific API key by its name -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-api-key-name-request] --------------------------------------------------- - -===== Retrieve all API keys for given realm -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-realm-api-keys-request] --------------------------------------------------- - -===== Retrieve all API keys for a given user -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-user-api-keys-request] --------------------------------------------------- - -===== Retrieve all API keys for given user in a realm -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-user-realm-api-keys-request] --------------------------------------------------- - -===== Retrieve all API keys for the current authenticated user -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-api-keys-owned-by-authenticated-user-request] --------------------------------------------------- - -===== Retrieve all API keys if the user is authorized to do so -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-all-api-keys-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get API Key information API Response - -The returned +{response}+ contains the information regarding the API keys that were -requested. - -`api_keys`:: Available using `getApiKeyInfos`, contains list of API keys that were retrieved for this request. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/security/get-builtin-privileges.asciidoc b/docs/java-rest/high-level/security/get-builtin-privileges.asciidoc deleted file mode 100644 index c7225e085f53..000000000000 --- a/docs/java-rest/high-level/security/get-builtin-privileges.asciidoc +++ /dev/null @@ -1,30 +0,0 @@ --- -:api: get-builtin-privileges -:request: GetBuiltinPrivilegesRequest -:response: GetBuiltinPrivilegesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Builtin Privileges API - -Retrieves the list of cluster privileges and index privileges that are -available in this version of {es}. - -include::../execution-no-req.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Builtin Privileges Response - -The returned +{response}+ contains the following properties - -`clusterPrivileges`:: -A `Set` of all _cluster_ privileges that are understood by this node. - -`indexPrivileges`:: -A `Set` of all _index_ privileges that are understood by this node. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- - diff --git a/docs/java-rest/high-level/security/get-certificates.asciidoc b/docs/java-rest/high-level/security/get-certificates.asciidoc deleted file mode 100644 index 5ada3c8a712d..000000000000 --- a/docs/java-rest/high-level/security/get-certificates.asciidoc +++ /dev/null @@ -1,35 +0,0 @@ - --- -:api: get-certificates -:response: GetSslCertificatesResponse --- - -[role="xpack"] -[id="{upid}-{api}"] -=== SSL Certificate API - -[id="{upid}-{api}-request"] -==== Get Certificates Request - -The X.509 Certificates that are used to encrypt communications in an -Elasticsearch cluster using the `security().getSslCertificates()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[{api}-execute] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Get Certificates Response - -The returned +{response}+ contains a single field, `certificates`. -This field, accessed with `getCertificates` returns a List of `CertificateInfo` -objects containing the information for all the certificates used. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[{api}-response] --------------------------------------------------- -<1> `certificates` is a List of `CertificateInfo` - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/security/get-privileges.asciidoc b/docs/java-rest/high-level/security/get-privileges.asciidoc deleted file mode 100644 index 9775daddfcaa..000000000000 --- a/docs/java-rest/high-level/security/get-privileges.asciidoc +++ /dev/null @@ -1,49 +0,0 @@ - --- -:api: get-privileges -:request: GetPrivilegesRequest -:response: GetPrivilegesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Application Privileges API - -Retrieves application privileges. - -[id="{upid}-{api}-request"] -==== Get Privileges Request - -The +{request}+ supports getting privileges for all or for specific applications. - -===== Specific privilege of a specific application - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -===== All privileges of a specific application - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-all-application-privileges-request] --------------------------------------------------- - -===== All privileges of all applications - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[get-all-privileges-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Privileges Response - -The returned +{response}+ allows to get information about the retrieved privileges as follows. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- \ No newline at end of file diff --git a/docs/java-rest/high-level/security/get-role-mappings.asciidoc b/docs/java-rest/high-level/security/get-role-mappings.asciidoc deleted file mode 100644 index b279702a4e12..000000000000 --- a/docs/java-rest/high-level/security/get-role-mappings.asciidoc +++ /dev/null @@ -1,68 +0,0 @@ -[role="xpack"] -[[java-rest-high-security-get-role-mappings]] -=== Get Role Mappings API - -[[java-rest-high-security-get-role-mappings-execution]] -==== Execution - -Retrieving a role mapping can be performed using the `security().getRoleMappings()` -method and by setting role mapping name on `GetRoleMappingsRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[get-role-mappings-execute] --------------------------------------------------- - -Retrieving multiple role mappings can be performed using the `security.getRoleMappings()` -method and by setting role mapping names on `GetRoleMappingsRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[get-role-mappings-list-execute] --------------------------------------------------- - -Retrieving all role mappings can be performed using the `security.getRoleMappings()` -method and with no role mapping name on `GetRoleMappingsRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[get-role-mappings-all-execute] --------------------------------------------------- - -[[java-rest-high-security-get-role-mappings-response]] -==== Response - -The returned `GetRoleMappingsResponse` contains the list of role mapping(s). - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[get-role-mappings-response] --------------------------------------------------- - -[[java-rest-high-security-get-role-mappings-async]] -==== Asynchronous Execution - -This request can be executed asynchronously using the `security().getRoleMappingsAsync()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[get-role-mappings-execute-async] --------------------------------------------------- -<1> The `GetRoleMappingsRequest` to execute and the `ActionListener` to use when -the execution completes - -The asynchronous method does not block and returns immediately. Once the request -has 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 a `GetRoleMappingsResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[get-role-mappings-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 \ No newline at end of file diff --git a/docs/java-rest/high-level/security/get-roles.asciidoc b/docs/java-rest/high-level/security/get-roles.asciidoc deleted file mode 100644 index 2c698222c7a4..000000000000 --- a/docs/java-rest/high-level/security/get-roles.asciidoc +++ /dev/null @@ -1,48 +0,0 @@ - --- -:api: get-roles -:request: GetRolesRequest -:response: GetRolesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Roles API - -[id="{upid}-{api}-request"] -==== Get Roles Request - -Retrieving a role can be performed using the `security().getRoles()` -method and by setting the role name on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -Retrieving multiple roles can be performed using the `security().getRoles()` -method and by setting multiple role names on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-list-request] --------------------------------------------------- - -Retrieving all roles can be performed using the `security().getRoles()` -method without specifying any role names on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-all-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Roles Response - -The returned +{response}+ allows getting information about the retrieved roles as follows. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- \ No newline at end of file diff --git a/docs/java-rest/high-level/security/get-service-account-credentials.asciidoc b/docs/java-rest/high-level/security/get-service-account-credentials.asciidoc deleted file mode 100644 index 5404c7869e15..000000000000 --- a/docs/java-rest/high-level/security/get-service-account-credentials.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ - --- -:api: get-service-account-credentials -:request: GetServiceAccountCredentialsRequest -:response: GetServiceAccountCredentialsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Service Account Credentials API - -[id="{upid}-{api}-request"] -==== Get Service Account Credentials Request - -Retrieving all credentials for a service account can be performed by setting the namespace -and service-name on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Service Account Credentials Response - -The returned +{response}+ contains service tokens for the requested service account. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Principal of the service account -<2> List of index-based service token information -<3> Name of the first service token -<4> Source of the first service token. The value is either `file` or `index`. -<5> For `file` service tokens, names of the nodes where the information is collected. -<6> List of file-based service token information -<7> Response header containing the information about the execution of collecting `file` service tokens. -<8> Number of nodes that successful complete the request of retrieving file-backed service tokens -<9> Number of nodes that fail to complete the request of retrieving file-backed service tokens - diff --git a/docs/java-rest/high-level/security/get-service-accounts.asciidoc b/docs/java-rest/high-level/security/get-service-accounts.asciidoc deleted file mode 100644 index 99e7aa38068a..000000000000 --- a/docs/java-rest/high-level/security/get-service-accounts.asciidoc +++ /dev/null @@ -1,49 +0,0 @@ - --- -:api: get-service-accounts -:request: GetServiceAccountsRequest -:response: GetServiceAccountsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Service Accounts API - -[id="{upid}-{api}-request"] -==== Get Service Accounts Request - -Retrieving a service account can be performed by setting the namespace -and service-name on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -Retrieving service accounts belong to a namespace can be performed -by just setting the namespace on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-namespace] --------------------------------------------------- - -Retrieving all service accounts can be performed without specifying -either namespace or service-name on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-all] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Service Accounts Response - -The returned +{response}+ allows getting information about the retrieved service accounts as follows. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Information for the requested service account diff --git a/docs/java-rest/high-level/security/get-user-privileges.asciidoc b/docs/java-rest/high-level/security/get-user-privileges.asciidoc deleted file mode 100644 index 70536b571528..000000000000 --- a/docs/java-rest/high-level/security/get-user-privileges.asciidoc +++ /dev/null @@ -1,48 +0,0 @@ --- -:api: get-user-privileges -:request: GetUserPrivilegesRequest -:response: GetUserPrivilegesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get User Privileges API - -Retrieves security privileges for the logged in user. - -include::../execution-no-req.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get User Privileges Response - -The returned +{response}+ contains the following properties - -`clusterPrivileges`:: -A `Set` of all _cluster_ privileges that are held by the user. -This will be the union of all the _cluster_ privileges from the user's roles. - -`globalPrivileges`:: -A `Set` of all _global_ privileges that are held by the user. -This will be the union of all the _global_ privileges from the user's roles. -Because this a union of multiple roles, it may contain multiple privileges for -the same `category` and `operation` (which is why it is represented as a `Set` -rather than a single object). - -`indicesPrivileges`:: -A `Set` of all _index_ privileges that are held by the user. -This will be the union of all the _index_ privileges from the user's roles. -Because this a union of multiple roles, it may contain multiple privileges for -the same `index`, and those privileges may have independent field level security -access grants and/or multiple document level security queries. - -`applicationPrivileges`:: -A `Set` of all _application_ privileges that are held by the user. -This will be the union of all the _application_ privileges from the user's roles. - -`runAsPrivilege`:: -A `Set` representation of the _run-as_ privilege that is held by the user. -This will be the union of the _run-as_ privilege from each of the user's roles. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/security/get-users.asciidoc b/docs/java-rest/high-level/security/get-users.asciidoc deleted file mode 100644 index cbd45801fe99..000000000000 --- a/docs/java-rest/high-level/security/get-users.asciidoc +++ /dev/null @@ -1,48 +0,0 @@ - --- -:api: get-users -:request: GetUsersRequest -:response: GetUsersResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Users API - -[id="{upid}-{api}-request"] -==== Get Users Request - -Retrieving a user can be performed using the `security().getUsers()` -method and by setting the username on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -Retrieving multiple users can be performed using the `security().getUsers()` -method and by setting multiple usernames on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-list-request] --------------------------------------------------- - -Retrieving all users can be performed using the `security().getUsers()` -method without specifying any usernames on +{request}+: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-all-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Get Users Response - -The returned +{response}+ allows getting information about the retrieved users as follows. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- \ No newline at end of file diff --git a/docs/java-rest/high-level/security/grant-api-key.asciidoc b/docs/java-rest/high-level/security/grant-api-key.asciidoc deleted file mode 100644 index bb65b27d4297..000000000000 --- a/docs/java-rest/high-level/security/grant-api-key.asciidoc +++ /dev/null @@ -1,44 +0,0 @@ --- -:api: grant-api-key -:request: GrantApiKeyRequest -:response: CreateApiKeyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Grant API key API - -Creates an API key on behalf of another user. - -[id="{upid}-{api}-request"] -==== Grant API key request - -This API is similar to <>, however it -creates the API key for a user that is different than the user that runs the API. - -A +{request}+ contains authentication credentials for the user on whose behalf -the API key will be created, a grant type (which indicates whether the -credentials are an access token or a user ID and password), and API key details. -The API key details include a name for the API key, an optional list of role -descriptors to define permissions, and an optional expiration for the -generated API key. If expiration is not provided, by default the API keys do not -expire. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Grant API key response - -The returned +{response}+ contains an ID, API key, name for the API key, and -optional expiration. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The API key that can be used to authenticate to Elasticsearch. -<2> Expiration details, if the API keys expire. diff --git a/docs/java-rest/high-level/security/has-privileges.asciidoc b/docs/java-rest/high-level/security/has-privileges.asciidoc deleted file mode 100644 index 5a9914c802b9..000000000000 --- a/docs/java-rest/high-level/security/has-privileges.asciidoc +++ /dev/null @@ -1,88 +0,0 @@ --- -:api: has-privileges -:request: HasPrivilegesRequest -:response: HasPrivilegesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Has Privileges API - -Determines whether the logged in user has a specified list of privileges. - -[id="{upid}-{api}-request"] -==== Has Privileges Request -The +{request}+ supports checking for any or all of the following privilege types: - -* Cluster Privileges -* Index Privileges -* Application Privileges - -Privileges types that you do not wish to check my be passed in as +null+, but as least -one privilege must be specified. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Has Privileges Response - -The returned +{response}+ contains the following properties - -`username`:: -The username (userid) of the current user (for whom the "has privileges" -check was executed) - -`hasAllRequested`:: -`true` if the user has all of the privileges that were specified in the -+{request}+. Otherwise `false`. - -`clusterPrivileges`:: -A `Map` where each key is the name of one of the cluster -privileges specified in the request, and the value is `true` if the user -has that privilege, and `false` otherwise. -+ -The method `hasClusterPrivilege` can be used to retrieve this information -in a more fluent manner. This method throws an `IllegalArgumentException` -if the privilege was not included in the response (which will be the case -if the privilege was not part of the request). - -`indexPrivileges`:: -A `Map>` where each key is the name of an -index (as specified in the +{request}+) and the value is a `Map` from -privilege name to a `Boolean`. The `Boolean` value is `true` if the user -has that privilege on that index, and `false` otherwise. -+ -The method `hasIndexPrivilege` can be used to retrieve this information -in a more fluent manner. This method throws an `IllegalArgumentException` -if the privilege was not included in the response (which will be the case -if the privilege was not part of the request). - -`applicationPrivileges`:: -A `Map>>>` where each key is the -name of an application (as specified in the +{request}+). -For each application, the value is a `Map` keyed by resource name, with -each value being another `Map` from privilege name to a `Boolean`. -The `Boolean` value is `true` if the user has that privilege on that -resource for that application, and `false` otherwise. -+ -The method `hasApplicationPrivilege` can be used to retrieve this -information in a more fluent manner. This method throws an -`IllegalArgumentException` if the privilege was not included in the -response (which will be the case if the privilege was not part of the -request). - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `hasMonitor` will be `true` if the user has the `"monitor"` - cluster privilege. -<2> `hasWrite` will be `true` if the user has the `"write"` - privilege on the `"logstash-2018-10-05"` index. -<3> `hasRead` will be `true` if the user has the `"read"` - privilege on all possible indices that would match - the `"logstash-2018-*"` pattern. - diff --git a/docs/java-rest/high-level/security/invalidate-api-key.asciidoc b/docs/java-rest/high-level/security/invalidate-api-key.asciidoc deleted file mode 100644 index 61ab471ce86d..000000000000 --- a/docs/java-rest/high-level/security/invalidate-api-key.asciidoc +++ /dev/null @@ -1,83 +0,0 @@ --- -:api: invalidate-api-key -:request: InvalidateApiKeyRequest -:response: InvalidateApiKeyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Invalidate API Key API - -API Key(s) can be invalidated using this API. - -[id="{upid}-{api}-request"] -==== Invalidate API Key Request -The +{request}+ supports invalidating - -. A specific API key - -. All API keys for a specific realm - -. All API keys for a specific user - -. All API keys for a specific user in a specific realm - -. A specific key or all API keys owned by the current authenticated user - -===== Specific API keys by a list of API key ids -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-api-key-ids-request] --------------------------------------------------- - -===== Specific API key by API key name -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-api-key-name-request] --------------------------------------------------- - -===== All API keys for realm -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-realm-api-keys-request] --------------------------------------------------- - -===== All API keys for user -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-user-api-keys-request] --------------------------------------------------- - -===== All API key for user in realm -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-user-realm-api-keys-request] --------------------------------------------------- - -===== Retrieve all API keys for the current authenticated user -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-api-keys-owned-by-authenticated-user-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Invalidate API Key Response - -The returned +{response}+ contains the information regarding the API keys that the request -invalidated. - -`invalidatedApiKeys`:: Available using `getInvalidatedApiKeys` lists the API keys - that this request invalidated. - -`previouslyInvalidatedApiKeys`:: Available using `getPreviouslyInvalidatedApiKeys` lists the API keys - that this request attempted to invalidate - but were already invalid. - -`errors`:: Available using `getErrors` contains possible errors that were encountered while - attempting to invalidate API keys. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/security/invalidate-token.asciidoc b/docs/java-rest/high-level/security/invalidate-token.asciidoc deleted file mode 100644 index 34969523c7ba..000000000000 --- a/docs/java-rest/high-level/security/invalidate-token.asciidoc +++ /dev/null @@ -1,73 +0,0 @@ --- -:api: invalidate-token -:request: InvalidateTokenRequest -:response: InvalidateTokenResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Invalidate Token API - -[id="{upid}-{api}-request"] -==== Invalidate Token Request -The +{request}+ supports invalidating - -. A specific token, that can be either an _access token_ or a _refresh token_ - -. All tokens (both _access tokens_ and _refresh tokens_) for a specific realm - -. All tokens (both _access tokens_ and _refresh tokens_) for a specific user - -. All tokens (both _access tokens_ and _refresh tokens_) for a specific user in a specific realm - -===== Specific access token -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-access-token-request] --------------------------------------------------- - -===== Specific refresh token -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-refresh-token-request] --------------------------------------------------- - -===== All tokens for realm -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-realm-tokens-request] --------------------------------------------------- - -===== All tokens for user -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-user-tokens-request] --------------------------------------------------- - -===== All tokens for user in realm -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[invalidate-user-realm-tokens-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Invalidate Token Response - -The returned +{response}+ contains the information regarding the tokens that the request -invalidated. - -`invalidatedTokens`:: Available using `getInvalidatedTokens` denotes the number of tokens - that this request invalidated. - -`previouslyInvalidatedTokens`:: Available using `getPreviouslyInvalidatedTokens` denotes - the number of tokens that this request attempted to invalidate - but were already invalid. - -`errors`:: Available using `getErrors` contains possible errors that were encountered while - attempting to invalidate specific tokens. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- \ No newline at end of file diff --git a/docs/java-rest/high-level/security/put-privileges.asciidoc b/docs/java-rest/high-level/security/put-privileges.asciidoc deleted file mode 100644 index 72e28e698832..000000000000 --- a/docs/java-rest/high-level/security/put-privileges.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: put-privileges -:request: PutPrivilegesRequest -:response: PutPrivilegesResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create or update privileges API - -Application privileges can be created or updated using this API. - -[id="{upid}-{api}-request"] -==== Request -A +{request}+ contains list of application privileges that -need to be created or updated. Each application privilege -consists of an application name, application privilege, -set of actions and optional metadata. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the information about the status -for each privilege present in the +{request}+. The status would be -`true` if the privilege was created, `false` if the privilege was updated. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The response contains the status for given application name and -privilege name. The status would be `true` if the privilege was created, -`false` if the privilege was updated. diff --git a/docs/java-rest/high-level/security/put-role-mapping.asciidoc b/docs/java-rest/high-level/security/put-role-mapping.asciidoc deleted file mode 100644 index 53e5a6ceaabd..000000000000 --- a/docs/java-rest/high-level/security/put-role-mapping.asciidoc +++ /dev/null @@ -1,54 +0,0 @@ -[role="xpack"] -[[java-rest-high-security-put-role-mapping]] -=== Create or update role mapping API - -[[java-rest-high-security-put-role-mapping-execution]] -==== Execution - -Creating and updating a role mapping can be performed using the `security().putRoleMapping()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-execute] --------------------------------------------------- - -[[java-rest-high-security-put-role-mapping-response]] -==== Response - -The returned `PutRoleMappingResponse` contains a single field, `created`. This field -serves as an indication if a role mapping was created or if an existing entry was updated. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-response] --------------------------------------------------- -<1> `created` is a boolean indicating whether the role mapping was created or updated - -[[java-rest-high-security-put-role-mapping-async]] -==== Asynchronous Execution - -This request can be executed asynchronously using the `security().putRoleMappingAsync()` -method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-execute-async] --------------------------------------------------- -<1> The `PutRoleMappingRequest` to execute and the `ActionListener` to use when -the execution completes - -The asynchronous method does not block and returns immediately. Once the request -has 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 a `PutRoleMappingResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-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 \ No newline at end of file diff --git a/docs/java-rest/high-level/security/put-role.asciidoc b/docs/java-rest/high-level/security/put-role.asciidoc deleted file mode 100644 index 41b5b9efd5b9..000000000000 --- a/docs/java-rest/high-level/security/put-role.asciidoc +++ /dev/null @@ -1,37 +0,0 @@ - --- -:api: put-role -:request: PutRoleRequest -:response: PutRoleResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create or update role API - -[id="{upid}-{api}-request"] -==== Request - -The +{request}+ class is used to create or update a role in the Native Roles -Store. The request contains a single role, which encapsulates privileges over -resources. A role can be assigned to an user using the -<<{upid}-put-role-mapping,Create or update role mapping API>>. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains a single field, `created`. This field -serves as an indication if the role was created or if an existing entry was -updated. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `created` is a boolean indicating whether the role was created or updated diff --git a/docs/java-rest/high-level/security/put-user.asciidoc b/docs/java-rest/high-level/security/put-user.asciidoc deleted file mode 100644 index 0af1d753c26c..000000000000 --- a/docs/java-rest/high-level/security/put-user.asciidoc +++ /dev/null @@ -1,58 +0,0 @@ --- -:api: put-user -:request: PutUserRequest -:response: PutUserResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create or update user API - -[id="{upid}-{api}-request"] -==== Request - -The +{request}+ class is used to create or update a user in the Native Realm. -There are 3 different factory methods for creating a request. - -===== Create or Update User with a Password - -If you wish to create a new user (or update an existing user) and directly specifying the user's new password, use the -`withPassword` method as shown below: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-password-request] --------------------------------------------------- - -===== Create or Update User with a Hashed Password - -If you wish to create a new user (or update an existing user) and perform password hashing on the client, -then use the `withPasswordHash` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-hash-request] - --------------------------------------------------- -===== Update a User without changing their password - -If you wish to update an existing user, and do not wish to change the user's password, -then use the `updateUserProperties` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-update-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned `PutUserResponse` contains a single field, `created`. This field -serves as an indication if a user was created or if an existing entry was updated. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-user-response] --------------------------------------------------- -<1> `created` is a boolean indicating whether the user was created or updated diff --git a/docs/java-rest/high-level/security/query-api-key.asciidoc b/docs/java-rest/high-level/security/query-api-key.asciidoc deleted file mode 100644 index 88a39acb7c92..000000000000 --- a/docs/java-rest/high-level/security/query-api-key.asciidoc +++ /dev/null @@ -1,86 +0,0 @@ --- -:api: query-api-key -:request: QueryApiKeyRequest -:response: QueryApiKeyResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Query API Key information API - -API Key(s) information can be queried and retrieved in a paginated -fashion using this API. - -[id="{upid}-{api}-request"] -==== Query API Key Request -The +{request}+ supports query and retrieving API key information using -Elasticsearch's {ref}/query-dsl.html[Query DSL] with -{ref}/paginate-search-results.html[pagination]. -It supports only a subset of available query types, including: - -. {ref}/query-dsl-bool-query.html[Boolean query] - -. {ref}/query-dsl-match-all-query.html[Match all query] - -. {ref}/query-dsl-term-query.html[Term query] - -. {ref}/query-dsl-terms-query.html[Terms query] - -. {ref}/query-dsl-ids-query.html[IDs Query] - -. {ref}/query-dsl-prefix-query.html[Prefix query] - -. {ref}/query-dsl-wildcard-query.html[Wildcard query] - -. {ref}/query-dsl-range-query.html[Range query] - -===== Query for all API keys -In its most basic form, the request selects all API keys that the user -has access to. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[query-api-key-default-request] --------------------------------------------------- - -===== Query API keys with Query DSL -The following query selects API keys owned by the user and also satisfy following criteria: -* The API key name must begin with the word `key` -* The API key name must *not* be `key-20000` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[query-api-key-query-request] --------------------------------------------------- - -===== Retrieve API keys with explicitly configured sort and paging -The following request sort the API keys by their names in descending order. -It also retrieves the API keys from index 1 (zero-based) and in a page size of 100. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[query-api-key-from-size-sort-request] --------------------------------------------------- - -===== Deep pagination can be achieved with search after - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[query-api-key-search-after-request] --------------------------------------------------- - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Query API Key information API Response - -The returned +{response}+ contains the information regarding the API keys that were -requested. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[query-api-key-from-size-sort-response] --------------------------------------------------- -<1> Total number of API keys matched by the query -<2> Number of API keys returned in this response -<3> The list of API keys -<4> If sorting is requested, each API key in the response contains its sort values. diff --git a/docs/java-rest/high-level/snapshot/clone_snapshot.asciidoc b/docs/java-rest/high-level/snapshot/clone_snapshot.asciidoc deleted file mode 100644 index 311f77ee95ff..000000000000 --- a/docs/java-rest/high-level/snapshot/clone_snapshot.asciidoc +++ /dev/null @@ -1,95 +0,0 @@ -[[java-rest-high-snapshot-clone-snapshot]] -=== Clone Snapshot API - -The Clone Snapshot API clones part or all of a snapshot into a new snapshot. - -[[java-rest-high-snapshot-clone-snapshot-request]] -==== Request - -A `CloneSnapshotRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-request] --------------------------------------------------- - -==== Indices to Clone - -Use `indices` to specify a list of indices from the source snapshot to include -in the snapshot clone: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-request-indices] --------------------------------------------------- -<1> Include only `test_index` from the source snapshot. - -==== Index Settings and Options - -You can also customize index settings and options when cloning a snapshot: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-request-index-settings] --------------------------------------------------- -<1> Set `IndicesOptions.Option.IGNORE_UNAVAILABLE` in `#indicesOptions()` to - have the clone succeed even if indices are missing in the source snapshot. - -==== Further Arguments - -You can also provide the following optional arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-snapshot-clone-snapshot-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-clone-snapshot-async]] -==== Asynchronous Execution - -The asynchronous execution of a clone snapshot request requires both the -`CloneSnapshotRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-execute-async] --------------------------------------------------- -<1> The `CloneSnapshotRequest` 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 `AcknowledgedResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is - provided as an argument. -<2> Called in case of a failure. The raised exception is provided as an argument. - -[[java-rest-high-cluster-clone-snapshot-response]] -==== Response - -`AcknowledgedResponse` indicates whether the request was received: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[clone-snapshot-response] --------------------------------------------------- -<1> A boolean value of `true` if the clone successfully completed. Otherwise, the value is `false`. diff --git a/docs/java-rest/high-level/snapshot/create_repository.asciidoc b/docs/java-rest/high-level/snapshot/create_repository.asciidoc deleted file mode 100644 index 5c5452920972..000000000000 --- a/docs/java-rest/high-level/snapshot/create_repository.asciidoc +++ /dev/null @@ -1,139 +0,0 @@ -[[java-rest-high-snapshot-create-repository]] -=== Snapshot Create RepositoryAPI - -The Snapshot Create RepositoryAPI allows to register a snapshot repository. - -[[java-rest-high-snapshot-create-repository-request]] -==== Snapshot Create RepositoryRequest - -A `PutRepositoryRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request] --------------------------------------------------- - -==== Repository Settings -Settings requirements will differ based on the repository backend chosen. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-repository-settings] --------------------------------------------------- -<1> Sets the repository settings - -==== Providing the Settings -The settings to be applied can be provided in different ways: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-create-settings] --------------------------------------------------- -<1> Settings provided as `Settings` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-settings-builder] --------------------------------------------------- -<1> Settings provided as `Settings.Builder` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-settings-source] --------------------------------------------------- -<1> Settings provided as `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-settings-map] --------------------------------------------------- -<1> Settings provided as a `Map` - -==== Required Arguments -The following arguments must be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-name] --------------------------------------------------- -<1> The name of the repository - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-type] --------------------------------------------------- -<1> The type of the repository - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-verify] --------------------------------------------------- -<1> Verify after creation as a `Boolean` - -[[java-rest-high-snapshot-create-repository-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-create-repository-async]] -==== Asynchronous Execution - -The asynchronous execution of a repository put settings requires both the -`PutRepositoryRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-execute-async] --------------------------------------------------- -<1> The `PutRepositoryRequest` 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 `PutRepositoryResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -[[java-rest-high-snapshot-create-repository-response]] -==== Snapshot Create RepositoryResponse - -The returned `PutRepositoryResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-response] --------------------------------------------------- -<1> Indicates the node has acknowledged the request diff --git a/docs/java-rest/high-level/snapshot/create_snapshot.asciidoc b/docs/java-rest/high-level/snapshot/create_snapshot.asciidoc deleted file mode 100644 index 971a6ee48671..000000000000 --- a/docs/java-rest/high-level/snapshot/create_snapshot.asciidoc +++ /dev/null @@ -1,132 +0,0 @@ -[[java-rest-high-snapshot-create-snapshot]] -=== Create Snapshot API - -Use the Create Snapshot API to create a new snapshot. - -[[java-rest-high-snapshot-create-snapshot-request]] -==== Create Snapshot Request - -A `CreateSnapshotRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request] --------------------------------------------------- - -==== Required Arguments -The following arguments are mandatory: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-repositoryName] --------------------------------------------------- -<1> The name of the repository. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-snapshotName] --------------------------------------------------- -<1> The name of the snapshot. - -==== Optional Arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-indices] --------------------------------------------------- -<1> A list of indices the snapshot is applied to. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-indicesOptions] --------------------------------------------------- -<1> Options applied to the indices. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-partial] --------------------------------------------------- -<1> Set `partial` to `true` to allow a successful snapshot without the -availability of all the indices primary shards. Defaults to `false`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-includeGlobalState] --------------------------------------------------- -<1> Set `includeGlobalState` to `false` to prevent writing the cluster's global -state as part of the snapshot. Defaults to `true`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue`. -<2> Timeout to connect to the master node as a `String`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-request-waitForCompletion] --------------------------------------------------- -<1> Waits for the snapshot to be completed before a response is returned. - -[[java-rest-high-snapshot-create-snapshot-sync]] -==== Synchronous Execution - -Execute a `CreateSnapshotRequest` synchronously to receive a `CreateSnapshotResponse`. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-execute] --------------------------------------------------- - -Retrieve the `SnapshotInfo` from a `CreateSnapshotResponse` when the snapshot is fully created. -(The `waitForCompletion` parameter is `true`). - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-response-snapshot-info] --------------------------------------------------- -<1> The `SnapshotInfo` object. - -[[java-rest-high-snapshot-create-snapshot-async]] -==== Asynchronous Execution - -The asynchronous execution of a create snapshot request requires both the -`CreateSnapshotRequest` instance and an `ActionListener` instance to be -passed as arguments to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-execute-async] --------------------------------------------------- -<1> The `CreateSnapshotRequest` 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 with the `onResponse` method -if the execution is successful or the `onFailure` method if the execution -failed. - -A typical listener for `CreateSnapshotResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument. -<2> Called in case of a failure. The raised exception is provided as an -argument. - -[[java-rest-high-snapshot-create-snapshot-response]] -==== Snapshot Create Response - -Use the `CreateSnapshotResponse` to retrieve information about the evaluated -request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-snapshot-response] --------------------------------------------------- -<1> Indicates the node has started the request. diff --git a/docs/java-rest/high-level/snapshot/delete_repository.asciidoc b/docs/java-rest/high-level/snapshot/delete_repository.asciidoc deleted file mode 100644 index e88535f2362a..000000000000 --- a/docs/java-rest/high-level/snapshot/delete_repository.asciidoc +++ /dev/null @@ -1,82 +0,0 @@ -[[java-rest-high-snapshot-delete-repository]] -=== Snapshot Delete Repository API - -The Snapshot Delete Repository API allows to delete a registered repository. - -[[java-rest-high-snapshot-delete-repository-request]] -==== Snapshot Delete Repository Request - -A `DeleteRepositoryRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-repository-request] --------------------------------------------------- - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-repository-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-snapshot-delete-repository-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-repository-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-delete-repository-async]] -==== Asynchronous Execution - -The asynchronous execution of a snapshot delete repository requires both the -`DeleteRepositoryRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-repository-execute-async] --------------------------------------------------- -<1> The `DeleteRepositoryRequest` 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 `DeleteRepositoryResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-repository-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -[[java-rest-high-cluster-delete-repository-response]] -==== Snapshot Delete Repository Response - -The returned `DeleteRepositoryResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-repository-response] --------------------------------------------------- -<1> Indicates the node has acknowledged the request diff --git a/docs/java-rest/high-level/snapshot/delete_snapshot.asciidoc b/docs/java-rest/high-level/snapshot/delete_snapshot.asciidoc deleted file mode 100644 index 2f770e35333b..000000000000 --- a/docs/java-rest/high-level/snapshot/delete_snapshot.asciidoc +++ /dev/null @@ -1,73 +0,0 @@ -[[java-rest-high-snapshot-delete-snapshot]] -=== Delete Snapshot API - -The Delete Snapshot API allows to delete a snapshot. - -[[java-rest-high-snapshot-delete-snapshot-request]] -==== Delete Snapshot Request - -A `DeleteSnapshotRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-snapshot-request] --------------------------------------------------- - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-snapshot-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-snapshot-delete-snapshot-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-snapshot-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-delete-snapshot-async]] -==== Asynchronous Execution - -The asynchronous execution of a delete snapshot request requires both the -`DeleteSnapshotRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-snapshot-execute-async] --------------------------------------------------- -<1> The `DeleteSnapshotRequest` 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 `DeleteSnapshotResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-snapshot-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -[[java-rest-high-cluster-delete-snapshot-response]] -==== Delete Snapshot Response - -The returned `DeleteSnapshotResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[delete-snapshot-response] --------------------------------------------------- -<1> Indicates the node has acknowledged the request diff --git a/docs/java-rest/high-level/snapshot/get_repository.asciidoc b/docs/java-rest/high-level/snapshot/get_repository.asciidoc deleted file mode 100644 index af006c66ab08..000000000000 --- a/docs/java-rest/high-level/snapshot/get_repository.asciidoc +++ /dev/null @@ -1,86 +0,0 @@ -[[java-rest-high-snapshot-get-repository]] -=== Snapshot Get Repository API - -The Snapshot Get Repository API allows to retrieve information about a registered repository. - -[[java-rest-high-snapshot-get-repository-request]] -==== Snapshot Get Repository Request - -A `GetRepositoriesRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-request] --------------------------------------------------- - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-request-repositories] --------------------------------------------------- -<1> Sets the repositories to retrieve - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-request-local] --------------------------------------------------- -<1> The `local` flag (defaults to `false`) controls whether the repositories need -to be looked up in the local cluster state or in the cluster state held by -the elected master node - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-snapshot-get-repository-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-get-repository-async]] -==== Asynchronous Execution - -The asynchronous execution of a snapshot get repository requires both the -`GetRepositoriesRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-execute-async] --------------------------------------------------- -<1> The `GetRepositoriesRequest` 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 `GetRepositoriesResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -[[java-rest-high-cluster-get-repository-response]] -==== Snapshot Get Repository Response - -The returned `GetRepositoriesResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-repository-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/snapshot/get_snapshots.asciidoc b/docs/java-rest/high-level/snapshot/get_snapshots.asciidoc deleted file mode 100644 index 1041f61d8422..000000000000 --- a/docs/java-rest/high-level/snapshot/get_snapshots.asciidoc +++ /dev/null @@ -1,108 +0,0 @@ -[[java-rest-high-snapshot-get-snapshots]] -=== Get Snapshots API - -Use the Get Snapshot API to get snapshots. - -[[java-rest-high-snapshot-get-snapshots-request]] -==== Get Snapshots Request - -A `GetSnapshotsRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-request] --------------------------------------------------- - -==== Required Arguments -The following arguments are mandatory: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-request-repositoryName] --------------------------------------------------- -<1> The name of the repository. - -==== Optional Arguments -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-request-snapshots] --------------------------------------------------- -<1> An array of snapshots to get. Otherwise it will return all snapshots for a repository. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue`. -<2> Timeout to connect to the master node as a `String`. - - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-request-verbose] --------------------------------------------------- -<1> `Boolean` indicating if the response should be verbose. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-request-ignore-unavailable] --------------------------------------------------- -<1> `Boolean` indicating if unavailable snapshots should be ignored. Otherwise the request will -fail if any of the snapshots are unavailable. - -[[java-rest-high-snapshot-get-snapshots-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-get-snapshots-async]] -==== Asynchronous Execution - -The asynchronous execution of a get snapshots request requires both the -`GetSnapshotsRequest` instance and an `ActionListener` instance to be -passed as arguments to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-execute-async] --------------------------------------------------- -<1> The `GetSnapshotsRequest` 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 with the `onResponse` method -if the execution is successful or the `onFailure` method if the execution -failed. - -A typical listener for `GetSnapshotsResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument. -<2> Called in case of a failure. The raised exception is provided as an -argument. - -[[java-rest-high-snapshot-get-snapshots-response]] -==== Get Snapshots Response - -The returned `GetSnapshotsResponse` allows the retrieval of information about the requested -snapshots: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-response] --------------------------------------------------- -<1> The REST status of a snapshot -<2> The snapshot id -<3> The current state of the snapshot -<4> Information about failures that occurred during the shard snapshot process. -<5> The snapshot start time -<6> The snapshot end time \ No newline at end of file diff --git a/docs/java-rest/high-level/snapshot/restore_snapshot.asciidoc b/docs/java-rest/high-level/snapshot/restore_snapshot.asciidoc deleted file mode 100644 index a4b83ca419a4..000000000000 --- a/docs/java-rest/high-level/snapshot/restore_snapshot.asciidoc +++ /dev/null @@ -1,144 +0,0 @@ -[[java-rest-high-snapshot-restore-snapshot]] -=== Restore Snapshot API - -The Restore Snapshot API allows to restore a snapshot. - -[[java-rest-high-snapshot-restore-snapshot-request]] -==== Restore Snapshot Request - -A `RestoreSnapshotRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request] --------------------------------------------------- - -==== Limiting Indices to Restore - -By default all indices are restored. With the `indices` property you can -provide a list of indices that should be restored: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-indices] --------------------------------------------------- -<1> Request that Elasticsearch only restores "test_index". - -==== Renaming Indices - -You can rename indices using regular expressions when restoring a snapshot: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-rename] --------------------------------------------------- -<1> A regular expression matching the indices that should be renamed. -<2> A replacement pattern that references the group from the regular - expression as `$1`. "test_index" from the snapshot is restored as - "restored_index" in this example. - -==== Index Settings and Options - -You can also customize index settings and options when restoring: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-index-settings] --------------------------------------------------- -<1> Use `#indexSettings()` to set any specific index setting for the indices - that are restored. -<2> Use `#ignoreIndexSettings()` to provide index settings that should be - ignored from the original indices. -<3> Set `IndicesOptions.Option.IGNORE_UNAVAILABLE` in `#indicesOptions()` to - have the restore succeed even if indices are missing in the snapshot. - -==== Further Arguments - -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-waitForCompletion] --------------------------------------------------- -<1> Boolean indicating whether to wait until the snapshot has been restored. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-partial] --------------------------------------------------- -<1> Boolean indicating whether the entire snapshot should succeed although one - or more indices participating in the snapshot don’t have all primary - shards available. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-include-global-state] --------------------------------------------------- -<1> Boolean indicating whether restored templates that don’t currently exist - in the cluster are added and existing templates with the same name are - replaced by the restored templates. The restored persistent settings are - added to the existing persistent settings. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-request-include-aliases] --------------------------------------------------- -<1> Boolean to control whether aliases should be restored. Set to `false` to - prevent aliases from being restored together with associated indices. - -[[java-rest-high-snapshot-restore-snapshot-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-restore-snapshot-async]] -==== Asynchronous Execution - -The asynchronous execution of a restore snapshot request requires both the -`RestoreSnapshotRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-execute-async] --------------------------------------------------- -<1> The `RestoreSnapshotRequest` 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 `RestoreSnapshotResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is - provided as an argument. -<2> Called in case of a failure. The raised exception is provided as an argument. - -[[java-rest-high-cluster-restore-snapshot-response]] -==== Restore Snapshot Response - -The returned `RestoreSnapshotResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[restore-snapshot-response] --------------------------------------------------- -<1> The `RestoreInfo` contains details about the restored snapshot like the indices or - the number of successfully restored and failed shards. diff --git a/docs/java-rest/high-level/snapshot/snapshots_status.asciidoc b/docs/java-rest/high-level/snapshot/snapshots_status.asciidoc deleted file mode 100644 index 8f91d774f4e1..000000000000 --- a/docs/java-rest/high-level/snapshot/snapshots_status.asciidoc +++ /dev/null @@ -1,97 +0,0 @@ -[[java-rest-high-snapshot-snapshots-status]] -=== Snapshots Status API - -The Snapshots Status API allows to retrieve detailed information about snapshots in progress. - -[[java-rest-high-snapshot-snapshots-status-request]] -==== Snapshots Status Request - -A `SnapshotsStatusRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-request] --------------------------------------------------- - -==== Required Arguments -The following arguments must be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-request-repository] --------------------------------------------------- -<1> Sets the repository to check for snapshot statuses - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-request-snapshots] --------------------------------------------------- -<1> The list of snapshot names to check the status of - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-request-ignoreUnavailable] --------------------------------------------------- -<1> The command will fail if some of the snapshots are unavailable. The `ignore_unavailable` flag -set to true will return all snapshots that are currently available. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-snapshot-snapshots-status-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-snapshots-status-async]] -==== Asynchronous Execution - -The asynchronous execution of retrieving snapshot statuses requires both the -`SnapshotsStatusRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-execute-async] --------------------------------------------------- -<1> The `SnapshotsStatusRequest` 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 `SnapshotsStatusResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -[[java-rest-high-snapshot-snapshots-status-response]] -==== Snapshots Status Response - -The returned `SnapshotsStatusResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[snapshots-status-response] --------------------------------------------------- -<1> Request contains a list of snapshot statuses -<2> Each status contains information about the snapshot -<3> Example of reading snapshot statistics about a specific index and shard diff --git a/docs/java-rest/high-level/snapshot/verify_repository.asciidoc b/docs/java-rest/high-level/snapshot/verify_repository.asciidoc deleted file mode 100644 index 4f03d1e5fe38..000000000000 --- a/docs/java-rest/high-level/snapshot/verify_repository.asciidoc +++ /dev/null @@ -1,81 +0,0 @@ -[[java-rest-high-snapshot-verify-repository]] -=== Snapshot Verify Repository API - -The Snapshot Verify Repository API allows to verify a registered repository. - -[[java-rest-high-snapshot-verify-repository-request]] -==== Snapshot Verify Repository Request - -A `VerifyRepositoryRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[verify-repository-request] --------------------------------------------------- - -==== Optional Arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[create-repository-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the settings were applied -as a `String` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[verify-repository-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` -<2> Timeout to connect to the master node as a `String` - -[[java-rest-high-snapshot-verify-repository-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[verify-repository-execute] --------------------------------------------------- - -[[java-rest-high-snapshot-verify-repository-async]] -==== Asynchronous Execution - -The asynchronous execution of a snapshot verify repository requires both the -`VerifyRepositoryRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[verify-repository-execute-async] --------------------------------------------------- -<1> The `VerifyRepositoryRequest` 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 `VerifyRepositoryResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[verify-repository-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -[[java-rest-high-cluster-verify-repository-response]] -==== Snapshot Verify Repository Response - -The returned `VerifyRepositoryResponse` allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[verify-repository-response] --------------------------------------------------- \ No newline at end of file diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc deleted file mode 100644 index e6432d0f272b..000000000000 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ /dev/null @@ -1,765 +0,0 @@ -[[java-rest-high-supported-apis]] - -== Document APIs - -:upid: {mainid}-document -:doc-tests-file: {doc-tests}/CRUDDocumentationIT.java - -The Java High Level REST Client supports the following Document APIs: - -[[single-doc]] -Single document APIs:: -* <<{upid}-index>> -* <<{upid}-get>> -* <<{upid}-get-source>> -* <<{upid}-exists>> -* <<{upid}-delete>> -* <<{upid}-update>> -* <<{upid}-term-vectors>> - -[[multi-doc]] -Multi-document APIs:: -* <<{upid}-bulk>> -* <<{upid}-multi-get>> -* <<{upid}-reindex>> -* <<{upid}-update-by-query>> -* <<{upid}-delete-by-query>> -* <<{upid}-rethrottle>> -* <<{upid}-multi-term-vectors>> - -include::document/index.asciidoc[] -include::document/get.asciidoc[] -include::document/get-source.asciidoc[] -include::document/exists.asciidoc[] -include::document/delete.asciidoc[] -include::document/update.asciidoc[] -include::document/term-vectors.asciidoc[] -include::document/bulk.asciidoc[] -include::document/multi-get.asciidoc[] -include::document/reindex.asciidoc[] -include::document/update-by-query.asciidoc[] -include::document/delete-by-query.asciidoc[] -include::document/rethrottle.asciidoc[] -include::document/multi-term-vectors.asciidoc[] - - -== Search APIs - -:upid: {mainid} -:doc-tests-file: {doc-tests}/SearchDocumentationIT.java - -The Java High Level REST Client supports the following Search APIs: - -* <<{upid}-search>> -* <<{upid}-search-scroll>> -* <<{upid}-clear-scroll>> -* <<{upid}-search-template>> -* <<{upid}-multi-search-template>> -* <<{upid}-multi-search>> -* <<{upid}-field-caps>> -* <<{upid}-rank-eval>> -* <<{upid}-explain>> -* <<{upid}-count>> -* <<{upid}-point-in-time>> - -include::search/search.asciidoc[] -include::search/scroll.asciidoc[] -include::search/multi-search.asciidoc[] -include::search/search-template.asciidoc[] -include::search/multi-search-template.asciidoc[] -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 - -:upid: {mainid}-asyncsearch -:doc-tests-file: {doc-tests}/AsyncSearchDocumentationIT.java - -The Java High Level REST Client supports the following Async Search APIs: - -* <<{upid}-asyncsearch-submit>> -* <<{upid}-asyncsearch-get>> -* <<{upid}-asyncsearch-delete>> - -include::asyncsearch/submit.asciidoc[] -include::asyncsearch/get.asciidoc[] -include::asyncsearch/delete.asciidoc[] - -== Miscellaneous APIs - -The Java High Level REST Client supports the following Miscellaneous APIs: - -* <> -* <> -* <> -* <> - -include::miscellaneous/main.asciidoc[] -include::miscellaneous/ping.asciidoc[] -include::miscellaneous/x-pack-info.asciidoc[] -include::miscellaneous/x-pack-usage.asciidoc[] - -== Index APIs - -:upid: {mainid} -:doc-tests-file: {doc-tests}/IndicesClientDocumentationIT.java - -The Java High Level REST Client supports the following Index APIs: - -Index Management:: -* <<{upid}-analyze>> -* <<{upid}-create-index>> -* <<{upid}-delete-index>> -* <<{upid}-indices-exists>> -* <<{upid}-open-index>> -* <<{upid}-close-index>> -* <<{upid}-shrink-index>> -* <<{upid}-split-index>> -* <<{upid}-clone-index>> -* <<{upid}-refresh>> -* <<{upid}-flush>> -* <<{upid}-clear-cache>> -* <<{upid}-force-merge>> -* <<{upid}-rollover-index>> -* <<{upid}-indices-put-settings>> -* <<{upid}-get-settings>> -* <<{upid}-indices-validate-query>> -* <<{upid}-get-index>> - -Mapping Management:: -* <<{upid}-put-mapping>> -* <<{upid}-get-mappings>> -* <<{upid}-get-field-mappings>> - -Alias Management:: -* <<{upid}-update-aliases>> -* <<{upid}-exists-alias>> -* <<{upid}-get-alias>> -* <<{upid}-delete-alias>> - -Template Management:: -* <<{upid}-get-templates>> -* <<{upid}-templates-exist>> -* <<{upid}-put-template>> - -include::indices/analyze.asciidoc[] -include::indices/create_index.asciidoc[] -include::indices/delete_index.asciidoc[] -include::indices/indices_exists.asciidoc[] -include::indices/open_index.asciidoc[] -include::indices/close_index.asciidoc[] -include::indices/shrink_index.asciidoc[] -include::indices/split_index.asciidoc[] -include::indices/clone_index.asciidoc[] -include::indices/refresh.asciidoc[] -include::indices/flush.asciidoc[] -include::indices/clear_cache.asciidoc[] -include::indices/force_merge.asciidoc[] -include::indices/rollover.asciidoc[] -include::indices/put_mapping.asciidoc[] -include::indices/get_mappings.asciidoc[] -include::indices/get_field_mappings.asciidoc[] -include::indices/update_aliases.asciidoc[] -include::indices/delete_alias.asciidoc[] -include::indices/exists_alias.asciidoc[] -include::indices/get_alias.asciidoc[] -include::indices/put_settings.asciidoc[] -include::indices/get_settings.asciidoc[] -include::indices/put_template.asciidoc[] -include::indices/validate_query.asciidoc[] -include::indices/get_templates.asciidoc[] -include::indices/templates_exist.asciidoc[] -include::indices/get_index.asciidoc[] -include::indices/freeze_index.asciidoc[] -include::indices/unfreeze_index.asciidoc[] -include::indices/delete_template.asciidoc[] -include::indices/reload_analyzers.asciidoc[] -include::indices/get_index_template.asciidoc[] -include::indices/put_index_template.asciidoc[] -include::indices/delete_index_template.asciidoc[] -include::indices/simulate_index_template.asciidoc[] - -== Cluster APIs - -The Java High Level REST Client supports the following Cluster APIs: - -* <> -* <> -* <> -* <> - -:upid: {mainid}-cluster -:doc-tests-file: {doc-tests}/ClusterClientDocumentationIT.java -include::cluster/put_settings.asciidoc[] -include::cluster/get_settings.asciidoc[] -include::cluster/health.asciidoc[] -include::cluster/remote_info.asciidoc[] -include::cluster/get_component_template.asciidoc[] -include::cluster/put_component_template.asciidoc[] -include::cluster/delete_component_template.asciidoc[] - -== Ingest APIs -The Java High Level REST Client supports the following Ingest APIs: - -* <> -* <> -* <> -* <> - -include::ingest/put_pipeline.asciidoc[] -include::ingest/get_pipeline.asciidoc[] -include::ingest/delete_pipeline.asciidoc[] -include::ingest/simulate_pipeline.asciidoc[] - -== Snapshot APIs - -The Java High Level REST Client supports the following Snapshot APIs: - -* <> -* <> -* <> -* <> -* <> -* <> -* <> -* <> -* <> -* <> - -include::snapshot/get_repository.asciidoc[] -include::snapshot/create_repository.asciidoc[] -include::snapshot/delete_repository.asciidoc[] -include::snapshot/verify_repository.asciidoc[] -include::snapshot/create_snapshot.asciidoc[] -include::snapshot/get_snapshots.asciidoc[] -include::snapshot/snapshots_status.asciidoc[] -include::snapshot/delete_snapshot.asciidoc[] -include::snapshot/restore_snapshot.asciidoc[] -include::snapshot/clone_snapshot.asciidoc[] - -== Tasks APIs - -The Java High Level REST Client supports the following Tasks APIs: - -* <> -* <> - -include::tasks/list_tasks.asciidoc[] -include::tasks/cancel_tasks.asciidoc[] - -== Script APIs - -The Java High Level REST Client supports the following Scripts APIs: - -* <> -* <> -* <> - -include::script/get_script.asciidoc[] -include::script/put_script.asciidoc[] -include::script/delete_script.asciidoc[] - -== Licensing APIs - -The Java High Level REST Client supports the following Licensing APIs: - -* <> -* <> -* <> -* <> -* <> -* <> -* <> - -include::licensing/put-license.asciidoc[] -include::licensing/get-license.asciidoc[] -include::licensing/delete-license.asciidoc[] -include::licensing/start-trial.asciidoc[] -include::licensing/start-basic.asciidoc[] -include::licensing/get-trial-status.asciidoc[] -include::licensing/get-basic-status.asciidoc[] - -[role="xpack"] -== Machine Learning APIs -:upid: {mainid}-x-pack-ml -:doc-tests-file: {doc-tests}/MlClientDocumentationIT.java - -The Java High Level REST Client supports the following {ml} APIs: - -* <<{upid}-close-job>> -* <<{upid}-delete-job>> -* <<{upid}-delete-calendar-job>> -* <<{upid}-delete-calendar>> -* <<{upid}-delete-calendar-event>> -* <<{upid}-delete-data-frame-analytics>> -* <<{upid}-delete-datafeed>> -* <<{upid}-delete-expired-data>> -* <<{upid}-delete-filter>> -* <<{upid}-delete-forecast>> -* <<{upid}-delete-model-snapshot>> -* <<{upid}-delete-trained-models>> -* <<{upid}-delete-trained-model-alias>> -* <<{upid}-estimate-model-memory>> -* <<{upid}-evaluate-data-frame>> -* <<{upid}-explain-data-frame-analytics>> -* <<{upid}-flush-job>> -* <<{upid}-forecast-job>> -* <<{upid}-get-job>> -* <<{upid}-get-job-stats>> -* <<{upid}-get-buckets>> -* <<{upid}-get-calendars>> -* <<{upid}-get-calendar-events>> -* <<{upid}-get-categories>> -* <<{upid}-get-data-frame-analytics>> -* <<{upid}-get-data-frame-analytics-stats>> -* <<{upid}-get-datafeed>> -* <<{upid}-get-datafeed-stats>> -* <<{upid}-get-filters>> -* <<{upid}-get-influencers>> -* <<{upid}-get-ml-info>> -* <<{upid}-get-model-snapshots>> -* <<{upid}-get-overall-buckets>> -* <<{upid}-get-records>> -* <<{upid}-get-trained-models>> -* <<{upid}-get-trained-models-stats>> -* <<{upid}-open-job>> -* <<{upid}-post-calendar-event>> -* <<{upid}-post-data>> -* <<{upid}-preview-datafeed>> -* <<{upid}-put-job>> -* <<{upid}-put-calendar-job>> -* <<{upid}-put-calendar>> -* <<{upid}-put-data-frame-analytics>> -* <<{upid}-put-datafeed>> -* <<{upid}-put-filter>> -* <<{upid}-put-trained-model>> -* <<{upid}-put-trained-model-alias>> -* <<{upid}-revert-model-snapshot>> -* <<{upid}-set-upgrade-mode>> -* <<{upid}-start-data-frame-analytics>> -* <<{upid}-start-datafeed>> -* <<{upid}-stop-data-frame-analytics>> -* <<{upid}-stop-datafeed>> -* <<{upid}-update-job>> -* <<{upid}-update-data-frame-analytics>> -* <<{upid}-update-datafeed>> -* <<{upid}-update-filter>> -* <<{upid}-update-model-snapshot>> -* <<{upid}-upgrade-job-model-snapshot>> - -// CLOSE -include::ml/close-job.asciidoc[] -// DELETE -include::ml/delete-job.asciidoc[] -include::ml/delete-calendar-job.asciidoc[] -include::ml/delete-calendar-event.asciidoc[] -include::ml/delete-calendar.asciidoc[] -include::ml/delete-data-frame-analytics.asciidoc[] -include::ml/delete-datafeed.asciidoc[] -include::ml/delete-expired-data.asciidoc[] -include::ml/delete-filter.asciidoc[] -include::ml/delete-forecast.asciidoc[] -include::ml/delete-model-snapshot.asciidoc[] -include::ml/delete-trained-models.asciidoc[] -include::ml/delete-trained-model-alias.asciidoc[] -// ESTIMATE -include::ml/estimate-model-memory.asciidoc[] -// EVALUATE -include::ml/evaluate-data-frame.asciidoc[] -// EXPLAIN -include::ml/explain-data-frame-analytics.asciidoc[] -// FLUSH -include::ml/flush-job.asciidoc[] -// FORECAST -include::ml/forecast-job.asciidoc[] -// GET -include::ml/get-job.asciidoc[] -include::ml/get-job-stats.asciidoc[] -include::ml/get-buckets.asciidoc[] -include::ml/get-calendar-events.asciidoc[] -include::ml/get-calendars.asciidoc[] -include::ml/get-categories.asciidoc[] -include::ml/get-data-frame-analytics.asciidoc[] -include::ml/get-data-frame-analytics-stats.asciidoc[] -include::ml/get-datafeed.asciidoc[] -include::ml/get-datafeed-stats.asciidoc[] -include::ml/get-filters.asciidoc[] -include::ml/get-influencers.asciidoc[] -include::ml/get-info.asciidoc[] -include::ml/get-model-snapshots.asciidoc[] -include::ml/get-overall-buckets.asciidoc[] -include::ml/get-records.asciidoc[] -include::ml/get-trained-models.asciidoc[] -include::ml/get-trained-models-stats.asciidoc[] -// OPEN -include::ml/open-job.asciidoc[] -// POST -include::ml/post-calendar-event.asciidoc[] -include::ml/post-data.asciidoc[] -// PREVIEW -include::ml/preview-datafeed.asciidoc[] -// PUT -include::ml/put-job.asciidoc[] -include::ml/put-calendar-job.asciidoc[] -include::ml/put-calendar.asciidoc[] -include::ml/put-data-frame-analytics.asciidoc[] -include::ml/put-datafeed.asciidoc[] -include::ml/put-filter.asciidoc[] -include::ml/put-trained-model.asciidoc[] -include::ml/put-trained-model-alias.asciidoc[] -// REVERT -include::ml/revert-model-snapshot.asciidoc[] -// SET -include::ml/set-upgrade-mode.asciidoc[] -// START -include::ml/start-data-frame-analytics.asciidoc[] -include::ml/start-datafeed.asciidoc[] -// STOP -include::ml/stop-data-frame-analytics.asciidoc[] -include::ml/stop-datafeed.asciidoc[] -// UPDATE -include::ml/update-job.asciidoc[] -include::ml/update-data-frame-analytics.asciidoc[] -include::ml/update-datafeed.asciidoc[] -include::ml/update-filter.asciidoc[] -include::ml/update-model-snapshot.asciidoc[] -include::ml/upgrade-job-model-snapshot.asciidoc[] - -== Migration APIs - -:upid: {mainid}-migration -:doc-tests-file: {doc-tests}/MigrationClientDocumentationIT.java - -The Java High Level REST Client supports the following Migration APIs: - -* <<{upid}-get-deprecation-info>> - -include::migration/get-deprecation-info.asciidoc[] - -[role="xpack"] -== Rollup APIs - -:upid: {mainid}-rollup -:doc-tests-file: {doc-tests}/RollupDocumentationIT.java - -The Java High Level REST Client supports the following Rollup APIs: - -* <> -* <<{upid}-rollup-start-job>> -* <<{upid}-rollup-stop-job>> -* <<{upid}-rollup-delete-job>> -* <> -* <<{upid}-search>> -* <<{upid}-x-pack-rollup-get-rollup-caps>> -* <<{upid}-x-pack-rollup-get-rollup-index-caps>> - -include::rollup/put_job.asciidoc[] -include::rollup/start_job.asciidoc[] -include::rollup/stop_job.asciidoc[] -include::rollup/delete_job.asciidoc[] -include::rollup/get_job.asciidoc[] -include::rollup/search.asciidoc[] -include::rollup/get_rollup_caps.asciidoc[] -include::rollup/get_rollup_index_caps.asciidoc[] - -[role="xpack"] -== Security APIs - -:upid: {mainid}-security -:doc-tests-file: {doc-tests}/SecurityDocumentationIT.java - -The Java High Level REST Client supports the following Security APIs: - -* <> -* <<{upid}-get-users>> -* <<{upid}-delete-user>> -* <> -* <> -* <> -* <<{upid}-put-role>> -* <<{upid}-get-roles>> -* <> -* <<{upid}-clear-roles-cache>> -* <<{upid}-clear-privileges-cache>> -* <<{upid}-clear-realm-cache>> -* <<{upid}-clear-api-key-cache>> -* <<{upid}-clear-service-account-token-cache>> -* <<{upid}-authenticate>> -* <<{upid}-has-privileges>> -* <<{upid}-get-user-privileges>> -* <> -* <> -* <> -* <> -* <> -* <<{upid}-invalidate-token>> -* <<{upid}-get-builtin-privileges>> -* <<{upid}-get-privileges>> -* <<{upid}-put-privileges>> -* <<{upid}-delete-privileges>> -* <<{upid}-create-api-key>> -* <<{upid}-get-api-key>> -* <<{upid}-invalidate-api-key>> -* <<{upid}-get-service-accounts>> -* <<{upid}-create-service-account-token>> -* <<{upid}-delete-service-account-token>> -* <<{upid}-get-service-account-credentials>> - -include::security/put-user.asciidoc[] -include::security/get-users.asciidoc[] -include::security/delete-user.asciidoc[] -include::security/enable-user.asciidoc[] -include::security/disable-user.asciidoc[] -include::security/change-password.asciidoc[] -include::security/put-role.asciidoc[] -include::security/get-roles.asciidoc[] -include::security/delete-role.asciidoc[] -include::security/delete-privileges.asciidoc[] -include::security/get-builtin-privileges.asciidoc[] -include::security/get-privileges.asciidoc[] -include::security/clear-roles-cache.asciidoc[] -include::security/clear-privileges-cache.asciidoc[] -include::security/clear-realm-cache.asciidoc[] -include::security/clear-api-key-cache.asciidoc[] -include::security/clear-service-account-token-cache.asciidoc[] -include::security/authenticate.asciidoc[] -include::security/has-privileges.asciidoc[] -include::security/get-user-privileges.asciidoc[] -include::security/get-certificates.asciidoc[] -include::security/put-role-mapping.asciidoc[] -include::security/get-role-mappings.asciidoc[] -include::security/delete-role-mapping.asciidoc[] -include::security/create-token.asciidoc[] -include::security/invalidate-token.asciidoc[] -include::security/put-privileges.asciidoc[] -include::security/create-api-key.asciidoc[] -include::security/grant-api-key.asciidoc[] -include::security/get-api-key.asciidoc[] -include::security/invalidate-api-key.asciidoc[] -include::security/query-api-key.asciidoc[] -include::security/get-service-accounts.asciidoc[] -include::security/create-service-account-token.asciidoc[] -include::security/delete-service-account-token.asciidoc[] -include::security/get-service-account-credentials.asciidoc[] - -[role="xpack"] -== Text Structure APIs -:upid: {mainid}-text-structure -:doc-tests-file: {doc-tests}/TextStructureClientDocumentationIT.java - -The Java High Level REST Client supports the following Text Structure APIs: - -* <<{upid}-find-structure>> - -include::textstructure/find-structure.asciidoc[] - -[role="xpack"] -== Watcher APIs - -:upid: {mainid}-watcher -:doc-tests-file: {doc-tests}/WatcherDocumentationIT.java - -The Java High Level REST Client supports the following Watcher APIs: - -* <<{upid}-start-watch-service>> -* <<{upid}-stop-watch-service>> -* <> -* <<{upid}-get-watch>> -* <> -* <> -* <<{upid}-ack-watch>> -* <<{upid}-activate-watch>> -* <<{upid}-execute-watch>> -* <<{upid}-watcher-stats>> - -include::watcher/start-watch-service.asciidoc[] -include::watcher/stop-watch-service.asciidoc[] -include::watcher/put-watch.asciidoc[] -include::watcher/get-watch.asciidoc[] -include::watcher/delete-watch.asciidoc[] -include::watcher/ack-watch.asciidoc[] -include::watcher/deactivate-watch.asciidoc[] -include::watcher/activate-watch.asciidoc[] -include::watcher/execute-watch.asciidoc[] -include::watcher/watcher-stats.asciidoc[] - -[role="xpack"] -== Graph APIs - -The Java High Level REST Client supports the following Graph APIs: - -* <> - -include::graph/explore.asciidoc[] - -//// -Clear attributes that we use to document that APIs included above so they -don't leak into the rest of the documentation. -//// --- -:api!: -:request!: -:response!: -:doc-tests-file!: -:upid!: --- - -[role="xpack"] -== CCR APIs - -:upid: {mainid}-ccr -:doc-tests-file: {doc-tests}/CCRDocumentationIT.java - -The Java High Level REST Client supports the following CCR APIs: - -* <<{upid}-ccr-put-follow>> -* <<{upid}-ccr-pause-follow>> -* <<{upid}-ccr-resume-follow>> -* <<{upid}-ccr-unfollow>> -* <<{upid}-ccr-forget-follower>> -* <<{upid}-ccr-put-auto-follow-pattern>> -* <<{upid}-ccr-delete-auto-follow-pattern>> -* <<{upid}-ccr-get-auto-follow-pattern>> -* <<{upid}-ccr-pause-auto-follow-pattern>> -* <<{upid}-ccr-resume-auto-follow-pattern>> -* <<{upid}-ccr-get-stats>> -* <<{upid}-ccr-get-follow-stats>> -* <<{upid}-ccr-get-follow-info>> - -include::ccr/put_follow.asciidoc[] -include::ccr/pause_follow.asciidoc[] -include::ccr/resume_follow.asciidoc[] -include::ccr/unfollow.asciidoc[] -include::ccr/forget_follower.asciidoc[] -include::ccr/put_auto_follow_pattern.asciidoc[] -include::ccr/delete_auto_follow_pattern.asciidoc[] -include::ccr/get_auto_follow_pattern.asciidoc[] -include::ccr/pause_auto_follow_pattern.asciidoc[] -include::ccr/resume_auto_follow_pattern.asciidoc[] -include::ccr/get_stats.asciidoc[] -include::ccr/get_follow_stats.asciidoc[] -include::ccr/get_follow_info.asciidoc[] - -[role="xpack"] -== Index Lifecycle Management APIs - -:upid: {mainid}-ilm -:doc-tests-file: {doc-tests}/ILMDocumentationIT.java - -The Java High Level REST Client supports the following Index Lifecycle -Management APIs: - -* <<{upid}-ilm-put-lifecycle-policy>> -* <<{upid}-ilm-delete-lifecycle-policy>> -* <<{upid}-ilm-get-lifecycle-policy>> -* <<{upid}-ilm-explain-lifecycle>> -* <<{upid}-ilm-start-ilm>> -* <<{upid}-ilm-stop-ilm>> -* <<{upid}-ilm-status>> -* <<{upid}-ilm-retry-lifecycle-policy>> -* <<{upid}-ilm-remove-lifecycle-policy-from-index>> - - -include::ilm/put_lifecycle_policy.asciidoc[] -include::ilm/delete_lifecycle_policy.asciidoc[] -include::ilm/get_lifecycle_policy.asciidoc[] -include::ilm/explain_lifecycle.asciidoc[] -include::ilm/start_lifecycle_management.asciidoc[] -include::ilm/stop_lifecycle_management.asciidoc[] -include::ilm/lifecycle_management_status.asciidoc[] -include::ilm/retry_lifecycle_policy.asciidoc[] -include::ilm/remove_lifecycle_policy_from_index.asciidoc[] - -[role="xpack"] -== Snapshot Lifecycle Management APIs - -:upid: {mainid}-ilm -:doc-tests-file: {doc-tests}/ILMDocumentationIT.java - -The Java High Level REST Client supports the following Snapshot Lifecycle -Management APIs: - -* <<{upid}-slm-put-snapshot-lifecycle-policy>> -* <<{upid}-slm-delete-snapshot-lifecycle-policy>> -* <<{upid}-ilm-get-lifecycle-policy>> -* <<{upid}-slm-start-slm>> -* <<{upid}-slm-stop-slm>> -* <<{upid}-slm-status>> -* <<{upid}-slm-execute-snapshot-lifecycle-policy>> -* <<{upid}-slm-execute-snapshot-lifecycle-retention>> - - -include::ilm/put_snapshot_lifecycle_policy.asciidoc[] -include::ilm/delete_snapshot_lifecycle_policy.asciidoc[] -include::ilm/get_snapshot_lifecycle_policy.asciidoc[] -include::ilm/start_snapshot_lifecycle_management.asciidoc[] -include::ilm/stop_snapshot_lifecycle_management.asciidoc[] -include::ilm/snapshot_lifecycle_management_status.asciidoc[] -include::ilm/execute_snapshot_lifecycle_policy.asciidoc[] -include::ilm/execute_snapshot_lifecycle_retention.asciidoc[] - -[role="xpack"] -== Searchable Snapshots APIs - -:upid: {mainid}-searchable-snapshots -:doc-tests-file: {doc-tests}/SearchableSnapshotsDocumentationIT.java - -The Java High Level REST Client supports the following Searchable Snapshots APIs: - -* <<{upid}-searchable-snapshots-mount-snapshot>> -* <<{upid}-searchable-snapshots-caches-stats>> - - -include::searchable_snapshots/mount_snapshot.asciidoc[] -include::searchable_snapshots/caches_stats.asciidoc[] - -[role="xpack"] -[[transform_apis]] -== {transform-cap} APIs - -:upid: {mainid} -:doc-tests-file: {doc-tests}/TransformDocumentationIT.java - -The Java High Level REST Client supports the following {transform} -APIs: - -* <<{upid}-get-transform>> -* <<{upid}-get-transform-stats>> -* <<{upid}-put-transform>> -* <<{upid}-update-transform>> -* <<{upid}-delete-transform>> -* <<{upid}-preview-transform>> -* <<{upid}-start-transform>> -* <<{upid}-stop-transform>> - -include::transform/get_transform.asciidoc[] -include::transform/get_transform_stats.asciidoc[] -include::transform/put_transform.asciidoc[] -include::transform/update_transform.asciidoc[] -include::transform/delete_transform.asciidoc[] -include::transform/preview_transform.asciidoc[] -include::transform/start_transform.asciidoc[] -include::transform/stop_transform.asciidoc[] - -== Enrich APIs - -:upid: {mainid}-enrich -:doc-tests-file: {doc-tests}/EnrichDocumentationIT.java - -The Java High Level REST Client supports the following Enrich APIs: - -* <<{upid}-enrich-put-policy>> -* <<{upid}-enrich-delete-policy>> -* <<{upid}-enrich-get-policy>> -* <<{upid}-enrich-stats>> -* <<{upid}-enrich-execute-policy>> - -include::enrich/put_policy.asciidoc[] -include::enrich/delete_policy.asciidoc[] -include::enrich/get_policy.asciidoc[] -include::enrich/stats.asciidoc[] -include::enrich/execute_policy.asciidoc[] diff --git a/docs/java-rest/high-level/tasks/cancel_tasks.asciidoc b/docs/java-rest/high-level/tasks/cancel_tasks.asciidoc deleted file mode 100644 index 69c317efa82c..000000000000 --- a/docs/java-rest/high-level/tasks/cancel_tasks.asciidoc +++ /dev/null @@ -1,84 +0,0 @@ -[[java-rest-high-cluster-cancel-tasks]] -=== Cancel Tasks API - -The Cancel Tasks API allows cancellation of a currently running task. - -==== Cancel Tasks Request - -A `CancelTasksRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-request] --------------------------------------------------- -There are no required parameters. The task cancellation command supports the same -task selection parameters as the list tasks command. - -==== Parameters - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-request-filter] --------------------------------------------------- -<1> Cancel a task -<2> Cancel only cluster-related tasks -<3> Should the request block until the cancellation of the task and its child tasks is completed. -Otherwise, the request can return soon after the cancellation is started. Defaults to `false`. -<4> Cancel all tasks running on nodes nodeId1 and nodeId2 - -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-execute] --------------------------------------------------- - -==== Asynchronous Execution - -The asynchronous execution requires `CancelTasksRequest` instance and an -`ActionListener` instance to be passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-execute-async] --------------------------------------------------- -<1> The `CancelTasksRequest` 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 `CancelTasksResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -==== Cancel Tasks Response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-response-tasks] --------------------------------------------------- -<1> List of cancelled tasks - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-response-calc] --------------------------------------------------- -<1> List of cancelled tasks grouped by a node -<2> List of cancelled tasks grouped by a parent task - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-response-failures] --------------------------------------------------- -<1> List of node failures -<2> List of task cancellation failures - diff --git a/docs/java-rest/high-level/tasks/list_tasks.asciidoc b/docs/java-rest/high-level/tasks/list_tasks.asciidoc deleted file mode 100644 index e60ca61247e7..000000000000 --- a/docs/java-rest/high-level/tasks/list_tasks.asciidoc +++ /dev/null @@ -1,101 +0,0 @@ -[[java-rest-high-tasks-list]] -=== List Tasks API - -The List Tasks API allows to get information about the tasks currently executing in the cluster. - -[[java-rest-high-cluster-list-tasks-request]] -==== List Tasks Request - -A `ListTasksRequest`: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-request] --------------------------------------------------- -There is no required parameters. By default the client will list all tasks and will not wait -for task completion. - -==== Parameters - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-request-filter] --------------------------------------------------- -<1> Request only cluster-related tasks -<2> Request all tasks running on nodes nodeId1 and nodeId2 -<3> Request only children of a particular task - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-request-detailed] --------------------------------------------------- -<1> Should the information include detailed, potentially slow to generate data. Defaults to `false` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-request-wait-completion] --------------------------------------------------- -<1> Should this request wait for all found tasks to complete. Defaults to `false` -<2> Timeout for the request as a `TimeValue`. Applicable only if `setWaitForCompletion` is `true`. -Defaults to 30 seconds -<3> Timeout as a `String` - -[[java-rest-high-cluster-list-tasks-sync]] -==== Synchronous Execution - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-execute] --------------------------------------------------- - -[[java-rest-high-cluster-list-tasks-async]] -==== Asynchronous Execution - -The asynchronous execution of a cluster update settings requires both the -`ListTasksRequest` instance and an `ActionListener` instance to be -passed to the asynchronous method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-execute-async] --------------------------------------------------- -<1> The `ListTasksRequest` 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 `ListTasksResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-execute-listener] --------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of a failure. The raised exception is provided as an argument - -[[java-rest-high-cluster-list-tasks-response]] -==== List Tasks Response - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-tasks] --------------------------------------------------- -<1> List of currently running tasks - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-calc] --------------------------------------------------- -<1> List of tasks grouped by a node -<2> List of tasks grouped by a parent task - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-failures] --------------------------------------------------- -<1> List of node failures -<2> List of tasks failures diff --git a/docs/java-rest/high-level/textstructure/find-structure.asciidoc b/docs/java-rest/high-level/textstructure/find-structure.asciidoc deleted file mode 100644 index b51a8cd11322..000000000000 --- a/docs/java-rest/high-level/textstructure/find-structure.asciidoc +++ /dev/null @@ -1,52 +0,0 @@ --- -:api: find-structure -:request: FindStructureRequest -:response: FindStructureResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Find structure API - -Determines the structure of text and other information that will be -useful to import its contents to an {es} index. It accepts a +{request}+ object -and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Find structure request - -A sample of the text to analyze must be added to the +{request}+ -object using the `FindStructureRequest#setSample` method. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Create a new `FindStructureRequest` object -<2> Add the contents of `anInterestingFile` to the request - -==== Optional arguments - -The following arguments are optional: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Set the maximum number of lines to sample (the entire sample will be - used if it contains fewer lines) -<2> Request that an explanation of the analysis be returned in the response - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Find structure response - -A +{response}+ contains information about the text structure, -as well as mappings and an ingest pipeline that could be used -to index the contents into {es}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The `TextStructure` object contains the structure information diff --git a/docs/java-rest/high-level/transform/delete_transform.asciidoc b/docs/java-rest/high-level/transform/delete_transform.asciidoc deleted file mode 100644 index 8416ce40e371..000000000000 --- a/docs/java-rest/high-level/transform/delete_transform.asciidoc +++ /dev/null @@ -1,31 +0,0 @@ --- -:api: delete-transform -:request: DeleteTransformRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Delete {transform} API - -Deletes an existing {transform}. - -[id="{upid}-{api}-request"] -==== Delete {transform} request - -A +{request}+ object requires a non-null `id`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new request referencing an existing {transform} -<2> Sets the optional argument `force`. When `true`, the {transform} -is deleted regardless of its current state. The default value is `false`, -meaning that only `stopped` {transforms} can be deleted. - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ object acknowledges the {transform} deletion. diff --git a/docs/java-rest/high-level/transform/get_transform.asciidoc b/docs/java-rest/high-level/transform/get_transform.asciidoc deleted file mode 100644 index ca79ebf17e1b..000000000000 --- a/docs/java-rest/high-level/transform/get_transform.asciidoc +++ /dev/null @@ -1,52 +0,0 @@ --- -:api: get-transform -:request: GetTransformRequest -:response: GetTransformResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get {transform} API - -Retrieves configuration information about one or more {transforms}. -The API accepts a +{request}+ object and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Get {transform} request - -A +{request}+ requires either a {transform} ID, a comma separated list -of ids or the special wildcard `_all` to get all {transforms}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new GET request referencing an existing {transform} - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of -{transforms} to skip. `size` specifies the maximum number of -{transforms} to get. Defaults to `0` and `100` respectively. -<2> Whether to ignore if a wildcard expression matches no {transforms}. -<3> Optional boolean value for requesting the {transform} in a format that can -then be put into another cluster. Certain fields that can only be set when -the {transform} is created are removed. - - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the requested {transforms}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- diff --git a/docs/java-rest/high-level/transform/get_transform_stats.asciidoc b/docs/java-rest/high-level/transform/get_transform_stats.asciidoc deleted file mode 100644 index cd2fcf2237cc..000000000000 --- a/docs/java-rest/high-level/transform/get_transform_stats.asciidoc +++ /dev/null @@ -1,56 +0,0 @@ --- -:api: get-transform-stats -:request: GetTransformStatsRequest -:response: GetTransformStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get {transform} stats API - -Retrieves the operational statistics of one or more {transforms}. -The API accepts a +{request}+ object and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Get {transform} stats request - -A +{request}+ requires a {transform} id or the special wildcard `_all` -to get the statistics for all {transforms}. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> Constructing a new GET Stats request referencing an existing {transform} - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> The page parameters `from` and `size`. `from` specifies the number of -{transform} stats to skip. -`size` specifies the maximum number of {transform} stats to get. -Defaults to `0` and `100` respectively. -<2> Whether to ignore if a wildcard expression matches no {transforms}. - - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the requested {transform} statistics. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The response contains a list of `TransformStats` objects -<2> The running state of the {transform}, for example `started`, `indexing`, etc. -<3> The overall {transform} statistics recording the number of documents indexed etc. -<4> The progress of the current run in the {transform}. Supplies the number of docs left until the next checkpoint -and the total number of docs expected. -<5> The assigned node information if the task is currently assigned to a node and running. diff --git a/docs/java-rest/high-level/transform/preview_transform.asciidoc b/docs/java-rest/high-level/transform/preview_transform.asciidoc deleted file mode 100644 index 377aba597a67..000000000000 --- a/docs/java-rest/high-level/transform/preview_transform.asciidoc +++ /dev/null @@ -1,32 +0,0 @@ --- -:api: preview-transform -:request: PreviewTransformRequest -:response: PreviewTransformResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Preview {transform} API - -Previews the results of a {transform}. - -The API accepts a +{request}+ object as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Preview {transform} request - -A +{request}+ takes a single argument: a valid {transform} config. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The source config from which the data should be gathered -<2> The pivot config used to transform the data -<3> The configuration of the {transform} to preview - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the preview documents diff --git a/docs/java-rest/high-level/transform/put_transform.asciidoc b/docs/java-rest/high-level/transform/put_transform.asciidoc deleted file mode 100644 index bd41a662eee7..000000000000 --- a/docs/java-rest/high-level/transform/put_transform.asciidoc +++ /dev/null @@ -1,160 +0,0 @@ --- -:api: put-transform -:request: PutTransformRequest -:response: AcknowledgedResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Create {transform} API - -Creates a new {transform}. - -The API accepts a +{request}+ object as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Create {transform} request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The configuration of the {transform} to create -<2> Whether or not to wait to run deferrable validations until `_start` is called. -This option should be used with care as the created {transform} will run -with the privileges of the user creating it. Meaning, if they do not have privileges, -such an error will not be visible until `_start` is called. - -[id="{upid}-{api}-config"] -==== {transform-cap} configuration - -The `TransformConfig` object contains all the details about the -{transform} configuration and contains the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> The {transform} ID -<2> The source indices and query from which to gather data -<3> The destination index and optional pipeline -<4> Optional, indicates how often to check for updates to the source indices -<5> The PivotConfig -<6> Optional free text description of the {transform} -<7> Optional {transform} settings -<8> Optional retention policy for the data in the destination index -<9> Details required only when the {transform} runs continuously - -[id="{upid}-{api}-query-config"] - -==== SourceConfig - -The indices and the query from which to collect data. -If query is not set, a `match_all` query is used by default. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-source-config] --------------------------------------------------- - -==== DestConfig - -The index where to write the data and the optional pipeline -through which the docs should be indexed - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-dest-config] --------------------------------------------------- - -===== QueryConfig - -The query with which to select data from the source. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-query-config] --------------------------------------------------- - -==== PivotConfig - -Defines the pivot function `group by` fields and the aggregation to reduce the data. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-pivot-config] --------------------------------------------------- -<1> The `GroupConfig` to use in the pivot -<2> The aggregations to use - -===== GroupConfig -The grouping terms. Defines the group by and destination fields -which are produced by the pivot function. There are 3 types of -groups - -* Terms -* Histogram -* Date Histogram - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-group-config] --------------------------------------------------- -<1> The destination field -<2> Group by values of the `user_id` field - -===== AggregationConfig - -Defines the aggregations for the group fields. -// TODO link to the supported aggregations - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-agg-config] --------------------------------------------------- -<1> Aggregate the average star rating - -===== RetentionPolicyConfig - -Defines a retention policy for the {transform}. Data that meets the defined -criteria is deleted from the destination index. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-retention-policy-config] --------------------------------------------------- -<1> The date field that is used to calculate the age of the document. -<2> Specifies the maximum age of a document in the destination index. - -===== SettingsConfig - -Defines settings. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-settings-config] --------------------------------------------------- -<1> The maximum paging size for the {transform} when pulling data -from the source. The size dynamically adjusts as the {transform} -is running to recover from and prevent OOM issues. - -===== SyncConfig - -Defines the properties {transforms} require to run continuously. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-sync-config] --------------------------------------------------- -<1> The date field that is used to identify new documents in the source. -<2> The time delay between the current time and the latest input data time. - - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ acknowledges the successful creation of -the new {transform} or an error if the configuration is invalid. diff --git a/docs/java-rest/high-level/transform/start_transform.asciidoc b/docs/java-rest/high-level/transform/start_transform.asciidoc deleted file mode 100644 index 9de2a0da23d2..000000000000 --- a/docs/java-rest/high-level/transform/start_transform.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ --- -:api: start-transform -:request: StartTransformRequest -:response: StartTransformResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Start {transform} API - -Starts a {transform}. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Start {transform} request - -A +{request}+ object requires a non-null `id`. - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new start request referencing an existing -{transform} - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> Controls the amount of time to wait until the {transform} starts. - -include::../execution.asciidoc[] - -==== Response - -The returned +{response}+ object acknowledges the {transform} has -started. diff --git a/docs/java-rest/high-level/transform/stop_transform.asciidoc b/docs/java-rest/high-level/transform/stop_transform.asciidoc deleted file mode 100644 index ce49434318d9..000000000000 --- a/docs/java-rest/high-level/transform/stop_transform.asciidoc +++ /dev/null @@ -1,42 +0,0 @@ --- -:api: stop-transform -:request: StopTransformRequest -:response: StopTransformResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Stop {transform} API - -Stops a started {transform}. -It accepts a +{request}+ object and responds with a +{response}+ object. - -[id="{upid}-{api}-request"] -==== Stop {transform} request - -A +{request}+ object requires a non-null `id`. `id` can be a comma separated -list of IDs or a single ID. Wildcards, `*` and `_all` are also accepted. - - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] ---------------------------------------------------- -<1> Constructing a new stop request referencing an existing {transform}. - -==== Optional arguments - -The following arguments are optional. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-options] --------------------------------------------------- -<1> If true wait for the {transform} task to stop before responding. -<2> Controls the amount of time to wait until the {transform} stops. -<3> Whether to ignore if a wildcard expression matches no {transforms}. - -include::../execution.asciidoc[] - -==== Response - -The returned +{response}+ object acknowledges the {transform} has stopped. diff --git a/docs/java-rest/high-level/transform/update_transform.asciidoc b/docs/java-rest/high-level/transform/update_transform.asciidoc deleted file mode 100644 index 59081396be48..000000000000 --- a/docs/java-rest/high-level/transform/update_transform.asciidoc +++ /dev/null @@ -1,53 +0,0 @@ --- -:api: update-transform -:request: UpdateTransformRequest -:response: UpdateTransformResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Update {transform} API - -Updates an existing {transform}. - -The API accepts a +{request}+ object as a request and returns a +{response}+. - -[id="{upid}-{api}-request"] -==== Update {transform} request - -A +{request}+ requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The update configuration with which to update the {transform}. -<2> The ID of the configuration to update. -<3> Whether or not to wait to run deferrable validations until `_start` is called. -This option should be used with care as the created {transform} will run -with the privileges of the user creating it. Meaning, if they do not have privileges, -such an error will not be visible until `_start` is called. - -[id="{upid}-{api}-config"] -==== {transform-cap} update configuration - -The `TransformConfigUpdate` object contains all the details about updated -{transform} configuration and contains the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-config] --------------------------------------------------- -<1> The source indices and query from which to gather data. -<2> The destination index and optional pipeline. -<3> How often to check for updates to the source indices. -<4> How to keep the {transform} in sync with incoming data. -<5> Optional free text description of the {transform}. -<6> Optional retention policy for the data in the destination index - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the updated {transform} configuration -or an error if the update failed or is invalid. diff --git a/docs/java-rest/high-level/watcher/ack-watch.asciidoc b/docs/java-rest/high-level/watcher/ack-watch.asciidoc deleted file mode 100644 index 7dfc3faad8eb..000000000000 --- a/docs/java-rest/high-level/watcher/ack-watch.asciidoc +++ /dev/null @@ -1,39 +0,0 @@ --- -:api: ack-watch -:request: AckWatchRequest -:response: AckWatchResponse --- - -[role="xpack"] -[id="{upid}-{api}"] -=== Ack watch API - -[id="{upid}-{api}-request"] -==== Execution - -{ref}/actions.html#actions-ack-throttle[Acknowledging a watch] enables you -to manually throttle execution of a watch's actions. A watch can be acknowledged -through the following request: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The ID of the watch to ack. -<2> An optional list of IDs representing the watch actions that should be acked. -If no action IDs are provided, then all of the watch's actions will be acked. - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the new status of the requested watch: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> The status of a specific action that was acked. -<2> The acknowledgement state of the action. If the action was successfully -acked, this state will be equal to `AckStatus.State.ACKED`. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/watcher/activate-watch.asciidoc b/docs/java-rest/high-level/watcher/activate-watch.asciidoc deleted file mode 100644 index 6cbe0344e34a..000000000000 --- a/docs/java-rest/high-level/watcher/activate-watch.asciidoc +++ /dev/null @@ -1,56 +0,0 @@ --- -:api: activate-watch -:request: ActivateWatchRequest -:response: ActivateWatchResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Activate watch API - -[id="{upid}-{api}-request"] -==== Execution - -A watch can be activated as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains the new status of the activated watch. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `watchStatus` contains status of the watch - -[id="{upid}-{api}-request-async"] -==== Asynchronous execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-async] --------------------------------------------------- -<1> The +{request}+ 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 +{response}+ looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-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 diff --git a/docs/java-rest/high-level/watcher/deactivate-watch.asciidoc b/docs/java-rest/high-level/watcher/deactivate-watch.asciidoc deleted file mode 100644 index 3594fda984e4..000000000000 --- a/docs/java-rest/high-level/watcher/deactivate-watch.asciidoc +++ /dev/null @@ -1,11 +0,0 @@ --- -:api: deactivate-watch -:request: deactivateWatchRequest -:response: deactivateWatchResponse -:doc-tests-file: {doc-tests}/WatcherDocumentationIT.java --- -[role="xpack"] -[[java-rest-high-watcher-deactivate-watch]] -=== Deactivate watch API - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/watcher/delete-watch.asciidoc b/docs/java-rest/high-level/watcher/delete-watch.asciidoc deleted file mode 100644 index 9e438bb16b5d..000000000000 --- a/docs/java-rest/high-level/watcher/delete-watch.asciidoc +++ /dev/null @@ -1,54 +0,0 @@ -[role="xpack"] -[[java-rest-high-x-pack-watcher-delete-watch]] -=== Delete watch API - -[[java-rest-high-x-pack-watcher-delete-watch-execution]] -==== Execution - -A watch can be deleted as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-delete-watch-execute] --------------------------------------------------- - -[[java-rest-high-x-pack-watcher-delete-watch-response]] -==== Response - -The returned `DeleteWatchResponse` contains `found`, `id`, -and `version` information. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-response] --------------------------------------------------- -<1> `_id` contains id of the watch -<2> `found` is a boolean indicating whether the watch was found -<3> `_version` returns the version of the deleted watch - -[[java-rest-high-x-pack-watcher-delete-watch-async]] -==== Asynchronous execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-delete-watch-execute-async] --------------------------------------------------- -<1> The `DeleteWatchRequest` 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 `DeleteWatchResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-delete-watch-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 diff --git a/docs/java-rest/high-level/watcher/execute-watch.asciidoc b/docs/java-rest/high-level/watcher/execute-watch.asciidoc deleted file mode 100644 index 4884b30ca7d2..000000000000 --- a/docs/java-rest/high-level/watcher/execute-watch.asciidoc +++ /dev/null @@ -1,89 +0,0 @@ --- -:api: execute-watch -:request: ExecuteWatchRequest -:response: ExecuteWatchResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Execute watch API - -The execute watch API allows clients to immediately execute a watch, either one -that has been previously added via the {ref}/watcher-api-put-watch.html[create -or update watch API] or inline as part of the request. - -[id="{upid}-{api}-request-by-id"] -==== Execute by id - -Submit the following request to execute a previously added watch: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id] ---------------------------------------------------- -<1> Alternative input for the watch to use in json format -<2> Set the mode for action "action1" to SIMULATE -<3> Record this execution in watcher history -<4> Execute the watch regardless of the watch's condition -<5> Set the trigger data for the watch in json format -<6> Enable debug mode - -[id="{upid}-{api}-response-by-id"] -==== Execute by id response - -The returned `Response` contains details of the execution: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-response] ---------------------------------------------------- -<1> The record ID for this execution -<2> The execution response as a java `Map` -<3> Extract information from the response map using `ObjectPath` - -[id="{upid}-{api}-response-by-id-async"] -==== Asynchronous execution by id - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-execute-async] --------------------------------------------------- -<1> The `ExecuteWatchRequest` 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 `ExecuteWatchResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-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 - - -[id="{upid}-{api}-request-inline"] -==== Execute inline - -Submit the following request to execute a watch defined as part of the request: - -["source","java",subs="attributes,callouts,macros"] ---------------------------------------------------- -include-tagged::{doc-tests-file}[x-pack-execute-watch-inline] ---------------------------------------------------- -<1> Alternative input for the watch to use in json format -<2> Set the mode for action "action1" to SIMULATE -<3> Execute the watch regardless of the watch's condition -<4> Set the trigger data for the watch in json format -<5> Enable debug mode - -Note that inline watches cannot be recorded. - -The response format and asynchronous execution methods are the same as for the -Execute Watch by ID API. \ No newline at end of file diff --git a/docs/java-rest/high-level/watcher/get-watch.asciidoc b/docs/java-rest/high-level/watcher/get-watch.asciidoc deleted file mode 100644 index 540f64ca9472..000000000000 --- a/docs/java-rest/high-level/watcher/get-watch.asciidoc +++ /dev/null @@ -1,36 +0,0 @@ --- -:api: get-watch -:request: GetWatchRequest -:response: GetWatchResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get watch API - -[id="{upid}-{api}-request"] -==== Execution - -A watch can be retrieved as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned +{response}+ contains `id`, `version`, `status` and `source` -information. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> `_id`, id of the watch -<2> `found` is a boolean indicating whether the watch was found -<3> `_version` returns the version of the watch -<4> `status` contains status of the watch -<5> `source` the source of the watch - -include::../execution.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/high-level/watcher/put-watch.asciidoc b/docs/java-rest/high-level/watcher/put-watch.asciidoc deleted file mode 100644 index c6a02a75e38c..000000000000 --- a/docs/java-rest/high-level/watcher/put-watch.asciidoc +++ /dev/null @@ -1,56 +0,0 @@ -[role="xpack"] -[[java-rest-high-x-pack-watcher-put-watch]] -=== Create or update watch API - -[[java-rest-high-x-pack-watcher-put-watch-execution]] -==== Execution - -General information about the installed {watcher} features can be retrieved -using the `watcher()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-execute] --------------------------------------------------- -<1> Allows to store the watch, but to not trigger it. Defaults to `true` - -[[java-rest-high-x-pack-watcher-put-watch-response]] -==== Response - -The returned `PutWatchResponse` contains `created`, `id`, -and `version` information. - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-response] --------------------------------------------------- -<1> `_id` contains id of the watch -<2> `created` is a boolean indicating whether the watch was created for the first time -<3> `_version` returns the newly created version - -[[java-rest-high-x-pack-watcher-put-watch-async]] -==== Asynchronous execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-execute-async] --------------------------------------------------- -<1> The `PutWatchRequest` 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 `PutWatchResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-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 diff --git a/docs/java-rest/high-level/watcher/start-watch-service.asciidoc b/docs/java-rest/high-level/watcher/start-watch-service.asciidoc deleted file mode 100644 index 02b439e0c6af..000000000000 --- a/docs/java-rest/high-level/watcher/start-watch-service.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ --- -:api: start-watch-service -:request: StartWatchServiceRequest -:response: StartWatchServiceResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Start watch service API - -[id="{upid}-{api}-request"] -==== Execution - -{ref}/watcher-api-start.html[Start watcher] enables you -to manually start the watch service. Submit the following request -to start the watch service: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned `AcknowledgedResponse` contains a value on whether or not the request -was received: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> A boolean value of `true` if successfully received, `false` otherwise. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/watcher/stop-watch-service.asciidoc b/docs/java-rest/high-level/watcher/stop-watch-service.asciidoc deleted file mode 100644 index 9eeca6b2236d..000000000000 --- a/docs/java-rest/high-level/watcher/stop-watch-service.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ --- -:api: stop-watch-service -:request: StopWatchServiceRequest -:response: StopWatchServiceResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Stop watch service API - -[[java-rest-high-watcher-stop-watch-service-execution]] -==== Execution - -{ref}/watcher-api-stop.html[Stop watcher] enables you -to manually stop the watch service. Submit the following request -to stop the watch service: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[[java-rest-high-watcher-stop-watch-service-response]] -==== Response - -The returned `AcknowledgeResponse` contains a value on whether or not the request -was received: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> A boolean value of `true` if successfully received, `false` otherwise. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/high-level/watcher/watcher-stats.asciidoc b/docs/java-rest/high-level/watcher/watcher-stats.asciidoc deleted file mode 100644 index d0e1837c26c9..000000000000 --- a/docs/java-rest/high-level/watcher/watcher-stats.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ --- -:api: watcher-stats -:request: WatcherStatsRequest -:response: WatcherStatsResponse --- -[role="xpack"] -[id="{upid}-{api}"] -=== Get Watcher stats API - -[id="{upid}-{api}-request"] -==== Execution - -{ref}/watcher-api-stats.html[Watcher Stats] returns the current {watcher} metrics. -Submit the following request to get the stats: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- - -[id="{upid}-{api}-response"] -==== Response - -The returned `AcknowledgeResponse` contains a value on whether or not the request -was received: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> A boolean value of `true` if successfully received, `false` otherwise. - -include::../execution.asciidoc[] diff --git a/docs/java-rest/index.asciidoc b/docs/java-rest/index.asciidoc index f688d152f228..70f07463e7b7 100644 --- a/docs/java-rest/index.asciidoc +++ b/docs/java-rest/index.asciidoc @@ -6,7 +6,3 @@ include::{asciidoc-dir}/../../shared/attributes.asciidoc[] include::../Versions.asciidoc[] include::overview.asciidoc[] - -include::high-level/index.asciidoc[] - -include::redirects.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/overview.asciidoc b/docs/java-rest/overview.asciidoc index 4539406e4c3f..8d7f97b0039a 100644 --- a/docs/java-rest/overview.asciidoc +++ b/docs/java-rest/overview.asciidoc @@ -1,13 +1,17 @@ [[java-rest-overview]] == Overview +removed[8.0.0, The High Level REST Client has been removed in favour of the {java-api-client}/index.html[Java API Client].] + The Java REST Client comes in 2 flavors: -* <>: the official low-level client for Elasticsearch. +* The official low-level client for Elasticsearch. It allows to communicate with an Elasticsearch cluster through http. Leaves requests marshalling and responses un-marshalling to users. It is compatible with all Elasticsearch versions. * <>: the official high-level client for Elasticsearch. Based on the low-level client, it exposes API specific methods and takes care -of requests marshalling and responses un-marshalling. \ No newline at end of file +of requests marshalling and responses un-marshalling. This Java High Level +REST Client was deprecated since 7.15.0 and is no longer available from 8.0.0. +The new {java-api-client}/index.html[Java API Client] should be used instead. diff --git a/docs/java-rest/redirects.asciidoc b/docs/java-rest/redirects.asciidoc deleted file mode 100644 index 37f331a87bce..000000000000 --- a/docs/java-rest/redirects.asciidoc +++ /dev/null @@ -1,57 +0,0 @@ -["appendix",role="exclude",id="redirects"] -= Deleted pages - -The following pages have moved or been deleted. - -[role="exclude",id="_data_frame_transform_apis"] -=== {transform-cap} APIs - -See <>. - -[role="exclude",id="java-rest-high-dataframe-get-data-frame-transform"] -=== Get {transform} API - -See <>. - -[role="exclude",id="java-rest-high-dataframe-get-data-frame-transform-stats"] -=== Get {transform} stats API - -See <>. - -[role="exclude",id="java-rest-high-dataframe-put-data-frame-transform"] -=== Put {transform} API - -See <>. - -[role="exclude",id="java-rest-high-dataframe-update-data-frame-transform"] -=== Update {transform} API - -See <>. - -[role="exclude",id="java-rest-high-dataframe-delete-data-frame-transform"] -=== Delete {transform} API - -See <>. - -[role="exclude",id="java-rest-high-dataframe-preview-data-frame-transform"] -=== Preview {transform} API - -See <>. - -[role="exclude",id="java-rest-high-dataframe-start-data-frame-transform"] -=== Start {transform} API - -See <>. - -[role="exclude",id="java-rest-high-dataframe-stop-data-frame-transform"] -=== Stop {transform} API - -See <>. - -[role="exclude",id="java-rest-high-freeze-index"] -=== Freeze index API - -The freeze index API was removed in 8.0. Frozen indices are no longer useful due -to -https://www.elastic.co/blog/significantly-decrease-your-elasticsearch-heap-memory-usage[recent -improvements in heap memory usage].