Skip to content

Commit

Permalink
Adding exists/existsAlias to SDK Indices Client (#802)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <[email protected]>
  • Loading branch information
joshpalis authored Jun 2, 2023
1 parent fbe2b9f commit 247c2cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/org/opensearch/sdk/SDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.opensearch.client.indices.CreateIndexResponse;
import org.opensearch.client.indices.GetFieldMappingsRequest;
import org.opensearch.client.indices.GetFieldMappingsResponse;
import org.opensearch.client.indices.GetIndexRequest;
import org.opensearch.client.indices.GetMappingsRequest;
import org.opensearch.client.indices.GetMappingsResponse;
import org.opensearch.client.indices.PutMappingRequest;
Expand Down Expand Up @@ -738,5 +739,27 @@ public Cancellable rolloverIndex(RolloverRequest rolloverRequest, ActionListener
public Cancellable getAliases(GetAliasesRequest getAliasesRequest, ActionListener<GetAliasesResponse> listener) {
return this.indicesClient.getAliasAsync(getAliasesRequest, options, listener);
}

/**
* Asynchronously checks if one or more aliases exist using the Aliases Exist API.
*
* @param getAliasesRequest the request
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable existsAlias(GetAliasesRequest getAliasesRequest, ActionListener<Boolean> listener) {
return this.indicesClient.existsAliasAsync(getAliasesRequest, options, listener);
}

/**
* Asynchronously checks if the index (indices) exists or not.
*
* @param getIndexRequest the request
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable exists(GetIndexRequest getIndexRequest, ActionListener<Boolean> listener) {
return this.indicesClient.existsAsync(getIndexRequest, options, listener);
}
}
}
3 changes: 3 additions & 0 deletions src/test/java/org/opensearch/sdk/TestSDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.opensearch.client.ResponseListener;
import org.opensearch.client.indices.CreateIndexRequest;
import org.opensearch.client.indices.GetFieldMappingsRequest;
import org.opensearch.client.indices.GetIndexRequest;
import org.opensearch.client.indices.GetMappingsRequest;
import org.opensearch.client.indices.PutMappingRequest;
import org.opensearch.client.indices.rollover.RolloverRequest;
Expand Down Expand Up @@ -153,6 +154,8 @@ public void testSDKIndicesClient() throws Exception {
indicesClient.rolloverIndex(new RolloverRequest("", ""), ActionListener.wrap(r -> {}, e -> {}))
);
assertInstanceOf(Cancellable.class, indicesClient.getAliases(new GetAliasesRequest(), ActionListener.wrap(r -> {}, e -> {})));
assertInstanceOf(Cancellable.class, indicesClient.existsAlias(new GetAliasesRequest(), ActionListener.wrap(r -> {}, e -> {})));
assertInstanceOf(Cancellable.class, indicesClient.exists(new GetIndexRequest(), ActionListener.wrap(r -> {}, e -> {})));

sdkClient.doCloseHighLevelClient();
}
Expand Down

0 comments on commit 247c2cd

Please sign in to comment.