From a464576ad7c523f39707b2525bbfb4bde320b122 Mon Sep 17 00:00:00 2001 From: "uri.nudelman" Date: Mon, 19 Aug 2024 17:17:11 -0400 Subject: [PATCH 1/5] Fixes #1116 Signed-off-by: uri.nudelman --- .../client/opensearch/core/SearchRequest.java | 44 +++++++++++++++++++ .../opensearch/core/SearchRequestTest.java | 11 +++++ 2 files changed, 55 insertions(+) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java index 3b7166c1fc..e1a47ab883 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java @@ -110,6 +110,9 @@ public class SearchRequest extends RequestBase implements PlainJsonSerializable @Nullable private final String pipeline; + @Nullable + private final Time cancelAfterTimeInterval; + @Nullable private final FieldCollapse collapse; @@ -246,6 +249,7 @@ private SearchRequest(Builder builder) { this.ccsMinimizeRoundtrips = builder.ccsMinimizeRoundtrips; this.phaseTook = builder.phaseTook; this.pipeline = builder.pipeline; + this.cancelAfterTimeInterval = builder.cancelAfterTimeInterval; this.collapse = builder.collapse; this.defaultOperator = builder.defaultOperator; this.df = builder.df; @@ -405,6 +409,17 @@ public final String pipeline() { return this.pipeline; } + /** + * The time after which the search request will be canceled. + * Request-level parameter takes precedence over cancel_after_time_interval cluster setting. + *

