diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java index a5a57e4d6b8fa..584bdad745026 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java @@ -61,6 +61,8 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; 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.UnfreezeIndexRequest; import org.elasticsearch.client.indices.rollover.RolloverRequest; import org.elasticsearch.client.indices.rollover.RolloverResponse; @@ -1328,4 +1330,28 @@ public void deleteTemplateAsync(DeleteIndexTemplateRequest request, RequestOptio restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::deleteTemplate, options, AcknowledgedResponse::fromXContent, listener, emptySet()); } + + /** + * Synchronously calls the _reload_search_analyzers API + * + * @param request the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + */ + public ReloadAnalyzersResponse reloadAnalyzers(ReloadAnalyzersRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, IndicesRequestConverters::reloadAnalyzers, options, + ReloadAnalyzersResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously calls the _reload_search_analyzers API + * + * @param request 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 reloadAnalyzersAsync(ReloadAnalyzersRequest request, RequestOptions options, + ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::reloadAnalyzers, options, + ReloadAnalyzersResponse::fromXContent, listener, emptySet()); + } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java index 1e7e810a91b8f..7de53510b5080 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java @@ -50,6 +50,7 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; +import org.elasticsearch.client.indices.ReloadAnalyzersRequest; import org.elasticsearch.client.indices.UnfreezeIndexRequest; import org.elasticsearch.client.indices.rollover.RolloverRequest; import org.elasticsearch.common.Strings; @@ -644,4 +645,13 @@ static Request deleteTemplate(DeleteIndexTemplateRequest deleteIndexTemplateRequ request.addParameters(params.asMap()); return request; } + + static Request reloadAnalyzers(ReloadAnalyzersRequest reloadAnalyzersRequest) { + String endpoint = RequestConverters.endpoint(reloadAnalyzersRequest.getIndices(), "_reload_search_analyzers"); + Request request = new Request(HttpPost.METHOD_NAME, endpoint); + RequestConverters.Params parameters = new RequestConverters.Params(); + parameters.withIndicesOptions(reloadAnalyzersRequest.indicesOptions()); + request.addParameters(parameters.asMap()); + return request; + } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/BroadcastResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/BroadcastResponse.java index 3665ba5bf5009..35ce0f55d717b 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/BroadcastResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/BroadcastResponse.java @@ -45,7 +45,7 @@ public Shards shards() { return shards; } - BroadcastResponse(final Shards shards) { + protected BroadcastResponse(final Shards shards) { this.shards = Objects.requireNonNull(shards); } @@ -56,7 +56,7 @@ public Shards shards() { a -> new BroadcastResponse((Shards) a[0])); static { - PARSER.declareObject(ConstructingObjectParser.constructorArg(), Shards.SHARDS_PARSER, SHARDS_FIELD); + declareShardsField(PARSER); } /** @@ -70,6 +70,10 @@ public static BroadcastResponse fromXContent(final XContentParser parser) throws return PARSER.parse(parser, null); } + protected static void declareShardsField(ConstructingObjectParser PARSER) { + PARSER.declareObject(ConstructingObjectParser.constructorArg(), Shards.SHARDS_PARSER, SHARDS_FIELD); + } + /** * Represents the results of a collection of shards on which a request was executed against. */ diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersRequest.java new file mode 100644 index 0000000000000..e815d91bbe8f5 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersRequest.java @@ -0,0 +1,68 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.indices; + +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.client.Validatable; + +import java.util.Objects; + +/** + * Request for the _reload_search_analyzers API + */ +public final class ReloadAnalyzersRequest implements Validatable { + + private final String[] indices; + private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); + + /** + * Creates a new reload analyzers request + * @param indices the index for which to reload analyzers + */ + public ReloadAnalyzersRequest(String... indices) { + this.indices = Objects.requireNonNull(indices); + } + + /** + * Returns the indices + */ + public String[] getIndices() { + return indices; + } + + /** + * Specifies what type of requested indices to ignore and how to deal with wildcard expressions. + * For example indices that don't exist. + * + * @return the current behaviour when it comes to index names and wildcard indices expressions + */ + public IndicesOptions indicesOptions() { + return indicesOptions; + } + + /** + * Specifies what type of requested indices to ignore and how to deal with wildcard expressions. + * For example indices that don't exist. + * + * @param indicesOptions the desired behaviour regarding indices to ignore and wildcard indices expressions + */ + public void setIndicesOptions(IndicesOptions indicesOptions) { + this.indicesOptions = indicesOptions; + } +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersResponse.java new file mode 100644 index 0000000000000..e2c39d0a7aeba --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersResponse.java @@ -0,0 +1,108 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.indices; + +import org.elasticsearch.client.core.BroadcastResponse; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.XContentParser; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; + +/** + * The response object that will be returned when reloading analyzers + */ +public class ReloadAnalyzersResponse extends BroadcastResponse { + + private final Map reloadDetails; + + ReloadAnalyzersResponse(final Shards shards, Map reloadDetails) { + super(shards); + this.reloadDetails = reloadDetails; + } + + @SuppressWarnings({ "unchecked" }) + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("reload_analyzer", + true, arg -> { + Shards shards = (Shards) arg[0]; + List> results = (List>) arg[1]; + Map reloadDetails = new HashMap<>(); + for (Tuple result : results) { + reloadDetails.put(result.v1(), result.v2()); + } + return new ReloadAnalyzersResponse(shards, reloadDetails); + }); + + @SuppressWarnings({ "unchecked" }) + private static final ConstructingObjectParser, Void> ENTRY_PARSER = new ConstructingObjectParser<>( + "reload_analyzer.entry", true, arg -> { + String index = (String) arg[0]; + Set nodeIds = new HashSet<>((List) arg[1]); + Set analyzers = new HashSet<>((List) arg[2]); + return new Tuple<>(index, new ReloadDetails(index, nodeIds, analyzers)); + }); + + static { + declareShardsField(PARSER); + PARSER.declareObjectArray(constructorArg(), ENTRY_PARSER, new ParseField("reload_details")); + ENTRY_PARSER.declareString(constructorArg(), new ParseField("index")); + ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_node_ids")); + ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_analyzers")); + } + + public static ReloadAnalyzersResponse fromXContent(XContentParser parser) { + return PARSER.apply(parser, null); + } + + public Map getReloadedDetails() { + return reloadDetails; + } + + public static class ReloadDetails { + + private final String indexName; + private final Set reloadedIndicesNodes; + private final Set reloadedAnalyzers; + + public ReloadDetails(String name, Set reloadedIndicesNodes, Set reloadedAnalyzers) { + this.indexName = name; + this.reloadedIndicesNodes = reloadedIndicesNodes; + this.reloadedAnalyzers = reloadedAnalyzers; + } + + public String getIndexName() { + return indexName; + } + + public Set getReloadedIndicesNodes() { + return reloadedIndicesNodes; + } + + public Set getReloadedAnalyzers() { + return reloadedAnalyzers; + } + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 458e6371010b0..59d76142566e6 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -73,6 +73,8 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; 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.UnfreezeIndexRequest; import org.elasticsearch.client.indices.rollover.RolloverRequest; import org.elasticsearch.client.indices.rollover.RolloverResponse; @@ -1877,4 +1879,14 @@ public void testFreezeAndUnfreeze() throws IOException { assertTrue(unfreeze.isShardsAcknowledged()); assertTrue(unfreeze.isAcknowledged()); } + + public void testReloadAnalyzer() throws IOException { + createIndex("test", Settings.EMPTY); + RestHighLevelClient client = highLevelClient(); + + ReloadAnalyzersResponse reloadResponse = execute(new ReloadAnalyzersRequest("test"), client.indices()::reloadAnalyzers, + client.indices()::reloadAnalyzersAsync); + assertNotNull(reloadResponse.shards()); + assertTrue(reloadResponse.getReloadedDetails().containsKey("test")); + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java index 8f52dd7b00b6a..d0f4177635797 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java @@ -54,6 +54,7 @@ import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.client.indices.RandomCreateIndexGenerator; +import org.elasticsearch.client.indices.ReloadAnalyzersRequest; import org.elasticsearch.client.indices.rollover.RolloverRequest; import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.Strings; @@ -1215,4 +1216,21 @@ public void testDeleteTemplateRequest() { Assert.assertThat(request.getParameters(), equalTo(expectedParams)); Assert.assertThat(request.getEntity(), nullValue()); } + + public void testReloadAnalyzers() { + String[] indices = RequestConvertersTests.randomIndicesNames(1, 5); + StringJoiner endpoint = new StringJoiner("/", "/", ""); + if (indices != null && indices.length > 0) { + endpoint.add(String.join(",", indices)); + } + ReloadAnalyzersRequest reloadRequest = new ReloadAnalyzersRequest(indices); + Map expectedParams = new HashMap<>(); + RequestConvertersTests.setRandomIndicesOptions(reloadRequest::setIndicesOptions, reloadRequest::indicesOptions, + expectedParams); + Request request = IndicesRequestConverters.reloadAnalyzers(reloadRequest); + Assert.assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); + Assert.assertThat(request.getEndpoint(), equalTo(endpoint + "/_reload_search_analyzers")); + Assert.assertThat(request.getParameters(), equalTo(expectedParams)); + Assert.assertThat(request.getEntity(), nullValue()); + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 650bf2e440321..a5650f3130c3b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -824,6 +824,7 @@ public void testApiNamingConventions() throws Exception { apiName.startsWith("ccr.") == false && apiName.startsWith("data_frame") == false && apiName.endsWith("freeze") == false && + apiName.endsWith("reload_analyzers") == false && // IndicesClientIT.getIndexTemplate should be renamed "getTemplate" in version 8.0 when we // can get rid of 7.0's deprecated "getTemplate" apiName.equals("indices.get_index_template") == false) { 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 index 8e0a3d2fd005b..f878f0f6f7d88 100644 --- 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 @@ -58,6 +58,7 @@ import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.SyncedFlushResponse; +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; @@ -77,6 +78,9 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; 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.UnfreezeIndexRequest; import org.elasticsearch.client.indices.rollover.RolloverRequest; import org.elasticsearch.client.indices.rollover.RolloverResponse; @@ -2748,4 +2752,77 @@ public void onFailure(Exception e) { 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 + } + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/ReloadAnalyzersResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/ReloadAnalyzersResponseTests.java new file mode 100644 index 0000000000000..6719e10808e42 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/ReloadAnalyzersResponseTests.java @@ -0,0 +1,111 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.indices; + +import org.elasticsearch.action.support.DefaultShardOperationFailedException; +import org.elasticsearch.client.AbstractResponseTestCase; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.seqno.RetentionLeaseNotFoundException; +import org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse.ReloadDetails; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.isIn; + +public class ReloadAnalyzersResponseTests + extends AbstractResponseTestCase { + + private String index; + private String id; + private Set shardIds; + + @Override + protected org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse createServerTestInstance() { + index = randomAlphaOfLength(8); + id = randomAlphaOfLength(8); + final int total = randomIntBetween(1, 16); + final int successful = total - scaledRandomIntBetween(0, total); + final int failed = scaledRandomIntBetween(0, total - successful); + final List failures = new ArrayList<>(); + shardIds = new HashSet<>(); + for (int i = 0; i < failed; i++) { + final DefaultShardOperationFailedException failure = new DefaultShardOperationFailedException( + index, + randomValueOtherThanMany(shardIds::contains, () -> randomIntBetween(0, total - 1)), + new RetentionLeaseNotFoundException(id)); + failures.add(failure); + shardIds.add(failure.shardId()); + } + Map reloadedDetailsMap = new HashMap<>(); + int randomIndices = randomIntBetween(0, 5); + for (int i = 0; i < randomIndices; i++) { + String indexName = randomAlphaOfLengthBetween(5, 10); + Set randomNodeIds = new HashSet<>(Arrays.asList(generateRandomStringArray(5, 5, false, true))); + Set randomAnalyzers = new HashSet<>(Arrays.asList(generateRandomStringArray(5, 5, false, true))); + + ReloadDetails reloadedDetails = new ReloadDetails(indexName, randomNodeIds, randomAnalyzers); + reloadedDetailsMap.put(indexName, reloadedDetails); + } + return new org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse(total, successful, failed, failures, reloadedDetailsMap); + } + + @Override + protected ReloadAnalyzersResponse doParseToClientInstance(XContentParser parser) throws IOException { + return ReloadAnalyzersResponse.fromXContent(parser); + } + + @Override + protected void assertInstances(org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse serverTestInstance, + ReloadAnalyzersResponse clientInstance) { + assertThat(clientInstance.shards().total(), equalTo(serverTestInstance.getTotalShards())); + assertThat(clientInstance.shards().successful(), equalTo(serverTestInstance.getSuccessfulShards())); + assertThat(clientInstance.shards().skipped(), equalTo(0)); + assertThat(clientInstance.shards().failed(), equalTo(serverTestInstance.getFailedShards())); + assertThat(clientInstance.shards().failures(), hasSize(clientInstance.shards().failed() == 0 ? 0 : 1)); // failures are grouped + if (clientInstance.shards().failed() > 0) { + final DefaultShardOperationFailedException groupedFailure = clientInstance.shards().failures().iterator().next(); + assertThat(groupedFailure.index(), equalTo(index)); + assertThat(groupedFailure.shardId(), isIn(shardIds)); + assertThat(groupedFailure.reason(), containsString("reason=retention lease with ID [" + id + "] not found")); + } + Map serverDetails = serverTestInstance.getReloadDetails(); + assertThat(clientInstance.getReloadedDetails().size(), equalTo(serverDetails.size())); + for (Entry entry : clientInstance + .getReloadedDetails().entrySet()) { + String indexName = entry.getKey(); + assertTrue(serverDetails.keySet().contains(indexName)); + assertEquals(serverDetails.get(indexName).getIndexName(), entry.getValue().getIndexName()); + assertEquals(serverDetails.get(indexName).getReloadedAnalyzers(), entry.getValue().getReloadedAnalyzers()); + assertEquals(serverDetails.get(indexName).getReloadedIndicesNodes(), entry.getValue().getReloadedIndicesNodes()); + } + } + +} diff --git a/docs/java-rest/high-level/indices/reload_analyzers.asciidoc b/docs/java-rest/high-level/indices/reload_analyzers.asciidoc new file mode 100644 index 0000000000000..29db206bf1402 --- /dev/null +++ b/docs/java-rest/high-level/indices/reload_analyzers.asciidoc @@ -0,0 +1,50 @@ +-- +: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/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 21ebdfab65155..88f21944156ea 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -155,6 +155,7 @@ 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[] == Cluster APIs diff --git a/docs/reference/indices/apis/reload-analyzers.asciidoc b/docs/reference/indices/apis/reload-analyzers.asciidoc index 59300867c2c32..657f6556df4b2 100644 --- a/docs/reference/indices/apis/reload-analyzers.asciidoc +++ b/docs/reference/indices/apis/reload-analyzers.asciidoc @@ -99,3 +99,7 @@ analyzers that were reloaded: // TESTRESPONSE[s/"total" : 2/"total" : $body._shards.total/] // TESTRESPONSE[s/"successful" : 2/"successful" : $body._shards.successful/] // TESTRESPONSE[s/mfdqTXn_T7SGr2Ho2KT8uw/$body.reload_details.0.reloaded_node_ids.0/] + +NOTE: Reloading does not happen on each shard of an index, but once on each node +the index has shards on. The total shard count can therefore differ from the number +of index shards. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java index ca6c93b34c402..b996c98bb5843 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java @@ -105,7 +105,7 @@ public static class ReloadDetails { private final Set reloadedIndicesNodes; private final Set reloadedAnalyzers; - ReloadDetails(String name, Set reloadedIndicesNodes, Set reloadedAnalyzers) { + public ReloadDetails(String name, Set reloadedIndicesNodes, Set reloadedAnalyzers) { this.indexName = name; this.reloadedIndicesNodes = reloadedIndicesNodes; this.reloadedAnalyzers = reloadedAnalyzers;