Check that client methods match API defined in the REST spec (#31825)

We have been encountering name mismatches between API defined in our
REST spec and method names that have been added to the high-level REST
client. We should check this automatically to prevent furher mismatches,
and correct all the current ones.

This commit adds a test for this and corrects the issues found by it.
This commit is contained in:
Luca Cavanna 2018-07-17 11:26:28 +02:00 committed by GitHub
parent 9e529d9d58
commit 049966a829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 359 additions and 86 deletions

View File

@ -24,7 +24,6 @@ import org.elasticsearch.gradle.VersionProperties
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.Transformer
import org.gradle.api.execution.TaskExecutionAdapter
import org.gradle.api.internal.tasks.options.Option
import org.gradle.api.provider.Property
@ -217,7 +216,7 @@ public class RestIntegTestTask extends DefaultTask {
* @param project The project to add the copy task to
* @param includePackagedTests true if the packaged tests should be copied, false otherwise
*/
private static Task createCopyRestSpecTask(Project project, Provider<Boolean> includePackagedTests) {
static Task createCopyRestSpecTask(Project project, Provider<Boolean> includePackagedTests) {
project.configurations {
restSpec
}

View File

@ -18,8 +18,8 @@
*/
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.gradle.api.XmlProvider
import org.gradle.api.publish.maven.MavenPublication
import org.elasticsearch.gradle.test.RestIntegTestTask
import org.gradle.api.internal.provider.Providers
buildscript {
repositories {
@ -41,6 +41,10 @@ apply plugin: 'com.github.johnrengelman.shadow'
group = 'org.elasticsearch.client'
archivesBaseName = 'elasticsearch-rest-high-level-client'
//we need to copy the yaml spec so we can check naming (see RestHighlevelClientTests#testApiNamingConventions)
Task copyRestSpec = RestIntegTestTask.createCopyRestSpecTask(project, Providers.FALSE)
test.dependsOn(copyRestSpec)
publishing {
publications {
nebula(MavenPublication) {
@ -102,6 +106,8 @@ dependencies {
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
testCompile "junit:junit:${versions.junit}"
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
//this is needed to make RestHighLevelClientTests#testApiNamingConventions work from IDEs
testCompile "org.elasticsearch:rest-api-spec:${version}"
}
dependencyLicenses {

View File

@ -174,7 +174,7 @@ public final class IndicesClient {
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetMappingsResponse getMappings(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
public GetMappingsResponse getMapping(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest, RequestConverters::getMappings, options,
GetMappingsResponse::fromXContent, emptySet());
}
@ -187,8 +187,8 @@ public final class IndicesClient {
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void getMappingsAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
ActionListener<GetMappingsResponse> listener) {
public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
ActionListener<GetMappingsResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest, RequestConverters::getMappings, options,
GetMappingsResponse::fromXContent, listener, emptySet());
}
@ -474,8 +474,23 @@ public final class IndicesClient {
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #forcemerge(ForceMergeRequest, RequestOptions)} instead
*/
@Deprecated
public ForceMergeResponse forceMerge(ForceMergeRequest forceMergeRequest, RequestOptions options) throws IOException {
return forcemerge(forceMergeRequest, options);
}
/**
* Force merge one or more indices using the Force Merge API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
* Force Merge API on elastic.co</a>
* @param forceMergeRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public ForceMergeResponse forcemerge(ForceMergeRequest forceMergeRequest, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(forceMergeRequest, RequestConverters::forceMerge, options,
ForceMergeResponse::fromXContent, emptySet());
}
@ -487,8 +502,22 @@ public final class IndicesClient {
* @param forceMergeRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @deprecated use {@link #forcemergeAsync(ForceMergeRequest, RequestOptions, ActionListener)} instead
*/
@Deprecated
public void forceMergeAsync(ForceMergeRequest forceMergeRequest, RequestOptions options, ActionListener<ForceMergeResponse> listener) {
forcemergeAsync(forceMergeRequest, options, listener);
}
/**
* Asynchronously force merge one or more indices using the Force Merge API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
* Force Merge API on elastic.co</a>
* @param forceMergeRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void forcemergeAsync(ForceMergeRequest forceMergeRequest, RequestOptions options, ActionListener<ForceMergeResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(forceMergeRequest, RequestConverters::forceMerge, options,
ForceMergeResponse::fromXContent, listener, emptySet());
}

View File

@ -139,7 +139,7 @@ public final class IngestClient {
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public SimulatePipelineResponse simulatePipeline(SimulatePipelineRequest request, RequestOptions options) throws IOException {
public SimulatePipelineResponse simulate(SimulatePipelineRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::simulatePipeline, options,
SimulatePipelineResponse::fromXContent, emptySet());
}
@ -154,9 +154,9 @@ public final class IngestClient {
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void simulatePipelineAsync(SimulatePipelineRequest request,
RequestOptions options,
ActionListener<SimulatePipelineResponse> listener) {
public void simulateAsync(SimulatePipelineRequest request,
RequestOptions options,
ActionListener<SimulatePipelineResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::simulatePipeline, options,
SimulatePipelineResponse::fromXContent, listener, emptySet());
}

View File

@ -384,8 +384,23 @@ public class RestHighLevelClient implements Closeable {
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #mget(MultiGetRequest, RequestOptions)} instead
*/
@Deprecated
public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, RequestOptions options) throws IOException {
return mget(multiGetRequest, options);
}
/**
* Retrieves multiple documents by id using the Multi Get API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
* @param multiGetRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public final MultiGetResponse mget(MultiGetRequest multiGetRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent,
singleton(404));
}
@ -396,8 +411,21 @@ public class RestHighLevelClient implements Closeable {
* @param multiGetRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @deprecated use {@link #mgetAsync(MultiGetRequest, RequestOptions, ActionListener)} instead
*/
@Deprecated
public final void multiGetAsync(MultiGetRequest multiGetRequest, RequestOptions options, ActionListener<MultiGetResponse> listener) {
mgetAsync(multiGetRequest, options, listener);
}
/**
* Asynchronously retrieves multiple documents by id using the Multi Get API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
* @param multiGetRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public final void mgetAsync(MultiGetRequest multiGetRequest, RequestOptions options, ActionListener<MultiGetResponse> listener) {
performRequestAsyncAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent, listener,
singleton(404));
}
@ -531,8 +559,23 @@ public class RestHighLevelClient implements Closeable {
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #msearch(MultiSearchRequest, RequestOptions)} instead
*/
@Deprecated
public final MultiSearchResponse multiSearch(MultiSearchRequest multiSearchRequest, RequestOptions options) throws IOException {
return msearch(multiSearchRequest, options);
}
/**
* Executes a multi search using the msearch API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
* elastic.co</a>
* @param multiSearchRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public final MultiSearchResponse msearch(MultiSearchRequest multiSearchRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(multiSearchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
emptySet());
}
@ -544,9 +587,24 @@ public class RestHighLevelClient implements Closeable {
* @param searchRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @deprecated use {@link #msearchAsync(MultiSearchRequest, RequestOptions, ActionListener)} instead
*/
@Deprecated
public final void multiSearchAsync(MultiSearchRequest searchRequest, RequestOptions options,
ActionListener<MultiSearchResponse> listener) {
ActionListener<MultiSearchResponse> listener) {
msearchAsync(searchRequest, options, listener);
}
/**
* Asynchronously executes a multi search using the msearch API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
* elastic.co</a>
* @param searchRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public final void msearchAsync(MultiSearchRequest searchRequest, RequestOptions options,
ActionListener<MultiSearchResponse> listener) {
performRequestAsyncAndParseEntity(searchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
listener, emptySet());
}
@ -559,8 +617,23 @@ public class RestHighLevelClient implements Closeable {
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #scroll(SearchScrollRequest, RequestOptions)} instead
*/
@Deprecated
public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
return scroll(searchScrollRequest, options);
}
/**
* Executes a search using the Search Scroll API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
* API on elastic.co</a>
* @param searchScrollRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public final SearchResponse scroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
emptySet());
}
@ -572,9 +645,24 @@ public class RestHighLevelClient implements Closeable {
* @param searchScrollRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @deprecated use {@link #scrollAsync(SearchScrollRequest, RequestOptions, ActionListener)} instead
*/
@Deprecated
public final void searchScrollAsync(SearchScrollRequest searchScrollRequest, RequestOptions options,
ActionListener<SearchResponse> listener) {
ActionListener<SearchResponse> listener) {
scrollAsync(searchScrollRequest, options, listener);
}
/**
* Asynchronously executes a search using the Search Scroll API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
* API on elastic.co</a>
* @param searchScrollRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public final void scrollAsync(SearchScrollRequest searchScrollRequest, RequestOptions options,
ActionListener<SearchResponse> listener) {
performRequestAsyncAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
listener, emptySet());
}
@ -691,8 +779,8 @@ public class RestHighLevelClient implements Closeable {
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-search-template.html">Multi Search Template API
* on elastic.co</a>.
*/
public final MultiSearchTemplateResponse multiSearchTemplate(MultiSearchTemplateRequest multiSearchTemplateRequest,
RequestOptions options) throws IOException {
public final MultiSearchTemplateResponse msearchTemplate(MultiSearchTemplateRequest multiSearchTemplateRequest,
RequestOptions options) throws IOException {
return performRequestAndParseEntity(multiSearchTemplateRequest, RequestConverters::multiSearchTemplate,
options, MultiSearchTemplateResponse::fromXContext, emptySet());
}
@ -703,9 +791,9 @@ public class RestHighLevelClient implements Closeable {
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-search-template.html">Multi Search Template API
* on elastic.co</a>.
*/
public final void multiSearchTemplateAsync(MultiSearchTemplateRequest multiSearchTemplateRequest,
RequestOptions options,
ActionListener<MultiSearchTemplateResponse> listener) {
public final void msearchTemplateAsync(MultiSearchTemplateRequest multiSearchTemplateRequest,
RequestOptions options,
ActionListener<MultiSearchTemplateResponse> listener) {
performRequestAsyncAndParseEntity(multiSearchTemplateRequest, RequestConverters::multiSearchTemplate,
options, MultiSearchTemplateResponse::fromXContext, listener, emptySet());
}

View File

@ -63,7 +63,7 @@ public final class SnapshotClient {
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetRepositoriesResponse getRepositories(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options)
public GetRepositoriesResponse getRepository(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options)
throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories, options,
GetRepositoriesResponse::fromXContent, emptySet());
@ -78,8 +78,8 @@ public final class SnapshotClient {
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void getRepositoriesAsync(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options,
ActionListener<GetRepositoriesResponse> listener) {
public void getRepositoryAsync(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options,
ActionListener<GetRepositoriesResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories, options,
GetRepositoriesResponse::fromXContent, listener, emptySet());
}

View File

@ -79,7 +79,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
assertThat(listener.afterCounts.get(), equalTo(1));
assertThat(listener.bulkFailures.size(), equalTo(0));
assertResponseItems(listener.bulkItems, numDocs);
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
}
}
@ -105,7 +105,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
assertThat(listener.afterCounts.get(), equalTo(1));
assertThat(listener.bulkFailures.size(), equalTo(0));
assertResponseItems(listener.bulkItems, numDocs);
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
}
}
@ -157,7 +157,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
assertThat(ids.add(bulkItemResponse.getId()), equalTo(true));
}
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
}
public void testBulkProcessorWaitOnClose() throws Exception {
@ -188,7 +188,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
}
assertThat(listener.bulkFailures.size(), equalTo(0));
assertResponseItems(listener.bulkItems, numDocs);
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
}
public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception {
@ -265,7 +265,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
}
}
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), testDocs);
assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), testDocs);
}
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) throws Exception {

View File

@ -129,7 +129,7 @@ public class BulkProcessorRetryIT extends ESRestHighLevelClientTestCase {
}
highLevelClient().indices().refresh(new RefreshRequest(), RequestOptions.DEFAULT);
int multiGetResponsesCount = highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT).getResponses().length;
int multiGetResponsesCount = highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT).getResponses().length;
if (rejectedExecutionExpected) {
assertThat(multiGetResponsesCount, lessThanOrEqualTo(numberOfAsyncOps));

View File

@ -253,7 +253,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.add("index", "type", "id1");
multiGetRequest.add("index", "type", "id2");
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::multiGet, highLevelClient()::multiGetAsync);
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::mget, highLevelClient()::mgetAsync);
assertEquals(2, response.getResponses().length);
assertTrue(response.getResponses()[0].isFailed());
@ -285,7 +285,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.add("index", "type", "id1");
multiGetRequest.add("index", "type", "id2");
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::multiGet, highLevelClient()::multiGetAsync);
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::mget, highLevelClient()::mgetAsync);
assertEquals(2, response.getResponses().length);
assertFalse(response.getResponses()[0].isFailed());

