diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/AsyncSearchRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/AsyncSearchRequestConverters.java index a5e2977bcfa2d..4d74012587340 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/AsyncSearchRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/AsyncSearchRequestConverters.java @@ -11,6 +11,7 @@ import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.RequestConverters.Params; import org.elasticsearch.client.asyncsearch.DeleteAsyncSearchRequest; import org.elasticsearch.client.asyncsearch.GetAsyncSearchRequest; @@ -53,7 +54,9 @@ static void addSearchRequestParams(Params params, SubmitAsyncSearchRequest reque params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true"); params.withRouting(request.getRouting()); params.withPreference(request.getPreference()); - params.withIndicesOptions(request.getIndicesOptions()); + if (SearchRequest.DEFAULT_INDICES_OPTIONS.equals(request.getIndicesOptions()) == false) { + params.withIndicesOptions(request.getIndicesOptions()); + } params.withSearchType(request.getSearchType().name().toLowerCase(Locale.ROOT)); params.withMaxConcurrentShardRequests(request.getMaxConcurrentShardRequests()); if (request.getRequestCache() != null) { 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 5a8a8a3a77d26..5dda32eb64cfd 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 @@ -26,6 +26,7 @@ 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.ValidateQueryRequest; +import org.elasticsearch.action.support.broadcast.BroadcastRequest; import org.elasticsearch.client.indices.AnalyzeRequest; import org.elasticsearch.client.indices.CloseIndexRequest; import org.elasticsearch.client.indices.CreateDataStreamRequest; @@ -100,7 +101,9 @@ static Request deleteIndex(DeleteIndexRequest deleteIndexRequest) { RequestConverters.Params parameters = new RequestConverters.Params(); parameters.withTimeout(deleteIndexRequest.timeout()); parameters.withMasterTimeout(deleteIndexRequest.masterNodeTimeout()); - parameters.withIndicesOptions(deleteIndexRequest.indicesOptions()); + if (DeleteIndexRequest.DEFAULT_INDICES_OPTIONS.equals(deleteIndexRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(deleteIndexRequest.indicesOptions()); + } request.addParameters(parameters.asMap()); return request; } @@ -113,7 +116,9 @@ static Request openIndex(OpenIndexRequest openIndexRequest) { parameters.withTimeout(openIndexRequest.timeout()); parameters.withMasterTimeout(openIndexRequest.masterNodeTimeout()); parameters.withWaitForActiveShards(openIndexRequest.waitForActiveShards()); - parameters.withIndicesOptions(openIndexRequest.indicesOptions()); + if (OpenIndexRequest.DEFAULT_INDICES_OPTIONS.equals(openIndexRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(openIndexRequest.indicesOptions()); + } request.addParameters(parameters.asMap()); return request; } @@ -125,7 +130,9 @@ static Request closeIndex(CloseIndexRequest closeIndexRequest) { RequestConverters.Params parameters = new RequestConverters.Params(); parameters.withTimeout(closeIndexRequest.timeout()); parameters.withMasterTimeout(closeIndexRequest.masterNodeTimeout()); - parameters.withIndicesOptions(closeIndexRequest.indicesOptions()); + if (CloseIndexRequest.DEFAULT_INDICES_OPTIONS.equals(closeIndexRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(closeIndexRequest.indicesOptions()); + } parameters.withWaitForActiveShards(closeIndexRequest.waitForActiveShards()); request.addParameters(parameters.asMap()); return request; @@ -163,7 +170,9 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio RequestConverters.Params parameters = new RequestConverters.Params(); parameters.withTimeout(putMappingRequest.timeout()); parameters.withMasterTimeout(putMappingRequest.masterNodeTimeout()); - parameters.withIndicesOptions(putMappingRequest.indicesOptions()); + if (PutMappingRequest.DEFAULT_INDICES_OPTIONS.equals(putMappingRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(putMappingRequest.indicesOptions()); + } request.addParameters(parameters.asMap()); request.setEntity(RequestConverters.createEntity(putMappingRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); return request; @@ -207,7 +216,9 @@ static Request refresh(RefreshRequest refreshRequest) { Request request = new Request(HttpPost.METHOD_NAME, RequestConverters.endpoint(indices, "_refresh")); RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withIndicesOptions(refreshRequest.indicesOptions()); + if (BroadcastRequest.DEFAULT_INDICES_OPTIONS.equals(refreshRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(refreshRequest.indicesOptions()); + } request.addParameters(parameters.asMap()); return request; } @@ -217,7 +228,9 @@ static Request flush(FlushRequest flushRequest) { Request request = new Request(HttpPost.METHOD_NAME, RequestConverters.endpoint(indices, "_flush")); RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withIndicesOptions(flushRequest.indicesOptions()); + if (BroadcastRequest.DEFAULT_INDICES_OPTIONS.equals(flushRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(flushRequest.indicesOptions()); + } parameters.putParam("wait_if_ongoing", Boolean.toString(flushRequest.waitIfOngoing())); parameters.putParam("force", Boolean.toString(flushRequest.force())); request.addParameters(parameters.asMap()); @@ -229,7 +242,9 @@ static Request forceMerge(ForceMergeRequest forceMergeRequest) { Request request = new Request(HttpPost.METHOD_NAME, RequestConverters.endpoint(indices, "_forcemerge")); RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withIndicesOptions(forceMergeRequest.indicesOptions()); + if (BroadcastRequest.DEFAULT_INDICES_OPTIONS.equals(forceMergeRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(forceMergeRequest.indicesOptions()); + } parameters.putParam("max_num_segments", Integer.toString(forceMergeRequest.maxNumSegments())); parameters.putParam("only_expunge_deletes", Boolean.toString(forceMergeRequest.onlyExpungeDeletes())); parameters.putParam("flush", Boolean.toString(forceMergeRequest.flush())); @@ -242,7 +257,9 @@ static Request clearCache(ClearIndicesCacheRequest clearIndicesCacheRequest) { Request request = new Request(HttpPost.METHOD_NAME, RequestConverters.endpoint(indices, "_cache/clear")); RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withIndicesOptions(clearIndicesCacheRequest.indicesOptions()); + if (BroadcastRequest.DEFAULT_INDICES_OPTIONS.equals(clearIndicesCacheRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(clearIndicesCacheRequest.indicesOptions()); + } parameters.putParam("query", Boolean.toString(clearIndicesCacheRequest.queryCache())); parameters.putParam("fielddata", Boolean.toString(clearIndicesCacheRequest.fieldDataCache())); parameters.putParam("request", Boolean.toString(clearIndicesCacheRequest.requestCache())); @@ -262,7 +279,9 @@ static Request existsAlias(GetAliasesRequest getAliasesRequest) { Request request = new Request(HttpHead.METHOD_NAME, RequestConverters.endpoint(indices, "_alias", aliases)); RequestConverters.Params params = new RequestConverters.Params(); - params.withIndicesOptions(getAliasesRequest.indicesOptions()); + if (GetAliasesRequest.DEFAULT_INDICES_OPTIONS.equals(getAliasesRequest.indicesOptions()) == false) { + params.withIndicesOptions(getAliasesRequest.indicesOptions()); + } params.withLocal(getAliasesRequest.local()); request.addParameters(params.asMap()); return request; @@ -363,7 +382,9 @@ static Request getSettings(GetSettingsRequest getSettingsRequest) { Request request = new Request(HttpGet.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(); - params.withIndicesOptions(getSettingsRequest.indicesOptions()); + if (GetSettingsRequest.DEFAULT_INDICES_OPTIONS.equals(getSettingsRequest.indicesOptions()) == false) { + params.withIndicesOptions(getSettingsRequest.indicesOptions()); + } params.withLocal(getSettingsRequest.local()); params.withIncludeDefaults(getSettingsRequest.includeDefaults()); params.withMasterTimeout(getSettingsRequest.masterNodeTimeout()); @@ -378,7 +399,9 @@ static Request getIndex(GetIndexRequest getIndexRequest) { Request request = new Request(HttpGet.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(); - params.withIndicesOptions(getIndexRequest.indicesOptions()); + if (GetIndexRequest.DEFAULT_INDICES_OPTIONS.equals(getIndexRequest.indicesOptions()) == false) { + params.withIndicesOptions(getIndexRequest.indicesOptions()); + } params.withLocal(getIndexRequest.local()); params.withIncludeDefaults(getIndexRequest.includeDefaults()); params.withHuman(getIndexRequest.humanReadable()); @@ -397,7 +420,9 @@ static Request indicesExist(GetIndexRequest getIndexRequest) { RequestConverters.Params params = new RequestConverters.Params(); params.withLocal(getIndexRequest.local()); params.withHuman(getIndexRequest.humanReadable()); - params.withIndicesOptions(getIndexRequest.indicesOptions()); + if (GetIndexRequest.DEFAULT_INDICES_OPTIONS.equals(getIndexRequest.indicesOptions()) == false) { + params.withIndicesOptions(getIndexRequest.indicesOptions()); + } params.withIncludeDefaults(getIndexRequest.includeDefaults()); request.addParameters(params.asMap()); return request; @@ -410,7 +435,9 @@ static Request indexPutSettings(UpdateSettingsRequest updateSettingsRequest) thr RequestConverters.Params parameters = new RequestConverters.Params(); parameters.withTimeout(updateSettingsRequest.timeout()); parameters.withMasterTimeout(updateSettingsRequest.masterNodeTimeout()); - parameters.withIndicesOptions(updateSettingsRequest.indicesOptions()); + if (UpdateSettingsRequest.DEFAULT_INDICES_OPTIONS.equals(updateSettingsRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(updateSettingsRequest.indicesOptions()); + } parameters.withPreserveExisting(updateSettingsRequest.isPreserveExisting()); request.addParameters(parameters.asMap()); request.setEntity(RequestConverters.createEntity(updateSettingsRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); @@ -477,7 +504,9 @@ static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws I String endpoint = RequestConverters.endpoint(indices, "_validate/query"); Request request = new Request(HttpGet.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(); - params.withIndicesOptions(validateQueryRequest.indicesOptions()); + if (ValidateQueryRequest.DEFAULT_INDICES_OPTIONS.equals(validateQueryRequest.indicesOptions()) == false) { + params.withIndicesOptions(validateQueryRequest.indicesOptions()); + } params.putParam("explain", Boolean.toString(validateQueryRequest.explain())); params.putParam("all_shards", Boolean.toString(validateQueryRequest.allShards())); params.putParam("rewrite", Boolean.toString(validateQueryRequest.rewrite())); @@ -492,7 +521,9 @@ static Request getAlias(GetAliasesRequest getAliasesRequest) { String endpoint = RequestConverters.endpoint(indices, "_alias", aliases); Request request = new Request(HttpGet.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(); - params.withIndicesOptions(getAliasesRequest.indicesOptions()); + if (GetAliasesRequest.DEFAULT_INDICES_OPTIONS.equals(getAliasesRequest.indicesOptions()) == false) { + params.withIndicesOptions(getAliasesRequest.indicesOptions()); + } params.withLocal(getAliasesRequest.local()); request.addParameters(params.asMap()); return request; @@ -610,7 +641,9 @@ 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()); + if (ReloadAnalyzersRequest.DEFAULT_INDICES_OPTIONS.equals(reloadAnalyzersRequest.indicesOptions()) == false) { + parameters.withIndicesOptions(reloadAnalyzersRequest.indicesOptions()); + } request.addParameters(parameters.asMap()); return request; } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 5580825d518e6..e5a60c0a16f80 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -401,7 +401,9 @@ static void addSearchRequestParams(Params params, SearchRequest searchRequest) { params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true"); params.withRouting(searchRequest.routing()); params.withPreference(searchRequest.preference()); - params.withIndicesOptions(searchRequest.indicesOptions()); + if (SearchRequest.DEFAULT_INDICES_OPTIONS.equals(searchRequest.indicesOptions()) == false) { + params.withIndicesOptions(searchRequest.indicesOptions()); + } params.withSearchType(searchRequest.searchType().name().toLowerCase(Locale.ROOT)); if (searchRequest.isCcsMinimizeRoundtrips() != SearchRequest.defaultCcsMinimizeRoundtrips(searchRequest)) { params.putParam("ccs_minimize_roundtrips", Boolean.toString(searchRequest.isCcsMinimizeRoundtrips())); @@ -437,7 +439,9 @@ static Request clearScroll(ClearScrollRequest clearScrollRequest) throws IOExcep static Request openPointInTime(OpenPointInTimeRequest openRequest) { Request request = new Request(HttpPost.METHOD_NAME, endpoint(openRequest.indices(), "_pit")); Params params = new Params(); - params.withIndicesOptions(openRequest.indicesOptions()); + if (OpenPointInTimeRequest.DEFAULT_INDICES_OPTIONS.equals(openRequest.indicesOptions()) == false) { + params.withIndicesOptions(openRequest.indicesOptions()); + } params.withRouting(openRequest.routing()); params.withPreference(openRequest.preference()); params.putParam("keep_alive", openRequest.keepAlive()); @@ -539,7 +543,9 @@ static Request fieldCaps(FieldCapabilitiesRequest fieldCapabilitiesRequest) thro Params params = new Params(); params.withFields(fieldCapabilitiesRequest.fields()); - params.withIndicesOptions(fieldCapabilitiesRequest.indicesOptions()); + if (FieldCapabilitiesRequest.DEFAULT_INDICES_OPTIONS.equals(fieldCapabilitiesRequest.indicesOptions()) == false) { + params.withIndicesOptions(fieldCapabilitiesRequest.indicesOptions()); + } request.addParameters(params.asMap()); if (fieldCapabilitiesRequest.indexFilter() != null) { request.setEntity(createEntity(fieldCapabilitiesRequest, REQUEST_BODY_CONTENT_TYPE)); @@ -551,7 +557,9 @@ static Request rankEval(RankEvalRequest rankEvalRequest) throws IOException { Request request = new Request(HttpGet.METHOD_NAME, endpoint(rankEvalRequest.indices(), Strings.EMPTY_ARRAY, "_rank_eval")); Params params = new Params(); - params.withIndicesOptions(rankEvalRequest.indicesOptions()); + if (SearchRequest.DEFAULT_INDICES_OPTIONS.equals(rankEvalRequest.indicesOptions()) == false) { + params.withIndicesOptions(rankEvalRequest.indicesOptions()); + } params.putParam("search_type", rankEvalRequest.searchType().name().toLowerCase(Locale.ROOT)); request.addParameters(params.asMap()); request.setEntity(createEntity(rankEvalRequest.getRankEvalSpec(), REQUEST_BODY_CONTENT_TYPE)); @@ -613,9 +621,13 @@ private static Request prepareDeleteByQueryRequest(DeleteByQueryRequest deleteBy .withTimeout(deleteByQueryRequest.getTimeout()) .withWaitForActiveShards(deleteByQueryRequest.getWaitForActiveShards()) .withRequestsPerSecond(deleteByQueryRequest.getRequestsPerSecond()) - .withIndicesOptions(deleteByQueryRequest.indicesOptions()) .withWaitForCompletion(waitForCompletion) .withSlices(deleteByQueryRequest.getSlices()); + + if (SearchRequest.DEFAULT_INDICES_OPTIONS.equals(deleteByQueryRequest.indicesOptions()) == false) { + params = params.withIndicesOptions(deleteByQueryRequest.indicesOptions()); + } + if (deleteByQueryRequest.isAbortOnVersionConflict() == false) { params.putParam("conflicts", "proceed"); } @@ -644,9 +656,11 @@ static Request prepareUpdateByQueryRequest(UpdateByQueryRequest updateByQueryReq .withTimeout(updateByQueryRequest.getTimeout()) .withWaitForActiveShards(updateByQueryRequest.getWaitForActiveShards()) .withRequestsPerSecond(updateByQueryRequest.getRequestsPerSecond()) - .withIndicesOptions(updateByQueryRequest.indicesOptions()) .withWaitForCompletion(waitForCompletion) .withSlices(updateByQueryRequest.getSlices()); + if (SearchRequest.DEFAULT_INDICES_OPTIONS.equals(updateByQueryRequest.indicesOptions()) == false) { + params = params.withIndicesOptions(updateByQueryRequest.indicesOptions()); + } if (updateByQueryRequest.isAbortOnVersionConflict() == false) { params.putParam("conflicts", "proceed"); } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java index 010750f37243d..a1fd6f6aee2c5 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java @@ -21,8 +21,6 @@ import java.util.Arrays; import java.util.Objects; -import static org.elasticsearch.action.search.SearchRequest.DEFAULT_INDICES_OPTIONS; - /** * Encapsulates a request to _count API against one, several or all indices. */ @@ -33,7 +31,7 @@ public final class CountRequest implements Validatable, ToXContentObject { private String routing; private String preference; private QueryBuilder query; - private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; + private IndicesOptions indicesOptions; private int terminateAfter = SearchContext.DEFAULT_TERMINATE_AFTER; private Float minScore; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/eql/EqlSearchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/eql/EqlSearchRequest.java index aaf965ba3bdd5..73bca59e1be9a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/eql/EqlSearchRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/eql/EqlSearchRequest.java @@ -28,7 +28,7 @@ public class EqlSearchRequest implements Validatable, ToXContentObject { private String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(true, true, true, false); + private IndicesOptions indicesOptions; private QueryBuilder filter = null; private String timestampField = "@timestamp"; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/ExplainLifecycleRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/ExplainLifecycleRequest.java index 02904b5eca5d8..ad47316d023e5 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/ExplainLifecycleRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/ExplainLifecycleRequest.java @@ -22,7 +22,7 @@ public class ExplainLifecycleRequest extends TimedRequest { private final String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); + private IndicesOptions indicesOptions; public ExplainLifecycleRequest(String... indices) { if (indices.length == 0) { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequest.java index fa4ac94ea8819..4b2c01da05435 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequest.java @@ -21,7 +21,8 @@ public class RemoveIndexLifecyclePolicyRequest extends TimedRequest { private final IndicesOptions indicesOptions; public RemoveIndexLifecyclePolicyRequest(List indices) { - this(indices, IndicesOptions.strictExpandOpen()); + this.indices = Objects.requireNonNull(indices); + this.indicesOptions = null; } public RemoveIndexLifecyclePolicyRequest(List indices, IndicesOptions indicesOptions) { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CloseIndexRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CloseIndexRequest.java index 5f1748c8f1530..4a889c3b9aa1f 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CloseIndexRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CloseIndexRequest.java @@ -22,8 +22,10 @@ */ public class CloseIndexRequest extends TimedRequest implements Validatable { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpen(); + private String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT; /** diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetFieldMappingsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetFieldMappingsRequest.java index a8af8d7d3c469..fdcbd1a240ba2 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetFieldMappingsRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetFieldMappingsRequest.java @@ -21,7 +21,7 @@ public class GetFieldMappingsRequest implements Validatable { private String[] indices = Strings.EMPTY_ARRAY; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); + private IndicesOptions indicesOptions; public GetFieldMappingsRequest indices(String... indices) { this.indices = indices; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexRequest.java index a7f606cd9602e..2224c35c7d33d 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexRequest.java @@ -23,13 +23,15 @@ public enum Feature { SETTINGS; } + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.fromOptions(false, false, true, true); + static final Feature[] DEFAULT_FEATURES = new Feature[] { Feature.ALIASES, Feature.MAPPINGS, Feature.SETTINGS }; private Feature[] features = DEFAULT_FEATURES; private boolean humanReadable = false; private transient boolean includeDefaults = false; private final String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private boolean local = false; public GetIndexRequest(String... indices) { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetMappingsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetMappingsRequest.java index 74bdd80702d85..29c4df678a187 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetMappingsRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetMappingsRequest.java @@ -17,7 +17,7 @@ public class GetMappingsRequest extends TimedRequest { private boolean local = false; private boolean includeDefaults = false; private String[] indices = Strings.EMPTY_ARRAY; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); + private IndicesOptions indicesOptions; /** * Indicates whether the receiving node should operate based on local index information or diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutMappingRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutMappingRequest.java index e7806ea3fda43..6171500fc561f 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutMappingRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutMappingRequest.java @@ -31,8 +31,10 @@ */ public class PutMappingRequest extends TimedRequest implements IndicesRequest, ToXContentObject { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.fromOptions(false, false, true, true); + private final String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private BytesReference source; private XContentType xContentType; 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 index 5c0b9bf4e4c9a..4b17000d5e388 100644 --- 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 @@ -17,8 +17,10 @@ */ public final class ReloadAnalyzersRequest implements Validatable { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpen(); + private final String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; /** * Creates a new reload analyzers request diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java index 956c4acba9963..80d68e5bc9bd0 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java @@ -64,6 +64,13 @@ public abstract class ESRestHighLevelClientTestCase extends ESRestTestCase { + public static final String IGNORE_THROTTLED_DEPRECATION_WARNING = "[ignore_throttled] parameter is deprecated because frozen " + + "indices have been deprecated. Consider cold or frozen tiers in place of frozen indices."; + + protected static final RequestOptions IGNORE_THROTTLED_WARNING = RequestOptions.DEFAULT.toBuilder() + .setWarningsHandler( + warnings -> List.of(IGNORE_THROTTLED_DEPRECATION_WARNING).equals(warnings) == false + ).build(); protected static final String CONFLICT_PIPELINE_ID = "conflict_pipeline"; private static RestHighLevelClient restHighLevelClient; 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 a7cfa410b6c17..320bf46bee459 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 @@ -665,13 +665,14 @@ public void testOpenNonExistentIndex() throws IOException { OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndex); lenientOpenIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::open, - highLevelClient().indices()::openAsync); + highLevelClient().indices()::openAsync, IGNORE_THROTTLED_WARNING); assertThat(lenientOpenIndexResponse.isAcknowledged(), equalTo(true)); OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndex); strictOpenIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen()); ElasticsearchException strictException = expectThrows(ElasticsearchException.class, - () -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync)); + () -> execute(openIndexRequest, highLevelClient().indices()::open, + highLevelClient().indices()::openAsync, IGNORE_THROTTLED_WARNING)); assertEquals(RestStatus.NOT_FOUND, strictException.status()); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java index 53be9e516dfe9..cffa76fdc3f53 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java @@ -99,7 +99,7 @@ public void testRankEvalRequest() throws IOException { // now try this when test2 is closed closeIndex("index2"); rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS)); - response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync); + response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync, IGNORE_THROTTLED_WARNING); } private static List createTestEvaluationSpec() { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index 7597d53206c74..38a2cd62a4002 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -1437,7 +1437,7 @@ public void testPointInTime() throws Exception { openRequest.preference(preference); expectedParams.put("preference", preference); } - openRequest.indicesOptions(setRandomIndicesOptions(openRequest.indicesOptions(), expectedParams)); + setRandomIndicesOptions(openRequest::indicesOptions, openRequest::indicesOptions, expectedParams); final Request request = RequestConverters.openPointInTime(openRequest); assertThat(request.getParameters(), equalTo(expectedParams)); assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); @@ -1576,7 +1576,8 @@ public void testFieldCaps() throws IOException { endpoint.add("_field_caps"); assertEquals(endpoint.toString(), request.getEndpoint()); - assertEquals(5, request.getParameters().size()); + int expectedSize = FieldCapabilitiesRequest.DEFAULT_INDICES_OPTIONS.equals(fieldCapabilitiesRequest.indicesOptions()) ? 1 : 5; + assertEquals(expectedSize, request.getParameters().size()); // Note that we don't check the field param value explicitly, as field names are // passed through @@ -1617,7 +1618,8 @@ public void testFieldCapsWithIndexFilter() throws IOException { endpoint.add("_field_caps"); assertEquals(endpoint.toString(), request.getEndpoint()); - assertEquals(5, request.getParameters().size()); + int expectedSize = FieldCapabilitiesRequest.DEFAULT_INDICES_OPTIONS.equals(fieldCapabilitiesRequest.indicesOptions()) ? 1 : 5; + assertEquals(expectedSize, request.getParameters().size()); // Note that we don't check the field param value explicitly, as field names are // passed through @@ -1656,7 +1658,8 @@ public void testRankEval() throws Exception { } endpoint.add(RestRankEvalAction.ENDPOINT); assertEquals(endpoint.toString(), request.getEndpoint()); - assertEquals(5, request.getParameters().size()); + int expectedSize = SearchRequest.DEFAULT_INDICES_OPTIONS.equals(rankEvalRequest.indicesOptions()) ? 1 : 5; + assertEquals(expectedSize, request.getParameters().size()); assertEquals(expectedParams, request.getParameters()); assertToXContentBody(spec, request.getEntity()); } @@ -1994,9 +1997,19 @@ public static void setRandomIndicesOptions(Consumer setter, Supp Map expectedParams) { if (randomBoolean()) { - setter.accept(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), - true, false, false, randomBoolean())); + // randomly not set random indices options. + return; } + + IndicesOptions defaults = getter.get(); + IndicesOptions random = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), true, false, + false, randomBoolean()); + if (random.equals(defaults)) { + // Random indices options is equal to the defaults, we expect no params to be set. + return; + } + + setter.accept(random); expectedParams.put("ignore_unavailable", Boolean.toString(getter.get().ignoreUnavailable())); expectedParams.put("allow_no_indices", Boolean.toString(getter.get().allowNoIndices())); if (getter.get().expandWildcardsOpen() && getter.get().expandWildcardsClosed()) { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/core/CountRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/CountRequestTests.java index 3538da0fd7baf..35171dddaac60 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/core/CountRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/CountRequestTests.java @@ -62,7 +62,7 @@ protected NamedXContentRegistry xContentRegistry() { public void testIllegalArguments() { CountRequest countRequest = new CountRequest(); assertNotNull(countRequest.indices()); - assertNotNull(countRequest.indicesOptions()); + assertNull(countRequest.indicesOptions()); assertNotNull(countRequest.types()); Exception e = expectThrows(NullPointerException.class, () -> countRequest.indices((String[]) null)); @@ -122,7 +122,9 @@ private CountRequest mutate(CountRequest countRequest) { private static CountRequest copyRequest(CountRequest countRequest) { CountRequest result = new CountRequest(); result.indices(countRequest.indices()); - result.indicesOptions(countRequest.indicesOptions()); + if (result.indicesOptions() != null) { + result.indicesOptions(countRequest.indicesOptions()); + } result.types(countRequest.types()); result.routing(countRequest.routing()); result.preference(countRequest.preference()); 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 index 99e28070ec5d4..3c00b40b7fdb4 100644 --- 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 @@ -1047,9 +1047,10 @@ public void testUpdateByQuery() throws Exception { 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.DEFAULT); + client.updateByQuery(request, requestOptions); // end::update-by-query-execute assertSame(0, bulkResponse.getSearchFailures().size()); assertSame(0, bulkResponse.getBulkFailures().size()); @@ -1159,9 +1160,10 @@ public void testDeleteByQuery() throws Exception { 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.DEFAULT); + client.deleteByQuery(request, requestOptions); // end::delete-by-query-execute assertSame(0, bulkResponse.getSearchFailures().size()); assertSame(0, bulkResponse.getBulkFailures().size()); 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 88e8192f7a271..0869d9b5cb303 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 @@ -108,6 +108,7 @@ import java.util.concurrent.TimeUnit; import static org.elasticsearch.client.IndicesClientIT.FROZEN_INDICES_DEPRECATION_WARNING; +import static org.elasticsearch.client.IndicesClientIT.IGNORE_THROTTLED_DEPRECATION_WARNING; import static org.elasticsearch.client.IndicesClientIT.LEGACY_TEMPLATE_OPTIONS; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; @@ -158,8 +159,9 @@ public void testIndicesExist() throws IOException { 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.DEFAULT); + boolean exists = client.indices().exists(request, requestOptions); // end::indices-exists-execute assertTrue(exists); } @@ -226,8 +228,9 @@ public void testDeleteIndex() throws IOException { 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.DEFAULT); + AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, requestOptions); // end::delete-index-execute // tag::delete-index-response @@ -590,8 +593,9 @@ public void testGetMapping() throws IOException { 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.DEFAULT); + GetMappingsResponse getMappingResponse = client.indices().getMapping(request, requestOptions); // end::get-mappings-execute // tag::get-mappings-response @@ -706,10 +710,11 @@ public void testGetFieldMapping() throws IOException, InterruptedException { 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.DEFAULT); + client.indices().getFieldMapping(request, requestOptions); // end::get-field-mappings-execute // tag::get-field-mappings-response @@ -760,7 +765,7 @@ public void onFailure(Exception e) { }); // tag::get-field-mappings-execute-async - client.indices().getFieldMappingAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.indices().getFieldMappingAsync(request, requestOptions, listener); // <1> // end::get-field-mappings-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); @@ -800,8 +805,9 @@ public void testOpenIndex() throws Exception { 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.DEFAULT); + OpenIndexResponse openIndexResponse = client.indices().open(request, requestOptions); // end::open-index-execute // tag::open-index-response @@ -831,7 +837,7 @@ public void onFailure(Exception e) { listener = new LatchedActionListener<>(listener, latch); // tag::open-index-execute-async - client.indices().openAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.indices().openAsync(request, requestOptions, listener); // <1> // end::open-index-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); @@ -867,7 +873,7 @@ public void testRefreshIndex() throws Exception { // end::refresh-request // tag::refresh-request-indicesOptions - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> + request.indicesOptions(IndicesOptions.strictExpandOpenAndForbidClosed()); // <1> // end::refresh-request-indicesOptions // tag::refresh-execute @@ -947,8 +953,9 @@ public void testFlushIndex() throws Exception { request.force(true); // <1> // end::flush-request-force + RequestOptions requestOptions = IGNORE_THROTTLED_WARNING; // tag::flush-execute - FlushResponse flushResponse = client.indices().flush(request, RequestOptions.DEFAULT); + FlushResponse flushResponse = client.indices().flush(request, requestOptions); // end::flush-execute // tag::flush-response @@ -977,7 +984,7 @@ public void onFailure(Exception e) { listener = new LatchedActionListener<>(listener, latch); // tag::flush-execute-async - client.indices().flushAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.indices().flushAsync(request, requestOptions, listener); // <1> // end::flush-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); @@ -1019,8 +1026,9 @@ public void testGetSettings() throws Exception { 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.DEFAULT); + GetSettingsResponse getSettingsResponse = client.indices().getSettings(request, requestOptions); // end::get-settings-execute // tag::get-settings-response @@ -1055,7 +1063,7 @@ public void onFailure(Exception e) { listener = new LatchedActionListener<>(listener, latch); // tag::get-settings-execute-async - client.indices().getSettingsAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.indices().getSettingsAsync(request, requestOptions, listener); // <1> // end::get-settings-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); @@ -1072,7 +1080,6 @@ public void testGetSettingsWithDefaults() throws Exception { } GetSettingsRequest request = new GetSettingsRequest().indices("index"); - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // tag::get-settings-request-include-defaults request.includeDefaults(true); // <1> @@ -1138,8 +1145,9 @@ public void testGetIndex() throws Exception { 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.DEFAULT); + GetIndexResponse getIndexResponse = client.indices().get(request, requestOptions); // end::get-index-execute // tag::get-index-response @@ -1183,7 +1191,7 @@ public void onFailure(Exception e) { listener = new LatchedActionListener<>(listener, latch); // tag::get-index-execute-async - client.indices().getAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.indices().getAsync(request, requestOptions, listener); // <1> // end::get-index-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); @@ -1224,8 +1232,9 @@ public void testForceMergeIndex() throws Exception { 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.DEFAULT); + ForceMergeResponse forceMergeResponse = client.indices().forcemerge(request, requestOptions); // end::force-merge-execute // tag::force-merge-response @@ -1250,7 +1259,7 @@ public void onFailure(Exception e) { // end::force-merge-execute-listener // tag::force-merge-execute-async - client.indices().forcemergeAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.indices().forcemergeAsync(request, requestOptions, listener); // <1> // end::force-merge-execute-async } { @@ -1302,8 +1311,9 @@ public void testClearCache() throws Exception { 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.DEFAULT); + ClearIndicesCacheResponse clearCacheResponse = client.indices().clearCache(request, requestOptions); // end::clear-cache-execute // tag::clear-cache-response @@ -1376,8 +1386,9 @@ public void testCloseIndex() throws Exception { 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.DEFAULT); + AcknowledgedResponse closeIndexResponse = client.indices().close(request, requestOptions); // end::close-index-execute // tag::close-index-response @@ -1444,8 +1455,9 @@ public void testExistsAlias() throws Exception { 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.DEFAULT); + boolean exists = client.indices().existsAlias(request, requestOptions); // end::exists-alias-execute assertTrue(exists); @@ -1911,8 +1923,9 @@ public void testGetAlias() throws Exception { 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.DEFAULT); + GetAliasesResponse response = client.indices().getAlias(request, requestOptions); // end::get-alias-execute // tag::get-alias-response @@ -1951,7 +1964,7 @@ public void onFailure(Exception e) { listener = new LatchedActionListener<>(listener, latch); // tag::get-alias-execute-async - client.indices().getAliasAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.indices().getAliasAsync(request, requestOptions, listener); // <1> // end::get-alias-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); @@ -2024,9 +2037,10 @@ public void testIndexPutSettings() throws Exception { 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.DEFAULT); + client.indices().putSettings(request, requestOptions); // end::indices-put-settings-execute // tag::indices-put-settings-response @@ -2887,7 +2901,9 @@ public void testFreezeIndex() throws Exception { // end::freeze-index-request-indicesOptions final RequestOptions freezeIndexOptions = RequestOptions.DEFAULT.toBuilder() - .setWarningsHandler(warnings -> List.of(FROZEN_INDICES_DEPRECATION_WARNING).equals(warnings) == false).build(); + .setWarningsHandler( + warnings -> List.of(FROZEN_INDICES_DEPRECATION_WARNING, IGNORE_THROTTLED_DEPRECATION_WARNING).equals(warnings) == false + ).build(); // tag::freeze-index-execute ShardsAcknowledgedResponse openIndexResponse = client.indices().freeze(request, freezeIndexOptions); @@ -2969,7 +2985,9 @@ public void testUnfreezeIndex() throws Exception { // tag::unfreeze-index-execute final RequestOptions unfreezeIndexOptions = RequestOptions.DEFAULT.toBuilder() - .setWarningsHandler(warnings -> List.of(FROZEN_INDICES_DEPRECATION_WARNING).equals(warnings) == false).build(); + .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 diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java index 7b64a2f27cda6..28e7cf69369c7 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java @@ -149,7 +149,7 @@ public void testSearch() throws Exception { // tag::search-request-preference searchRequest.preference("_local"); // <1> // end::search-request-preference - assertNotNull(client.search(searchRequest, RequestOptions.DEFAULT)); + assertNotNull(client.search(searchRequest, IGNORE_THROTTLED_WARNING)); } { // tag::search-source-basics @@ -777,7 +777,7 @@ public void testPointInTime() throws Exception { openRequest.preference("_local"); // <1> // end::open-point-in-time-preference - openResponse = client.openPointInTime(openRequest, RequestOptions.DEFAULT); + openResponse = client.openPointInTime(openRequest, IGNORE_THROTTLED_WARNING); pitId = openResponse.getPointInTimeId(); client.closePointInTime(new ClosePointInTimeRequest(pitId), RequestOptions.DEFAULT); } @@ -1119,8 +1119,9 @@ public void testFieldCaps() throws Exception { 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.DEFAULT); + FieldCapabilitiesResponse response = client.fieldCaps(request, requestOptions); // end::field-caps-execute // tag::field-caps-response @@ -1371,7 +1372,7 @@ public void testCount() throws Exception { .indicesOptions(IndicesOptions.lenientExpandOpen()) // <3> .preference("_local"); // <4> // end::count-request-args - assertNotNull(client.count(countRequest, RequestOptions.DEFAULT)); + assertNotNull(client.count(countRequest, IGNORE_THROTTLED_WARNING)); } { // tag::count-source-basics diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/eql/EqlSearchRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/eql/EqlSearchRequestTests.java index 25a210df30776..39238cd3ee5ac 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/eql/EqlSearchRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/eql/EqlSearchRequestTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.client.eql; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.AbstractRequestTestCase; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.NamedXContentRegistry; @@ -70,7 +71,9 @@ protected void assertInstances(org.elasticsearch.xpack.eql.action.EqlSearchReque assertThat(serverInstance.tiebreakerField(), equalTo(clientTestInstance.tiebreakerField())); assertThat(serverInstance.filter(), equalTo(clientTestInstance.filter())); assertThat(serverInstance.query(), equalTo(clientTestInstance.query())); - assertThat(serverInstance.indicesOptions(), equalTo(clientTestInstance.indicesOptions())); + IndicesOptions actual = clientTestInstance.indicesOptions() == null ? + org.elasticsearch.xpack.eql.action.EqlSearchRequest.DEFAULT_INDICES_OPTIONS : clientTestInstance.indicesOptions(); + assertThat(serverInstance.indicesOptions(), equalTo(actual)); assertThat(serverInstance.indices(), equalTo(clientTestInstance.indices())); assertThat(serverInstance.fetchSize(), equalTo(clientTestInstance.fetchSize())); assertThat(serverInstance.size(), equalTo(clientTestInstance.size())); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequestTests.java index 21b3fa182fef8..ee7bb86e7f319 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ilm/RemoveIndexLifecyclePolicyRequestTests.java @@ -42,11 +42,15 @@ protected RemoveIndexLifecyclePolicyRequest createInstance() { } private RemoveIndexLifecyclePolicyRequest copyInstance(RemoveIndexLifecyclePolicyRequest req) { - return new RemoveIndexLifecyclePolicyRequest(new ArrayList<>(req.indices()), IndicesOptions.fromOptions( + if (req.indicesOptions() != null) { + return new RemoveIndexLifecyclePolicyRequest(new ArrayList<>(req.indices()), IndicesOptions.fromOptions( req.indicesOptions().ignoreUnavailable(), req.indicesOptions().allowNoIndices(), req.indicesOptions().expandWildcardsOpen(), req.indicesOptions().expandWildcardsClosed(), req.indicesOptions().allowAliasesToMultipleIndices(), req.indicesOptions().forbidClosedIndices(), req.indicesOptions().ignoreAliases(), req.indicesOptions().ignoreThrottled())); + } else { + return new RemoveIndexLifecyclePolicyRequest(new ArrayList<>(req.indices())); + } } private RemoveIndexLifecyclePolicyRequest mutateInstance(RemoveIndexLifecyclePolicyRequest req) { @@ -55,9 +59,14 @@ private RemoveIndexLifecyclePolicyRequest mutateInstance(RemoveIndexLifecyclePol randomValueOtherThan(req.indicesOptions(), () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()))); } else { - return new RemoveIndexLifecyclePolicyRequest( + if (req.indicesOptions() != null) { + return new RemoveIndexLifecyclePolicyRequest( randomValueOtherThan(req.indices(), () -> Arrays.asList(generateRandomStringArray(20, 20, false))), req.indicesOptions()); + } else { + return new RemoveIndexLifecyclePolicyRequest( + randomValueOtherThan(req.indices(), () -> Arrays.asList(generateRandomStringArray(20, 20, false)))); + } } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesRequest.java index 9175af743aee0..dde5fd637d6a0 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesRequest.java @@ -19,9 +19,11 @@ public class GetAliasesRequest extends MasterNodeReadRequest implements AliasesRequest { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandHidden(); + private String[] indices = Strings.EMPTY_ARRAY; private String[] aliases = Strings.EMPTY_ARRAY; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandHidden(); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private String[] originalAliases = Strings.EMPTY_ARRAY; public GetAliasesRequest(String... aliases) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java index 11d8d61d7096c..141108df95580 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java @@ -25,9 +25,12 @@ */ public class DeleteIndexRequest extends AcknowledgedRequest implements IndicesRequest.Replaceable { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = + IndicesOptions.fromOptions(false, true, true, true, false, false, true, false); + private String[] indices; // Delete index should work by default on both open and closed indices. - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true, false, false, true, false); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; public DeleteIndexRequest(StreamInput in) throws IOException { super(in); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java index 6474aa85a50e5..2f15b0f8b190a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java @@ -26,8 +26,10 @@ */ public class OpenIndexRequest extends AcknowledgedRequest implements IndicesRequest.Replaceable { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.fromOptions(false, true, false, true); + private String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, false, true); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT; public OpenIndexRequest(StreamInput in) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java index b209f08feefac..beaacd377bf7e 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java @@ -23,8 +23,10 @@ public class GetSettingsRequest extends MasterNodeReadRequest implements IndicesRequest.Replaceable { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.fromOptions(false, true, true, true); + private String[] indices = Strings.EMPTY_ARRAY; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private String[] names = Strings.EMPTY_ARRAY; private boolean humanReadable = false; private boolean includeDefaults = false; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java index ec41573a86759..78cf32952a66c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java @@ -39,8 +39,10 @@ public class UpdateSettingsRequest extends AcknowledgedRequest implements IndicesRequest.Replaceable, ToXContentObject { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.fromOptions(false, false, true, true); + private String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private Settings settings = EMPTY_SETTINGS; private boolean preserveExisting = false; private String origin = ""; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java index ffcff1d4d642d..4ca09393977eb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java @@ -31,6 +31,8 @@ */ public class ValidateQueryRequest extends BroadcastRequest implements ToXContentObject { + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.fromOptions(false, false, true, false); + private QueryBuilder query = new MatchAllQueryBuilder(); private boolean explain; @@ -65,7 +67,7 @@ public ValidateQueryRequest(StreamInput in) throws IOException { */ public ValidateQueryRequest(String... indices) { super(indices); - indicesOptions(IndicesOptions.fromOptions(false, false, true, false)); + indicesOptions(DEFAULT_INDICES_OPTIONS); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java index 63d4d611a1b75..d69366793e87a 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java @@ -30,9 +30,10 @@ public final class FieldCapabilitiesRequest extends ActionRequest implements IndicesRequest.Replaceable, ToXContentObject { public static final String NAME = "field_caps_request"; + public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpen(); private String[] indices = Strings.EMPTY_ARRAY; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); + private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS; private String[] fields = Strings.EMPTY_ARRAY; private boolean includeUnmapped = false; // pkg private API mainly for cross cluster search to signal that we do multiple reductions ie. the results should not be merged diff --git a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java index 3f3f790c15018..cd1299ae8754a 100644 --- a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java +++ b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java @@ -8,6 +8,8 @@ package org.elasticsearch.action.support; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.logging.DeprecationCategory; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.core.Nullable; import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.io.stream.StreamInput; @@ -103,6 +105,10 @@ public enum Option { public static final EnumSet