From 6d3b7cbc220b53031439dd496687773a63618e07 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 08:49:32 -0700 Subject: [PATCH] Adds DeleteByQuery Request for SDKRestClient (#708) (#710) (cherry picked from commit b30bec488ee4ac0b74fdad14d503a1e5f99482ed) Signed-off-by: Owais Kazi Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- src/main/java/org/opensearch/sdk/SDKClient.java | 13 +++++++++++++ src/test/java/org/opensearch/sdk/TestSDKClient.java | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/org/opensearch/sdk/SDKClient.java b/src/main/java/org/opensearch/sdk/SDKClient.java index e30fe747..86fc3568 100644 --- a/src/main/java/org/opensearch/sdk/SDKClient.java +++ b/src/main/java/org/opensearch/sdk/SDKClient.java @@ -76,6 +76,8 @@ import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.transport.OpenSearchTransport; import org.opensearch.client.transport.rest_client.RestClientTransport; +import org.opensearch.index.reindex.BulkByScrollResponse; +import org.opensearch.index.reindex.DeleteByQueryRequest; /** * This class creates SDKClient for an extension to make requests to OpenSearch @@ -438,6 +440,17 @@ public void delete(DeleteRequest request, ActionListener listene restHighLevelClient.deleteAsync(request, options, listener); } + /** + * Deletes a document from the index based on the query. + * + * @param request The delete by query request + * @param listener A listener to be notified with a result + * + */ + public void deleteByQueryAsync(DeleteByQueryRequest request, ActionListener listener) { + restHighLevelClient.deleteByQueryAsync(request, options, listener); + } + /** * Search across one or more indices with a query. * diff --git a/src/test/java/org/opensearch/sdk/TestSDKClient.java b/src/test/java/org/opensearch/sdk/TestSDKClient.java index 104d47b5..964c4898 100644 --- a/src/test/java/org/opensearch/sdk/TestSDKClient.java +++ b/src/test/java/org/opensearch/sdk/TestSDKClient.java @@ -37,6 +37,7 @@ import org.opensearch.client.opensearch.cluster.OpenSearchClusterClient; import org.opensearch.client.opensearch.indices.OpenSearchIndicesAsyncClient; import org.opensearch.client.opensearch.indices.OpenSearchIndicesClient; +import org.opensearch.index.reindex.DeleteByQueryRequest; import org.opensearch.sdk.SDKClient.SDKClusterAdminClient; import org.opensearch.sdk.SDKClient.SDKIndicesClient; import org.opensearch.sdk.SDKClient.SDKRestClient; @@ -100,6 +101,7 @@ public void testSDKRestClient() throws Exception { assertDoesNotThrow(() -> restClient.multiGet(new MultiGetRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.update(new UpdateRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.delete(new DeleteRequest(), ActionListener.wrap(r -> {}, e -> {}))); + assertDoesNotThrow(() -> restClient.deleteByQueryAsync(new DeleteByQueryRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.search(new SearchRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.multiSearch(new MultiSearchRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.bulk(new BulkRequest(), ActionListener.wrap(r -> {}, e -> {})));