diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java index eb54fe101b..54ca6915d1 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java @@ -37,6 +37,7 @@ import java.util.Map; import java.util.function.Function; import java.util.function.Supplier; +import java.util.stream.Collectors; import javax.annotation.Nullable; import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonpDeserializer; @@ -46,6 +47,7 @@ import org.opensearch.client.json.ObjectBuilderDeserializer; import org.opensearch.client.json.ObjectDeserializer; import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.opensearch._types.FieldValue; import org.opensearch.client.opensearch.core.explain.Explanation; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; @@ -98,7 +100,7 @@ public class Hit implements PlainJsonSerializable { @Nullable private final Long version; - private final List sort; + private final List sort; @Nullable private final JsonpSerializer tDocumentSerializer; @@ -265,8 +267,19 @@ public final Long version() { /** * API name: {@code sort} + * + *

NOTE: In version 3.0.0 of opensearch-java, this method will instead return a {@code List}.

*/ public final List sort() { + return this.sort.stream().map(FieldValue::_toJsonString).collect(Collectors.toList()); + } + + /** + * API name: {@code sort} + * + *

NOTE: In version 3.0.0 of opensearch-java, this method will be renamed to replace {@link #sort()}.

+ */ + public final List sortVals() { return this.sort; } @@ -404,8 +417,8 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { if (ApiTypeHelper.isDefined(this.sort)) { generator.writeKey("sort"); generator.writeStartArray(); - for (String item0 : this.sort) { - generator.write(item0); + for (FieldValue item0 : this.sort) { + item0.serialize(generator, mapper); } generator.writeEnd(); @@ -474,7 +487,7 @@ public static class Builder extends ObjectBuilderBase implements Obje private Long version; @Nullable - private List sort; + private List sort; @Nullable private JsonpSerializer tDocumentSerializer; @@ -702,9 +715,11 @@ public final Builder version(@Nullable Long value) { * API name: {@code sort} *

* Adds all elements of list to sort. + * + *

NOTE: In version 3.0.0 of opensearch-java, this method will instead accept a {@code List}.

*/ public final Builder sort(List list) { - this.sort = _listAddAll(this.sort, list); + this.sort = _listAddAll(this.sort, FieldValue::of, list); return this; } @@ -712,8 +727,34 @@ public final Builder sort(List list) { * API name: {@code sort} *

* Adds one or more values to sort. + * + *

NOTE: In version 3.0.0 of opensearch-java, this method will instead accept a {@code List}.

*/ public final Builder sort(String value, String... values) { + this.sort = _listAdd(this.sort, FieldValue::of, value, values); + return this; + } + + /** + * API name: {@code sort} + *

+ * Adds all elements of list to sort. + * + *

NOTE: In version 3.0.0 of opensearch-java, this method will be renamed to replace {@link #sort(List)}.

+ */ + public final Builder sortVals(List list) { + this.sort = _listAddAll(this.sort, list); + return this; + } + + /** + * API name: {@code sort} + *

+ * Adds one or more values to sort. + * + *

NOTE: In version 3.0.0 of opensearch-java, this method will be renamed to replace {@link #sort(String, String...)}.

+ */ + public final Builder sortVals(FieldValue value, FieldValue... values) { this.sort = _listAdd(this.sort, value, values); return this; } @@ -778,7 +819,7 @@ protected static void setupHitDeserializer( op.add(Builder::seqNo, JsonpDeserializer.longDeserializer(), "_seq_no"); op.add(Builder::primaryTerm, JsonpDeserializer.longDeserializer(), "_primary_term"); op.add(Builder::version, JsonpDeserializer.longDeserializer(), "_version"); - op.add(Builder::sort, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringOrNullDeserializer()), "sort"); + op.add(Builder::sortVals, JsonpDeserializer.arrayDeserializer(FieldValue._DESERIALIZER), "sort"); }