Skip to content

Commit 557ea3a

Browse files
authored
Create generic DocRequest to better categorize ActionRequests (#18269)
Signed-off-by: Craig Perkins <[email protected]>
1 parent 20ea406 commit 557ea3a

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2828
- Upgrade crypto kms plugin dependencies for AWS SDK v2.x. ([#18268](https://github.com/opensearch-project/OpenSearch/pull/18268))
2929

3030
### Changed
31+
- Create generic DocRequest to better categorize ActionRequests ([#18269](https://github.com/opensearch-project/OpenSearch/pull/18269)))
3132

3233
### Dependencies
3334
- 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))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.action;
10+
11+
import org.opensearch.common.annotation.PublicApi;
12+
13+
/**
14+
* Generic interface to group ActionRequest, which perform actions on a single document
15+
*
16+
* @opensearch.api
17+
*/
18+
@PublicApi(since = "3.1.0")
19+
public interface DocRequest {
20+
/**
21+
* Get the index that this request operates on
22+
* @return the index
23+
*/
24+
String index();
25+
26+
/**
27+
* Get the id of the document for this request
28+
* @return the id
29+
*/
30+
String id();
31+
}

server/src/main/java/org/opensearch/action/DocWriteRequest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* @opensearch.api
6060
*/
6161
@PublicApi(since = "1.0.0")
62-
public interface DocWriteRequest<T> extends IndicesRequest, Accountable {
62+
public interface DocWriteRequest<T> extends IndicesRequest, DocRequest, Accountable {
6363

6464
// Flag set for disallowing index auto creation for an individual write request.
6565
String REQUIRE_ALIAS = "require_alias";
@@ -70,18 +70,6 @@ public interface DocWriteRequest<T> extends IndicesRequest, Accountable {
7070
*/
7171
T index(String index);
7272

73-
/**
74-
* Get the index that this request operates on
75-
* @return the index
76-
*/
77-
String index();
78-
79-
/**
80-
* Get the id of the document for this request
81-
* @return the id
82-
*/
83-
String id();
84-
8573
/**
8674
* Get the options for this request
8775
* @return the indices options

server/src/main/java/org/opensearch/action/get/GetRequest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import org.opensearch.Version;
3636
import org.opensearch.action.ActionRequestValidationException;
37+
import org.opensearch.action.DocRequest;
3738
import org.opensearch.action.RealtimeRequest;
3839
import org.opensearch.action.ValidateActions;
3940
import org.opensearch.action.support.single.shard.SingleShardRequest;
@@ -49,6 +50,7 @@
4950
import org.opensearch.transport.client.Requests;
5051

5152
import java.io.IOException;
53+
import java.util.Objects;
5254

5355
import static org.opensearch.action.ValidateActions.addValidationError;
5456

@@ -66,7 +68,7 @@
6668
* @opensearch.api
6769
*/
6870
@PublicApi(since = "1.0.0")
69-
public class GetRequest extends SingleShardRequest<GetRequest> implements RealtimeRequest {
71+
public class GetRequest extends SingleShardRequest<GetRequest> implements RealtimeRequest, DocRequest {
7072

7173
private String id;
7274
private String routing;
@@ -163,6 +165,12 @@ public GetRequest preference(String preference) {
163165
return this;
164166
}
165167

168+
@Override
169+
public String index() {
170+
return Objects.requireNonNull(super.index());
171+
}
172+
173+
@Override
166174
public String id() {
167175
return id;
168176
}

0 commit comments

Comments
 (0)