View File

@ -121,7 +121,7 @@ public class CustomRestHighLevelClientTests extends ESTestCase {
* so that they can be used by subclasses to implement custom logic.
*/
@SuppressForbidden(reason = "We're forced to uses Class#getDeclaredMethods() here because this test checks protected methods")
public void testMethodsVisibility() throws ClassNotFoundException {
public void testMethodsVisibility() {
final String[] methodNames = new String[]{"parseEntity",
"parseResponseException",
"performRequest",

View File

@ -443,7 +443,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
.types("_doc");
GetMappingsResponse getMappingsResponse =
execute(request, highLevelClient().indices()::getMappings, highLevelClient().indices()::getMappingsAsync);
execute(request, highLevelClient().indices()::getMapping, highLevelClient().indices()::getMappingAsync);
Map<String, Object> mappings = getMappingsResponse.getMappings().get(indexName).get("_doc").sourceAsMap();
Map<String, String> type = new HashMap<>();
@ -796,7 +796,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
createIndex(index, settings);
ForceMergeRequest forceMergeRequest = new ForceMergeRequest(index);
ForceMergeResponse forceMergeResponse =
execute(forceMergeRequest, highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync);
execute(forceMergeRequest, highLevelClient().indices()::forcemerge, highLevelClient().indices()::forcemergeAsync);
assertThat(forceMergeResponse.getTotalShards(), equalTo(1));
assertThat(forceMergeResponse.getSuccessfulShards(), equalTo(1));
assertThat(forceMergeResponse.getFailedShards(), equalTo(0));
@ -807,7 +807,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
assertFalse(indexExists(nonExistentIndex));
ForceMergeRequest forceMergeRequest = new ForceMergeRequest(nonExistentIndex);
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> execute(forceMergeRequest, highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync));
() -> execute(forceMergeRequest, highLevelClient().indices()::forcemerge, highLevelClient().indices()::forcemergeAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
}
}

View File

@ -135,7 +135,7 @@ public class IngestClientIT extends ESRestHighLevelClientTestCase {
);
request.setVerbose(isVerbose);
SimulatePipelineResponse response =
execute(request, highLevelClient().ingest()::simulatePipeline, highLevelClient().ingest()::simulatePipelineAsync);
execute(request, highLevelClient().ingest()::simulate, highLevelClient().ingest()::simulateAsync);
List<SimulateDocumentResult> results = response.getResults();
assertEquals(1, results.size());
if (isVerbose) {

View File

@ -20,8 +20,6 @@
package org.elasticsearch.client;
import com.fasterxml.jackson.core.JsonParseException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
@ -53,6 +51,7 @@ import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -73,20 +72,30 @@ import org.elasticsearch.search.aggregations.matrix.stats.MatrixStatsAggregation
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.InternalAggregationTestCase;
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi;
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;
import org.junit.Before;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.elasticsearch.client.RestClientTestUtil.randomHeaders;
import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
@ -137,7 +146,6 @@ public class RestHighLevelClientTests extends ESTestCase {
}
public void testInfo() throws IOException {
Header[] headers = randomHeaders(random(), "Header");
MainResponse testInfo = new MainResponse("nodeName", Version.CURRENT, new ClusterName("clusterName"), "clusterUuid",
Build.CURRENT);
mockResponse(testInfo);
@ -150,7 +158,7 @@ public class RestHighLevelClientTests extends ESTestCase {
null, false, false, null, 1), randomAlphaOfLengthBetween(5, 10), 5, 5, 0, 100, ShardSearchFailure.EMPTY_ARRAY,
SearchResponse.Clusters.EMPTY);
mockResponse(mockSearchResponse);
SearchResponse searchResponse = restHighLevelClient.searchScroll(
SearchResponse searchResponse = restHighLevelClient.scroll(
new SearchScrollRequest(randomAlphaOfLengthBetween(5, 10)), RequestOptions.DEFAULT);
assertEquals(mockSearchResponse.getScrollId(), searchResponse.getScrollId());
assertEquals(0, searchResponse.getHits().totalHits);
@ -632,6 +640,149 @@ public class RestHighLevelClientTests extends ESTestCase {
assertTrue(names.contains(DiscountedCumulativeGain.NAME));
}
public void testApiNamingConventions() throws Exception {
//this list should be empty once the high-level client is feature complete
String[] notYetSupportedApi = new String[]{
"cluster.remote_info",
"count",
"create",
"delete_by_query",
"exists_source",
"get_source",
"indices.delete_alias",
"indices.delete_template",
"indices.exists_template",
"indices.exists_type",
"indices.get_upgrade",
"indices.put_alias",
"mtermvectors",
"put_script",
"reindex",
"reindex_rethrottle",
"render_search_template",
"scripts_painless_execute",
"snapshot.restore",
"tasks.get",
"termvectors",
"update_by_query"
};
//These API are not required for high-level client feature completeness
String[] notRequiredApi = new String[] {
"cluster.allocation_explain",
"cluster.pending_tasks",
"cluster.reroute",
"cluster.state",
"cluster.stats",
"indices.shard_stores",
"indices.upgrade",
"indices.recovery",
"indices.segments",
"indices.stats",
"ingest.processor_grok",
"nodes.info",
"nodes.stats",
"nodes.hot_threads",
"nodes.usage",
"search_shards",
};
Set<String> deprecatedMethods = new HashSet<>();
deprecatedMethods.add("indices.force_merge");
deprecatedMethods.add("multi_get");
deprecatedMethods.add("multi_search");
deprecatedMethods.add("search_scroll");
ClientYamlSuiteRestSpec restSpec = ClientYamlSuiteRestSpec.load("/rest-api-spec/api");
Set<String> apiSpec = restSpec.getApis().stream().map(ClientYamlSuiteRestApi::getName).collect(Collectors.toSet());
Set<String> topLevelMethodsExclusions = new HashSet<>();
topLevelMethodsExclusions.add("getLowLevelClient");
topLevelMethodsExclusions.add("close");
Map<String, Method> methods = Arrays.stream(RestHighLevelClient.class.getMethods())
.filter(method -> method.getDeclaringClass().equals(RestHighLevelClient.class)
&& topLevelMethodsExclusions.contains(method.getName()) == false)
.map(method -> Tuple.tuple(toSnakeCase(method.getName()), method))
.flatMap(tuple -> tuple.v2().getReturnType().getName().endsWith("Client")
? getSubClientMethods(tuple.v1(), tuple.v2().getReturnType()) : Stream.of(tuple))
.collect(Collectors.toMap(Tuple::v1, Tuple::v2));
Set<String> apiNotFound = new HashSet<>();
for (Map.Entry<String, Method> entry : methods.entrySet()) {
Method method = entry.getValue();
String apiName = entry.getKey();
assertTrue("method [" + apiName + "] is not final",
Modifier.isFinal(method.getClass().getModifiers()) || Modifier.isFinal(method.getModifiers()));
assertTrue(Modifier.isPublic(method.getModifiers()));
//we convert all the method names to snake case, hence we need to look for the '_async' suffix rather than 'Async'
if (apiName.endsWith("_async")) {
assertTrue("async method [" + method.getName() + "] doesn't have corresponding sync method",
methods.containsKey(apiName.substring(0, apiName.length() - 6)));
assertThat(method.getReturnType(), equalTo(Void.TYPE));
assertEquals(0, method.getExceptionTypes().length);
assertEquals(3, method.getParameterTypes().length);
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
assertThat(method.getParameterTypes()[1].getName(), equalTo(RequestOptions.class.getName()));
assertThat(method.getParameterTypes()[2].getName(), equalTo(ActionListener.class.getName()));
} else {
//A few methods return a boolean rather than a response object
if (apiName.equals("ping") || apiName.contains("exist")) {
assertThat(method.getReturnType().getSimpleName(), equalTo("boolean"));
} else {
assertThat(method.getReturnType().getSimpleName(), endsWith("Response"));
}
assertEquals(1, method.getExceptionTypes().length);
//a few methods don't accept a request object as argument
if (apiName.equals("ping") || apiName.equals("info")) {
assertEquals(1, method.getParameterTypes().length);
assertThat(method.getParameterTypes()[0].getName(), equalTo(RequestOptions.class.getName()));
} else {
assertEquals(apiName, 2, method.getParameterTypes().length);
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
assertThat(method.getParameterTypes()[1].getName(), equalTo(RequestOptions.class.getName()));
}
boolean remove = apiSpec.remove(apiName);
if (remove == false && deprecatedMethods.contains(apiName) == false) {
//TODO xpack api are currently ignored, we need to load xpack yaml spec too
if (apiName.startsWith("xpack.") == false) {
apiNotFound.add(apiName);
}
}
}
}
assertThat("Some client method doesn't match a corresponding API defined in the REST spec: " + apiNotFound,
apiNotFound.size(), equalTo(0));
//we decided not to support cat API in the high-level REST client, they are supposed to be used from a low-level client
apiSpec.removeIf(api -> api.startsWith("cat."));
Stream.concat(Arrays.stream(notYetSupportedApi), Arrays.stream(notRequiredApi)).forEach(
api -> assertTrue(api + " API is either not defined in the spec or already supported by the high-level client",
apiSpec.remove(api)));
assertThat("Some API are not supported but they should be: " + apiSpec, apiSpec.size(), equalTo(0));
}
private static Stream<Tuple<String, Method>> getSubClientMethods(String namespace, Class<?> clientClass) {
return Arrays.stream(clientClass.getMethods()).filter(method -> method.getDeclaringClass().equals(clientClass))
.map(method -> Tuple.tuple(namespace + "." + toSnakeCase(method.getName()), method));
}
private static String toSnakeCase(String camelCase) {
StringBuilder snakeCaseString = new StringBuilder();
for (Character aChar : camelCase.toCharArray()) {
if (Character.isUpperCase(aChar)) {
snakeCaseString.append('_');
snakeCaseString.append(Character.toLowerCase(aChar));
} else {
snakeCaseString.append(aChar);
}
}
return snakeCaseString.toString();
}
private static class TrackingActionListener implements ActionListener<Integer> {
private final AtomicInteger statusCode = new AtomicInteger(-1);
private final AtomicReference<Exception> exception = new AtomicReference<>();

View File

@ -597,7 +597,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
}
searchResponse = execute(new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2)),
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync);
highLevelClient()::scroll, highLevelClient()::scrollAsync);
assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
assertThat(searchResponse.getHits().getHits().length, equalTo(35));
@ -606,7 +606,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
}
searchResponse = execute(new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2)),
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync);
highLevelClient()::scroll, highLevelClient()::scrollAsync);
assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
assertThat(searchResponse.getHits().getHits().length, equalTo(30));
@ -623,7 +623,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
SearchScrollRequest scrollRequest = new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2));
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> execute(scrollRequest,
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync));
highLevelClient()::scroll, highLevelClient()::scrollAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
assertThat(exception.getRootCause(), instanceOf(ElasticsearchException.class));
ElasticsearchException rootCause = (ElasticsearchException) exception.getRootCause();
@ -644,7 +644,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
multiSearchRequest.add(searchRequest3);
MultiSearchResponse multiSearchResponse =
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
execute(multiSearchRequest, highLevelClient()::msearch, highLevelClient()::msearchAsync);
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(3));
@ -686,7 +686,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
multiSearchRequest.add(searchRequest3);
MultiSearchResponse multiSearchResponse =
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
execute(multiSearchRequest, highLevelClient()::msearch, highLevelClient()::msearchAsync);
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(3));
@ -734,7 +734,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
multiSearchRequest.add(searchRequest3);
MultiSearchResponse multiSearchResponse =
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
execute(multiSearchRequest, highLevelClient()::msearch, highLevelClient()::msearchAsync);
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(3));
@ -759,7 +759,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
searchRequest1.source().highlighter(new HighlightBuilder().field("field"));
searchRequest2.source().highlighter(new HighlightBuilder().field("field"));
searchRequest3.source().highlighter(new HighlightBuilder().field("field"));
multiSearchResponse = execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
multiSearchResponse = execute(multiSearchRequest, highLevelClient()::msearch, highLevelClient()::msearchAsync);
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(3));
@ -797,7 +797,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
multiSearchRequest.add(searchRequest2);
MultiSearchResponse multiSearchResponse =
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
execute(multiSearchRequest, highLevelClient()::msearch, highLevelClient()::msearchAsync);
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(2));
@ -941,8 +941,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
multiSearchTemplateRequest.add(badRequest);
MultiSearchTemplateResponse multiSearchTemplateResponse =
execute(multiSearchTemplateRequest, highLevelClient()::multiSearchTemplate,
highLevelClient()::multiSearchTemplateAsync);
execute(multiSearchTemplateRequest, highLevelClient()::msearchTemplate,
highLevelClient()::msearchTemplateAsync);
Item[] responses = multiSearchTemplateResponse.getResponses();
@ -999,8 +999,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
// The whole HTTP request should fail if no nested search requests are valid
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class,
() -> execute(multiSearchTemplateRequest, highLevelClient()::multiSearchTemplate,
highLevelClient()::multiSearchTemplateAsync));
() -> execute(multiSearchTemplateRequest, highLevelClient()::msearchTemplate,
highLevelClient()::msearchTemplateAsync));
assertEquals(RestStatus.BAD_REQUEST, exception.status());
assertThat(exception.getMessage(), containsString("no requests added"));