+ * API name: {@code cancel_after_time_interval} + */ + @Nullable + public final Time cancelAfterTimeInterval() { + return this.cancelAfterTimeInterval; + } + /** * API name: {@code collapse} */ @@ -1114,6 +1129,7 @@ public Builder toBuilder() { .ccsMinimizeRoundtrips(ccsMinimizeRoundtrips) .phaseTook(phaseTook) .pipeline(pipeline) + .cancelAfterTimeInterval(cancelAfterTimeInterval) .collapse(collapse) .defaultOperator(defaultOperator) .df(df) @@ -1198,6 +1214,9 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder + * API name: {@code cancel_after_time_interval} + */ + public final Builder cancelAfterTimeInterval(@Nullable Time value) { + this.cancelAfterTimeInterval = value; + return this; + } + + /** + * The time after which the search request will be canceled. + * Request-level parameter takes precedence over cancel_after_time_interval cluster setting. + *

+ * API name: {@code cancel_after_time_interval} + */ + public final Builder cancelAfterTimeInterval(Function> fn) { + return this.cancelAfterTimeInterval(fn.apply(new Time.Builder()).build()); + } + /** * API name: {@code collapse} */ @@ -2283,6 +2323,7 @@ protected static void setupSearchRequestDeserializer(ObjectDeserializer ti.time("1000ms")); + SearchRequest request = new SearchRequest.Builder().cancelAfterTimeInterval(cancelAfterTimeInterval).build(); + + assertEquals("{}", toJson(request)); + assertEquals(cancelAfterTimeInterval, request.cancelAfterTimeInterval()); + assertEquals("1000ms", SearchRequest._ENDPOINT.queryParameters(request).get("cancel_after_time_interval")); + } + @Test public void toBuilder() { SearchRequest origin = new SearchRequest.Builder().index("index").build(); From e537648f9b771ebd0d87fec3fbbe8278721a8685 Mon Sep 17 00:00:00 2001 From: "uri.nudelman" Date: Mon, 19 Aug 2024 17:45:38 -0400 Subject: [PATCH 2/5] Adds MsearchRequest. Fixes SearchRequest. Signed-off-by: uri.nudelman --- .../opensearch/core/MsearchRequest.java | 34 +++++++++++++++++++ .../client/opensearch/core/SearchRequest.java | 1 - .../opensearch/core/MsearchRequestTest.java | 18 ++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java index 931be38b15..ff4194cdc9 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java @@ -48,6 +48,7 @@ import org.opensearch.client.opensearch._types.ExpandWildcard; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.SearchType; +import org.opensearch.client.opensearch._types.Time; import org.opensearch.client.opensearch.core.msearch.RequestItem; import org.opensearch.client.transport.Endpoint; import org.opensearch.client.transport.endpoints.SimpleEndpoint; @@ -66,6 +67,9 @@ public class MsearchRequest extends RequestBase implements NdJsonpSerializable, @Nullable private final Boolean allowNoIndices; + @Nullable + private final Time cancelAfterTimeInterval; + @Nullable private final Boolean ccsMinimizeRoundtrips; @@ -98,6 +102,7 @@ public class MsearchRequest extends RequestBase implements NdJsonpSerializable, private MsearchRequest(Builder builder) { this.allowNoIndices = builder.allowNoIndices; + this.cancelAfterTimeInterval = builder.cancelAfterTimeInterval; this.ccsMinimizeRoundtrips = builder.ccsMinimizeRoundtrips; this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards); this.ignoreThrottled = builder.ignoreThrottled; @@ -134,6 +139,17 @@ public final Boolean allowNoIndices() { return this.allowNoIndices; } + /** + * The time after which the search request will be canceled. + * Request-level parameter takes precedence over cancel_after_time_interval cluster setting. + *

+ * API name: {@code cancel_after_time_interval} + */ + @Nullable + public final Time cancelAfterTimeInterval() { + return this.cancelAfterTimeInterval; + } + /** * If true, network roundtrips between the coordinating node and remote clusters * are minimized for cross-cluster search requests. @@ -256,6 +272,7 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { public Builder toBuilder() { return new Builder().allowNoIndices(allowNoIndices) + .cancelAfterTimeInterval(cancelAfterTimeInterval) .ccsMinimizeRoundtrips(ccsMinimizeRoundtrips) .expandWildcards(expandWildcards) .ignoreThrottled(ignoreThrottled) @@ -278,6 +295,9 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder + * API name: {@code cancel_after_time_interval} + */ + public final Builder cancelAfterTimeInterval(@Nullable Time value) { + this.cancelAfterTimeInterval = value; + return this; + } + /** * If true, network roundtrips between the coordinating node and remote clusters * are minimized for cross-cluster search requests. @@ -540,6 +571,9 @@ public MsearchRequest build() { request -> { Map params = new HashMap<>(); params.put("typed_keys", "true"); + if (request.cancelAfterTimeInterval != null) { + params.put("cancel_after_time_interval", request.cancelAfterTimeInterval._toJsonString()); + } if (request.preFilterShardSize != null) { params.put("pre_filter_shard_size", String.valueOf(request.preFilterShardSize)); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java index e1a47ab883..28faf4c174 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java @@ -2323,7 +2323,6 @@ protected static void setupSearchRequestDeserializer(ObjectDeserializer ti.time("1000ms")); + MsearchRequest request = new MsearchRequest.Builder() + .index("index") + .searches(Collections.emptyList()) + .cancelAfterTimeInterval(cancelAfterTimeInterval).build(); + + assertEquals("[]", toJson(request)); + assertEquals(cancelAfterTimeInterval, request.cancelAfterTimeInterval()); + assertEquals("1000ms", MsearchRequest._ENDPOINT.queryParameters(request).get("cancel_after_time_interval")); + } } From 264b3aaac44d955ea1a6abca62bc19a1dcb72124 Mon Sep 17 00:00:00 2001 From: "uri.nudelman" Date: Mon, 19 Aug 2024 17:52:02 -0400 Subject: [PATCH 3/5] Update CHANGELOG.md Signed-off-by: uri.nudelman --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbae3767c5..aefa38cbbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Added - Adds `queryImage` (query_image) field to `NeuralQuery`, following definition in ([Neural Query](https://opensearch.org/docs/latest/query-dsl/specialized/neural/)) ([#1137](https://github.com/opensearch-project/opensearch-java/pull/1138)) +- Adds `cancelAfterTimeInterval` to `SearchRequest` and `MsearchRequest` ([#1147](https://github.com/opensearch-project/opensearch-java/pull/1147)) ### Dependencies From 949779d804cffad534a138686b130b2b499dadd3 Mon Sep 17 00:00:00 2001 From: "uri.nudelman" Date: Mon, 19 Aug 2024 18:07:32 -0400 Subject: [PATCH 4/5] spotlessJavaCheck Signed-off-by: uri.nudelman --- .../client/opensearch/core/MsearchRequestTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java index 3cd112e451..1113bed475 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java @@ -26,10 +26,10 @@ public void toBuilder() { @Test public void cancelAfterTimeInterval() { Time cancelAfterTimeInterval = Time.of(ti -> ti.time("1000ms")); - MsearchRequest request = new MsearchRequest.Builder() - .index("index") - .searches(Collections.emptyList()) - .cancelAfterTimeInterval(cancelAfterTimeInterval).build(); + MsearchRequest request = new MsearchRequest.Builder().index("index") + .searches(Collections.emptyList()) + .cancelAfterTimeInterval(cancelAfterTimeInterval) + .build(); assertEquals("[]", toJson(request)); assertEquals(cancelAfterTimeInterval, request.cancelAfterTimeInterval()); From 320d4cf4a8bb3a38f729df9da5cf74a5b2099cc8 Mon Sep 17 00:00:00 2001 From: "uri.nudelman" Date: Wed, 21 Aug 2024 19:15:29 -0400 Subject: [PATCH 5/5] Adds Builder Function method in MSearch Signed-off-by: uri.nudelman --- .../client/opensearch/core/MsearchRequest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java index ff4194cdc9..a417915504 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/MsearchRequest.java @@ -352,6 +352,16 @@ public final Builder cancelAfterTimeInterval(@Nullable Time value) { return this; } + /** + * The time after which the search request will be canceled. + * Request-level parameter takes precedence over cancel_after_time_interval cluster setting. + *

+ * API name: {@code cancel_after_time_interval} + */ + public final Builder cancelAfterTimeInterval(Function> fn) { + return this.cancelAfterTimeInterval(fn.apply(new Time.Builder()).build()); + } + /** * If true, network roundtrips between the coordinating node and remote clusters * are minimized for cross-cluster search requests.