diff --git a/CHANGELOG.md b/CHANGELOG.md index 34e0e27c51..32f29e6bcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased 2.x] ### Added +- Add support for phase_took & search_pipeline request params ([#1036](https://github.com/opensearch-project/opensearch-java/pull/1036)) ### Dependencies - Bumps `io.github.classgraph:classgraph` from 4.8.173 to 4.8.174 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 c5168227d5..582321414a 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 @@ -104,6 +104,12 @@ public class SearchRequest extends RequestBase implements JsonpSerializable { @Nullable private final Boolean ccsMinimizeRoundtrips; + @Nullable + private final Boolean phaseTook; + + @Nullable + private final String pipeline; + @Nullable private final FieldCollapse collapse; @@ -238,6 +244,8 @@ private SearchRequest(Builder builder) { this.analyzer = builder.analyzer; this.batchedReduceSize = builder.batchedReduceSize; this.ccsMinimizeRoundtrips = builder.ccsMinimizeRoundtrips; + this.phaseTook = builder.phaseTook; + this.pipeline = builder.pipeline; this.collapse = builder.collapse; this.defaultOperator = builder.defaultOperator; this.df = builder.df; @@ -376,6 +384,27 @@ public final Boolean ccsMinimizeRoundtrips() { return this.ccsMinimizeRoundtrips; } + /** + * Indicates whether search phase took times should be returned + * in SearchResponse + *
+ * API name: {@code phase_took} + */ + @Nullable + public final Boolean phaseTook() { + return this.phaseTook; + } + + /** + * Specifies search pipeline name + *
+ * API name: {@code pipeline}
+ */
+ @Nullable
+ public final String pipeline() {
+ return this.pipeline;
+ }
+
/**
* API name: {@code collapse}
*/
@@ -1083,6 +1112,8 @@ public Builder toBuilder() {
.analyzer(analyzer)
.batchedReduceSize(batchedReduceSize)
.ccsMinimizeRoundtrips(ccsMinimizeRoundtrips)
+ .phaseTook(phaseTook)
+ .pipeline(pipeline)
.collapse(collapse)
.defaultOperator(defaultOperator)
.df(df)
@@ -1161,6 +1192,12 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder
+ * API name: {@code phase_took}
+ */
+ public final Builder phaseTook(@Nullable Boolean value) {
+ this.phaseTook = value;
+ return this;
+ }
+
+ /**
+ * Specifies search pipeline name
+ *
+ * API name: {@code pipeline}
+ */
+ public final Builder pipeline(@Nullable String value) {
+ this.pipeline = value;
+ return this;
+ }
+
/**
* API name: {@code collapse}
*/
@@ -2353,6 +2411,12 @@ protected static void setupSearchRequestDeserializer(ObjectDeserializer
+ * API name: {@code phase_took}
+ */
+ @Nullable
+ public final Boolean phaseTook() {
+ return this.phaseTook;
+ }
+
+ /**
+ * Specifies search pipeline name
+ *
+ * API name: {@code pipeline}
+ */
+ @Nullable
+ public final String pipeline() {
+ return this.pipeline;
+ }
+
/**
* Whether to expand wildcard expression to concrete indices that are open,
* closed or both.
@@ -334,6 +363,8 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
public Builder toBuilder() {
return new Builder().allowNoIndices(allowNoIndices)
.ccsMinimizeRoundtrips(ccsMinimizeRoundtrips)
+ .phaseTook(phaseTook)
+ .pipeline(pipeline)
.expandWildcards(expandWildcards)
.explain(explain)
.id(id)
@@ -362,6 +393,12 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder
+ * API name: {@code phase_took}
+ */
+ public final Builder phaseTook(@Nullable Boolean value) {
+ this.phaseTook = value;
+ return this;
+ }
+
+ /**
+ * Specifies search pipeline name
+ *
+ * API name: {@code pipeline}
+ */
+ public final Builder pipeline(@Nullable String value) {
+ this.pipeline = value;
+ return this;
+ }
+
/**
* Whether to expand wildcard expression to concrete indices that are open,
* closed or both.
@@ -700,6 +758,12 @@ protected static void setupSearchTemplateRequestDeserializer(ObjectDeserializer<
if (request.ccsMinimizeRoundtrips != null) {
params.put("ccs_minimize_roundtrips", String.valueOf(request.ccsMinimizeRoundtrips));
}
+ if (request.phaseTook != null) {
+ params.put("phase_took", String.valueOf(request.phaseTook));
+ }
+ if (request.pipeline != null) {
+ params.put("search_pipeline", request.pipeline);
+ }
if (request.routing != null) {
params.put("routing", request.routing);
}
diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchRequestTest.java
index 0b3c91f3c8..07eda7fce0 100644
--- a/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchRequestTest.java
+++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchRequestTest.java
@@ -25,6 +25,24 @@ public void ext() {
assertEquals("{\"ext\":{\"similarity\":{\"fields\":[\"name\"]}}}", toJson(request));
}
+ @Test
+ public void phaseTook() {
+ SearchRequest request = new SearchRequest.Builder().phaseTook(true).build();
+
+ assertEquals("{}", toJson(request));
+ assertEquals(true, request.phaseTook());
+ assertTrue(Boolean.parseBoolean(SearchRequest._ENDPOINT.queryParameters(request).get("phase_took")));
+ }
+
+ @Test
+ public void pipeline() {
+ SearchRequest request = new SearchRequest.Builder().pipeline("my_pipeline").build();
+
+ assertEquals("{}", toJson(request));
+ assertEquals("my_pipeline", request.pipeline());
+ assertEquals("my_pipeline", SearchRequest._ENDPOINT.queryParameters(request).get("search_pipeline"));
+ }
+
@Test
public void toBuilder() {
SearchRequest origin = new SearchRequest.Builder().index("index").build();
diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchTemplateRequestTest.java
index 4047bf8051..0e70e32c13 100644
--- a/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchTemplateRequestTest.java
+++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/SearchTemplateRequestTest.java
@@ -8,10 +8,28 @@
package org.opensearch.client.opensearch.core;
-import org.junit.Assert;
import org.junit.Test;
+import org.opensearch.client.opensearch.model.ModelTestCase;
-public class SearchTemplateRequestTest extends Assert {
+public class SearchTemplateRequestTest extends ModelTestCase {
+
+ @Test
+ public void phaseTook() {
+ SearchTemplateRequest request = new SearchTemplateRequest.Builder().phaseTook(true).build();
+
+ assertEquals("{}", toJson(request));
+ assertEquals(true, request.phaseTook());
+ assertTrue(Boolean.parseBoolean(SearchTemplateRequest._ENDPOINT.queryParameters(request).get("phase_took")));
+ }
+
+ @Test
+ public void pipeline() {
+ SearchTemplateRequest request = new SearchTemplateRequest.Builder().pipeline("my_pipeline").build();
+
+ assertEquals("{}", toJson(request));
+ assertEquals("my_pipeline", request.pipeline());
+ assertEquals("my_pipeline", SearchTemplateRequest._ENDPOINT.queryParameters(request).get("search_pipeline"));
+ }
@Test
public void toBuilder() {
expandWildcards;
@@ -424,6 +461,27 @@ public final Builder ccsMinimizeRoundtrips(@Nullable Boolean value) {
return this;
}
+ /**
+ * Indicates whether search phase took times should be returned
+ * in SearchResponse
+ *