View File

@ -77,8 +77,8 @@ public class SnapshotIT extends ESRestHighLevelClientTestCase {
GetRepositoriesRequest request = new GetRepositoriesRequest();
request.repositories(new String[]{testRepository});
GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepositories,
highLevelClient().snapshot()::getRepositoriesAsync);
GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepository,
highLevelClient().snapshot()::getRepositoryAsync);
assertThat(1, equalTo(response.repositories().size()));
}
@ -86,8 +86,8 @@ public class SnapshotIT extends ESRestHighLevelClientTestCase {
assertTrue(createTestRepository("other", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
assertTrue(createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
GetRepositoriesResponse response = execute(new GetRepositoriesRequest(), highLevelClient().snapshot()::getRepositories,
highLevelClient().snapshot()::getRepositoriesAsync);
GetRepositoriesResponse response = execute(new GetRepositoriesRequest(), highLevelClient().snapshot()::getRepository,
highLevelClient().snapshot()::getRepositoryAsync);
assertThat(2, equalTo(response.repositories().size()));
}
@ -95,7 +95,7 @@ public class SnapshotIT extends ESRestHighLevelClientTestCase {
String repository = "doesnotexist";
GetRepositoriesRequest request = new GetRepositoriesRequest(new String[]{repository});
ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(request,
highLevelClient().snapshot()::getRepositories, highLevelClient().snapshot()::getRepositoriesAsync));
highLevelClient().snapshot()::getRepository, highLevelClient().snapshot()::getRepositoryAsync));
assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND));
assertThat(exception.getMessage(), equalTo(
@ -107,8 +107,8 @@ public class SnapshotIT extends ESRestHighLevelClientTestCase {
assertTrue(createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
GetRepositoriesRequest request = new GetRepositoriesRequest();
GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepositories,
highLevelClient().snapshot()::getRepositoriesAsync);
GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepository,
highLevelClient().snapshot()::getRepositoryAsync);
assertThat(1, equalTo(response.repositories().size()));
DeleteRepositoryRequest deleteRequest = new DeleteRepositoryRequest(repository);

View File

@ -1121,7 +1121,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
// end::multi-get-request-top-level-extras
// tag::multi-get-execute
MultiGetResponse response = client.multiGet(request, RequestOptions.DEFAULT);
MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
// end::multi-get-execute
// tag::multi-get-response
@ -1174,7 +1174,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
listener = new LatchedActionListener<>(listener, latch);
// tag::multi-get-execute-async
client.multiGetAsync(request, RequestOptions.DEFAULT, listener); // <1>
client.mgetAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::multi-get-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
@ -1185,7 +1185,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
request.add(new MultiGetRequest.Item("index", "type", "example_id")
.fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE)); // <1>
// end::multi-get-request-no-source
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request, RequestOptions.DEFAULT));
MultiGetItemResponse item = unwrapAndAssertExample(client.mget(request, RequestOptions.DEFAULT));
assertNull(item.getResponse().getSource());
}
{
@ -1198,7 +1198,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
request.add(new MultiGetRequest.Item("index", "type", "example_id")
.fetchSourceContext(fetchSourceContext)); // <1>
// end::multi-get-request-source-include
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request, RequestOptions.DEFAULT));
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")));
@ -1213,7 +1213,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
request.add(new MultiGetRequest.Item("index", "type", "example_id")
.fetchSourceContext(fetchSourceContext)); // <1>
// end::multi-get-request-source-exclude
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request, RequestOptions.DEFAULT));
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"));
@ -1223,7 +1223,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
// tag::multi-get-request-stored
request.add(new MultiGetRequest.Item("index", "type", "example_id")
.storedFields("foo")); // <1>
MultiGetResponse response = client.multiGet(request, RequestOptions.DEFAULT);
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
@ -1235,7 +1235,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
MultiGetRequest request = new MultiGetRequest();
request.add(new MultiGetRequest.Item("index", "type", "example_id")
.version(1000L));
MultiGetResponse response = client.multiGet(request, RequestOptions.DEFAULT);
MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
MultiGetItemResponse item = response.getResponses()[0];
assertNull(item.getResponse()); // <1>
Exception e = item.getFailure().getFailure(); // <2>

