From a464576ad7c523f39707b2525bbfb4bde320b122 Mon Sep 17 00:00:00 2001 From: "uri.nudelman" Date: Mon, 19 Aug 2024 17:17:11 -0400 Subject: [PATCH] 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();