diff --git a/CHANGELOG.md b/CHANGELOG.md index efe350ea83764..1c361d21d543c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Decouple the init of Crypto Plugin and KeyProvider in CryptoRegistry ([18270](https://github.com/opensearch-project/OpenSearch/pull18270))) ### Changed +- Create generic DocRequest to better categorize ActionRequests ([#18269](https://github.com/opensearch-project/OpenSearch/pull/18269))) ### Dependencies - Bump `com.google.code.gson:gson` from 2.12.1 to 2.13.1 ([#17923](https://github.com/opensearch-project/OpenSearch/pull/17923), [#18266](https://github.com/opensearch-project/OpenSearch/pull/18266)) diff --git a/server/src/main/java/org/opensearch/action/DocRequest.java b/server/src/main/java/org/opensearch/action/DocRequest.java new file mode 100644 index 0000000000000..a9e535406d446 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/DocRequest.java @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.action; + +import org.opensearch.common.annotation.PublicApi; + +/** + * Generic interface to group ActionRequest, which perform actions on a single document + * + * @opensearch.api + */ +@PublicApi(since = "3.1.0") +public interface DocRequest { + /** + * Get the index that this request operates on + * @return the index + */ + String index(); + + /** + * Get the id of the document for this request + * @return the id + */ + String id(); +} diff --git a/server/src/main/java/org/opensearch/action/DocWriteRequest.java b/server/src/main/java/org/opensearch/action/DocWriteRequest.java index e09c76430defc..e887af898527e 100644 --- a/server/src/main/java/org/opensearch/action/DocWriteRequest.java +++ b/server/src/main/java/org/opensearch/action/DocWriteRequest.java @@ -59,7 +59,7 @@ * @opensearch.api */ @PublicApi(since = "1.0.0") -public interface DocWriteRequest extends IndicesRequest, Accountable { +public interface DocWriteRequest extends IndicesRequest, DocRequest, Accountable { // Flag set for disallowing index auto creation for an individual write request. String REQUIRE_ALIAS = "require_alias"; @@ -70,18 +70,6 @@ public interface DocWriteRequest extends IndicesRequest, Accountable { */ T index(String index); - /** - * Get the index that this request operates on - * @return the index - */ - String index(); - - /** - * Get the id of the document for this request - * @return the id - */ - String id(); - /** * Get the options for this request * @return the indices options diff --git a/server/src/main/java/org/opensearch/action/get/GetRequest.java b/server/src/main/java/org/opensearch/action/get/GetRequest.java index 588cc81cfca4a..c7acc2142438f 100644 --- a/server/src/main/java/org/opensearch/action/get/GetRequest.java +++ b/server/src/main/java/org/opensearch/action/get/GetRequest.java @@ -34,6 +34,7 @@ import org.opensearch.Version; import org.opensearch.action.ActionRequestValidationException; +import org.opensearch.action.DocRequest; import org.opensearch.action.RealtimeRequest; import org.opensearch.action.ValidateActions; import org.opensearch.action.support.single.shard.SingleShardRequest; @@ -49,6 +50,7 @@ import org.opensearch.transport.client.Requests; import java.io.IOException; +import java.util.Objects; import static org.opensearch.action.ValidateActions.addValidationError; @@ -66,7 +68,7 @@ * @opensearch.api */ @PublicApi(since = "1.0.0") -public class GetRequest extends SingleShardRequest implements RealtimeRequest { +public class GetRequest extends SingleShardRequest implements RealtimeRequest, DocRequest { private String id; private String routing; @@ -163,6 +165,12 @@ public GetRequest preference(String preference) { return this; } + @Override + public String index() { + return Objects.requireNonNull(super.index()); + } + + @Override public String id() { return id; }