View File

@ -622,7 +622,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// end::get-mapping-request-indicesOptions
// tag::get-mapping-execute
GetMappingsResponse getMappingResponse = client.indices().getMappings(request, RequestOptions.DEFAULT);
GetMappingsResponse getMappingResponse = client.indices().getMapping(request, RequestOptions.DEFAULT);
// end::get-mapping-execute
// tag::get-mapping-response
@ -704,7 +704,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
});
// tag::get-mapping-execute-async
client.indices().getMappingsAsync(request, RequestOptions.DEFAULT, listener); // <1>
client.indices().getMappingAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::get-mapping-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
@ -1344,7 +1344,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// end::force-merge-request-flush
// tag::force-merge-execute
ForceMergeResponse forceMergeResponse = client.indices().forceMerge(request, RequestOptions.DEFAULT);
ForceMergeResponse forceMergeResponse = client.indices().forcemerge(request, RequestOptions.DEFAULT);
// end::force-merge-execute
// tag::force-merge-response
@ -1369,14 +1369,14 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// end::force-merge-execute-listener
// tag::force-merge-execute-async
client.indices().forceMergeAsync(request, RequestOptions.DEFAULT, listener); // <1>
client.indices().forcemergeAsync(request, RequestOptions.DEFAULT, 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);
client.indices().forcemerge(request, RequestOptions.DEFAULT);
} catch (ElasticsearchException exception) {
if (exception.status() == RestStatus.NOT_FOUND) {
// <1>

View File

@ -317,7 +317,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
// end::simulate-pipeline-request-verbose
// tag::simulate-pipeline-execute
SimulatePipelineResponse response = client.ingest().simulatePipeline(request, RequestOptions.DEFAULT); // <1>
SimulatePipelineResponse response = client.ingest().simulate(request, RequestOptions.DEFAULT); // <1>
// end::simulate-pipeline-execute
// tag::simulate-pipeline-response
@ -381,7 +381,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
listener = new LatchedActionListener<>(listener, latch);
// tag::simulate-pipeline-execute-async
client.ingest().simulatePipelineAsync(request, RequestOptions.DEFAULT, listener); // <1>
client.ingest().simulateAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::simulate-pipeline-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));

