From 766b6ecdb532ec332a18099b91b67798d4eaec03 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 4 Apr 2024 14:30:41 -0400 Subject: [PATCH] Add missed fields to MultisearchBody: ext, rescore and to SearchRequest: ext (#918) Signed-off-by: Andriy Redko --- CHANGELOG.md | 1 + .../client/opensearch/core/SearchRequest.java | 50 ++++++++- .../core/msearch/MultisearchBody.java | 100 ++++++++++++++++++ .../opensearch/core/SearchRequestTest.java | 12 +++ .../integTest/AbstractSearchRequestIT.java | 18 ++++ 5 files changed, 180 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09bf98d9e8..1f39926c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Added - Add missed fields to MultisearchBody: seqNoPrimaryTerm, storedFields, explain, fields, indicesBoost ([#914](https://github.com/opensearch-project/opensearch-java/pull/914)) - Add missed fields to MultisearchBody: collapse, version, timeout ([#916](https://github.com/opensearch-project/opensearch-java/pull/916) +- Add missed fields to MultisearchBody: ext, rescore and to SearchRequest: ext ([#918](https://github.com/opensearch-project/opensearch-java/pull/918) ### Dependencies - Bumps `io.github.classgraph:classgraph` from 4.8.161 to 4.8.165 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 0032c6cce5..9ab808705a 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 @@ -39,6 +39,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; @@ -59,6 +60,7 @@ import org.opensearch.client.opensearch._types.query_dsl.FieldAndFormat; import org.opensearch.client.opensearch._types.query_dsl.Operator; import org.opensearch.client.opensearch._types.query_dsl.Query; +import org.opensearch.client.opensearch.core.SearchTemplateRequest.Builder; import org.opensearch.client.opensearch.core.search.FieldCollapse; import org.opensearch.client.opensearch.core.search.Highlight; import org.opensearch.client.opensearch.core.search.Pit; @@ -223,6 +225,8 @@ public class SearchRequest extends RequestBase implements JsonpSerializable { @Nullable private final Boolean version; + private final Map ext; + // --------------------------------------------------------------------------------------------- private SearchRequest(Builder builder) { @@ -279,6 +283,7 @@ private SearchRequest(Builder builder) { this.trackScores = builder.trackScores; this.trackTotalHits = builder.trackTotalHits; this.version = builder.version; + this.ext = ApiTypeHelper.unmodifiable(builder.ext); } @@ -821,6 +826,13 @@ public final Boolean version() { return this.version; } + /** + * API name: {@code ext} + */ + public final Map ext() { + return this.ext; + } + /** * Serialize this object to JSON. */ @@ -1050,6 +1062,17 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } + if (ApiTypeHelper.isDefined(this.ext)) { + generator.writeKey("ext"); + generator.writeStartObject(); + for (Map.Entry item0 : this.ext.entrySet()) { + generator.writeKey(item0.getKey()); + item0.getValue().serialize(generator, mapper); + + } + generator.writeEnd(); + } + } public Builder toBuilder() { @@ -1104,7 +1127,8 @@ public Builder toBuilder() { .timeout(timeout) .trackScores(trackScores) .trackTotalHits(trackTotalHits) - .version(version); + .version(version) + .ext(ext); } // --------------------------------------------------------------------------------------------- @@ -1270,6 +1294,9 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder ext; + /** * Indicates which source fields are returned for matching documents. These * fields are returned in the hits._source property of the search response. @@ -2152,6 +2179,26 @@ public final Builder version(@Nullable Boolean value) { return this; } + /** + * API name: {@code ext} + *

+ * Adds all entries of map to ext. + */ + public final Builder ext(Map map) { + this.ext = _mapPutAll(this.ext, map); + return this; + } + + /** + * API name: {@code ext} + *

+ * Adds an entry to ext. + */ + public final Builder ext(String key, JsonData value) { + this.ext = _mapPut(this.ext, key, value); + return this; + } + /** * Builds a {@link SearchRequest}. * @@ -2211,6 +2258,7 @@ protected static void setupSearchRequestDeserializer(ObjectDeserializer rescore; + + private final Map ext; + // --------------------------------------------------------------------------------------------- private MultisearchBody(Builder builder) { @@ -147,6 +153,8 @@ private MultisearchBody(Builder builder) { this.collapse = builder.collapse; this.version = builder.version; this.timeout = builder.timeout; + this.rescore = ApiTypeHelper.unmodifiable(builder.rescore); + this.ext = ApiTypeHelper.unmodifiable(builder.ext); } public static MultisearchBody of(Function> fn) { @@ -341,6 +349,20 @@ public final String timeout() { return this.timeout; } + /** + * API name: {@code rescore} + */ + public final List rescore() { + return this.rescore; + } + + /** + * API name: {@code ext} + */ + public final Map ext() { + return this.ext; + } + /** * Serialize this object to JSON. */ @@ -511,6 +533,27 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("timeout"); generator.write(this.timeout); } + + if (ApiTypeHelper.isDefined(this.rescore)) { + generator.writeKey("rescore"); + generator.writeStartArray(); + for (Rescore item0 : this.rescore) { + item0.serialize(generator, mapper); + + } + generator.writeEnd(); + } + + if (ApiTypeHelper.isDefined(this.ext)) { + generator.writeKey("ext"); + generator.writeStartObject(); + for (Map.Entry item0 : this.ext.entrySet()) { + generator.writeKey(item0.getKey()); + item0.getValue().serialize(generator, mapper); + + } + generator.writeEnd(); + } } // --------------------------------------------------------------------------------------------- @@ -585,6 +628,12 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder rescore; + + @Nullable + private Map ext; + /** * API name: {@code aggregations} *

@@ -965,6 +1014,55 @@ public final Builder timeout(@Nullable String value) { return this; } + /** + * API name: {@code rescore} + *

+ * Adds all elements of list to rescore. + */ + public final Builder rescore(List list) { + this.rescore = _listAddAll(this.rescore, list); + return this; + } + + /** + * API name: {@code rescore} + *

+ * Adds one or more values to rescore. + */ + public final Builder rescore(Rescore value, Rescore... values) { + this.rescore = _listAdd(this.rescore, value, values); + return this; + } + + /** + * API name: {@code rescore} + *

+ * Adds a value to rescore using a builder lambda. + */ + public final Builder rescore(Function> fn) { + return rescore(fn.apply(new Rescore.Builder()).build()); + } + + /** + * API name: {@code ext} + *

+ * Adds all entries of map to ext. + */ + public final Builder ext(Map map) { + this.ext = _mapPutAll(this.ext, map); + return this; + } + + /** + * API name: {@code ext} + *

+ * Adds an entry to ext. + */ + public final Builder ext(String key, JsonData value) { + this.ext = _mapPut(this.ext, key, value); + return this; + } + /** * Builds a {@link MultisearchBody}. * @@ -1016,6 +1114,8 @@ protected static void setupMultisearchBodyDeserializer(ObjectDeserializer r.index(index) + .sort(s -> s.field(f -> f.field("name").order(SortOrder.Asc))) + .query(b -> b.matchAll(QueryBuilders.matchAll().build())) + .ext(Map.of()) + ); + + final SearchResponse response = javaClient().search(request, ShopItem.class); + assertEquals(response.hits().hits().size(), 8); + } + private void createTestDocuments(String index) throws IOException { javaClient().create(_1 -> _1.index(index).id("1").document(createItem("hummer", "huge", "yes", 2))); javaClient().create(_1 -> _1.index(index).id("2").document(createItem("jammer", "huge", "yes", 1)));