From 217d81a789ea1dffc5113402d2bc4b5c23752688 Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Fri, 31 Mar 2023 01:47:38 -0700 Subject: [PATCH] Added multi search for Search Detector Signed-off-by: Owais Kazi --- src/main/java/org/opensearch/sdk/SDKClient.java | 12 ++++++++++++ src/test/java/org/opensearch/sdk/TestSDKClient.java | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/org/opensearch/sdk/SDKClient.java b/src/main/java/org/opensearch/sdk/SDKClient.java index bfb57405..89bec33a 100644 --- a/src/main/java/org/opensearch/sdk/SDKClient.java +++ b/src/main/java/org/opensearch/sdk/SDKClient.java @@ -45,6 +45,8 @@ import org.opensearch.action.get.MultiGetResponse; import org.opensearch.action.index.IndexRequest; import org.opensearch.action.index.IndexResponse; +import org.opensearch.action.search.MultiSearchRequest; +import org.opensearch.action.search.MultiSearchResponse; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchResponse; import org.opensearch.action.support.TransportAction; @@ -463,6 +465,16 @@ public void search(SearchRequest request, ActionListener listene restHighLevelClient.searchAsync(request, RequestOptions.DEFAULT, listener); } + /** + * Search across all documents that match the criteria + * + * @param request The multiSearch Request + * @param listener A listener to be notified with a result + */ + public void multiSearch(MultiSearchRequest request, ActionListener listener) { + restHighLevelClient.msearchAsync(request, RequestOptions.DEFAULT, listener); + } + /** * Sends a request to the OpenSearch cluster that the client points to. * diff --git a/src/test/java/org/opensearch/sdk/TestSDKClient.java b/src/test/java/org/opensearch/sdk/TestSDKClient.java index 1dcfca81..5d2cedcb 100644 --- a/src/test/java/org/opensearch/sdk/TestSDKClient.java +++ b/src/test/java/org/opensearch/sdk/TestSDKClient.java @@ -18,6 +18,7 @@ import org.opensearch.action.get.GetRequest; import org.opensearch.action.get.MultiGetRequest; import org.opensearch.action.index.IndexRequest; +import org.opensearch.action.search.MultiSearchRequest; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.update.UpdateRequest; import org.opensearch.client.Cancellable; @@ -96,6 +97,7 @@ public void testSDKRestClient() throws Exception { assertDoesNotThrow(() -> restClient.update(new UpdateRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.delete(new DeleteRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.search(new SearchRequest(), ActionListener.wrap(r -> {}, e -> {}))); + assertDoesNotThrow(() -> restClient.multiSearch(new MultiSearchRequest(), ActionListener.wrap(r -> {}, e -> {}))); expectThrows(ConnectException.class, () -> restClient.performRequest(new Request("GET", "/"))); sdkClient.doCloseHighLevelClient();