View File

@ -583,7 +583,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
// tag::search-scroll2
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <1>
scrollRequest.scroll(TimeValue.timeValueSeconds(30));
SearchResponse searchScrollResponse = client.searchScroll(scrollRequest, RequestOptions.DEFAULT);
SearchResponse searchScrollResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT);
scrollId = searchScrollResponse.getScrollId(); // <2>
hits = searchScrollResponse.getHits(); // <3>
assertEquals(3, hits.getTotalHits());
@ -612,7 +612,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
// end::scroll-request-arguments
// tag::search-scroll-execute-sync
SearchResponse searchResponse = client.searchScroll(scrollRequest, RequestOptions.DEFAULT);
SearchResponse searchResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT);
// end::search-scroll-execute-sync
assertEquals(0, searchResponse.getFailedShards());
@ -638,7 +638,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
scrollListener = new LatchedActionListener<>(scrollListener, latch);
// tag::search-scroll-execute-async
client.searchScrollAsync(scrollRequest, RequestOptions.DEFAULT, scrollListener); // <1>
client.scrollAsync(scrollRequest, RequestOptions.DEFAULT, scrollListener); // <1>
// end::search-scroll-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
@ -710,7 +710,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
while (searchHits != null && searchHits.length > 0) { // <2>
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <3>
scrollRequest.scroll(scroll);
searchResponse = client.searchScroll(scrollRequest, RequestOptions.DEFAULT);
searchResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT);
scrollId = searchResponse.getScrollId();
searchHits = searchResponse.getHits().getHits();
// <4>
@ -861,7 +861,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
// end::multi-search-template-request-inline
// tag::multi-search-template-request-sync
MultiSearchTemplateResponse multiResponse = client.multiSearchTemplate(multiRequest, RequestOptions.DEFAULT);
MultiSearchTemplateResponse multiResponse = client.msearchTemplate(multiRequest, RequestOptions.DEFAULT);
// end::multi-search-template-request-sync
// tag::multi-search-template-response
@ -916,7 +916,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
// tag::multi-search-template-execute
MultiSearchTemplateResponse multiResponse = client.multiSearchTemplate(multiRequest, RequestOptions.DEFAULT);
MultiSearchTemplateResponse multiResponse = client.msearchTemplate(multiRequest, RequestOptions.DEFAULT);
// end::multi-search-template-execute
assertNotNull(multiResponse);
@ -944,7 +944,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
listener = new LatchedActionListener<>(listener, latch);
// tag::multi-search-template-execute-async
client.multiSearchTemplateAsync(multiRequest, RequestOptions.DEFAULT, listener);
client.msearchTemplateAsync(multiRequest, RequestOptions.DEFAULT, listener);
// end::multi-search-template-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
@ -1201,7 +1201,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
request.add(secondSearchRequest);
// end::multi-search-request-basic
// tag::multi-search-execute
MultiSearchResponse response = client.multiSearch(request, RequestOptions.DEFAULT);
MultiSearchResponse response = client.msearch(request, RequestOptions.DEFAULT);
// end::multi-search-execute
// tag::multi-search-response
MultiSearchResponse.Item firstResponse = response.getResponses()[0]; // <1>
@ -1233,7 +1233,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
listener = new LatchedActionListener<>(listener, latch);
// tag::multi-search-execute-async
client.multiSearchAsync(request, RequestOptions.DEFAULT, listener); // <1>
client.msearchAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::multi-search-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
@ -1244,7 +1244,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
request.add(new SearchRequest("posts") // <1>
.types("doc")); // <2>
// end::multi-search-request-index
MultiSearchResponse response = client.multiSearch(request, RequestOptions.DEFAULT);
MultiSearchResponse response = client.msearch(request, RequestOptions.DEFAULT);
MultiSearchResponse.Item firstResponse = response.getResponses()[0];
assertNull(firstResponse.getFailure());
SearchResponse searchResponse = firstResponse.getResponse();

View File

@ -221,7 +221,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
// end::get-repository-request-masterTimeout
// tag::get-repository-execute
GetRepositoriesResponse response = client.snapshot().getRepositories(request, RequestOptions.DEFAULT);
GetRepositoriesResponse response = client.snapshot().getRepository(request, RequestOptions.DEFAULT);
// end::get-repository-execute
// tag::get-repository-response
@ -256,7 +256,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
listener = new LatchedActionListener<>(listener, latch);
// tag::get-repository-execute-async
client.snapshot().getRepositoriesAsync(request, RequestOptions.DEFAULT, listener); // <1>
client.snapshot().getRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::get-repository-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));

View File

@ -171,7 +171,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase {
assertEquals(10, response.getHits().totalHits);
assertEquals(10, response.getHits().getHits().length);
String scrollId = response.getScrollId();
SearchResponse scrollResponse = restHighLevelClient.searchScroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT);
SearchResponse scrollResponse = restHighLevelClient.scroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT);
assertSame(SearchResponse.Clusters.EMPTY, scrollResponse.getClusters());
assertEquals(10, scrollResponse.getHits().totalHits);
assertEquals(0, scrollResponse.getHits().getHits().length);
@ -206,7 +206,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase {
assertEquals(10, response.getHits().totalHits);
assertEquals(10, response.getHits().getHits().length);
String scrollId = response.getScrollId();
SearchResponse scrollResponse = restHighLevelClient.searchScroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT);
SearchResponse scrollResponse = restHighLevelClient.scroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT);
assertSame(SearchResponse.Clusters.EMPTY, scrollResponse.getClusters());
assertEquals(10, scrollResponse.getHits().totalHits);
assertEquals(0, scrollResponse.getHits().getHits().length);