Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change sort and searchAfter to List<FieldValue> #1225

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ This section is for maintaining a changelog for all breaking changes for the cli
- Changed type of `DanglingIndex`'s `creationDateMillis` field from `String` to `long` ([#1124](https://github.com/opensearch-project/opensearch-java/pull/1124))
- Changed type of `ShardStatistics`'s `total`, `successful`, `failed` & `skipped` fields from `Number` to `int/Integer` ([#1158](https://github.com/opensearch-project/opensearch-java/pull/1158))
- Unified `tasks.Info` and `tasks.State` classes into `tasks.TaskInfo` ([#1187](https://github.com/opensearch-project/opensearch-java/pull/1187))
- Changed type of `Hit`'s `sort` field from `List<String>` to `List<FieldValue>` ([#1225](https://github.com/opensearch-project/opensearch-java/pull/1225))
- Changed type of `MultisearchBody`'s `searchAfter` field from `List<String>` to `List<FieldValue>` ([#1225](https://github.com/opensearch-project/opensearch-java/pull/1225))

### Deprecated
- Deprecate RestClientTransport ([#536](https://github.com/opensearch-project/opensearch-java/pull/536))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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._types.ScriptField;
import org.opensearch.client.opensearch._types.SortOptions;
import org.opensearch.client.opensearch._types.aggregations.Aggregation;
Expand Down Expand Up @@ -77,7 +78,7 @@ public class MultisearchBody implements PlainJsonSerializable {
@Nullable
private final Query postFilter;

private final List<String> searchAfter;
private final List<FieldValue> searchAfter;

@Nullable
private final Integer size;
Expand Down Expand Up @@ -202,7 +203,7 @@ public final Query postFilter() {
/**
* API name: {@code search_after}
*/
public final List<String> searchAfter() {
public final List<FieldValue> searchAfter() {
reta marked this conversation as resolved.
Show resolved Hide resolved
return this.searchAfter;
}

Expand Down Expand Up @@ -407,8 +408,8 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
if (ApiTypeHelper.isDefined(this.searchAfter)) {
generator.writeKey("search_after");
generator.writeStartArray();
for (String item0 : this.searchAfter) {
generator.write(item0);
for (FieldValue item0 : this.searchAfter) {
item0.serialize(generator, mapper);

}
generator.writeEnd();
Expand Down Expand Up @@ -578,7 +579,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<M
private Query postFilter;

@Nullable
private List<String> searchAfter;
private List<FieldValue> searchAfter;

@Nullable
private Integer size;
Expand Down Expand Up @@ -716,7 +717,7 @@ public final Builder postFilter(Function<Query.Builder, ObjectBuilder<Query>> fn
* <p>
* Adds all elements of <code>list</code> to <code>searchAfter</code>.
*/
public final Builder searchAfter(List<String> list) {
public final Builder searchAfter(List<FieldValue> list) {
this.searchAfter = _listAddAll(this.searchAfter, list);
return this;
}
Expand All @@ -726,7 +727,7 @@ public final Builder searchAfter(List<String> list) {
* <p>
* Adds one or more values to <code>searchAfter</code>.
*/
public final Builder searchAfter(String value, String... values) {
public final Builder searchAfter(FieldValue value, FieldValue... values) {
this.searchAfter = _listAdd(this.searchAfter, value, values);
return this;
}
Expand Down Expand Up @@ -1092,7 +1093,7 @@ protected static void setupMultisearchBodyDeserializer(ObjectDeserializer<Multis
op.add(Builder::from, JsonpDeserializer.integerDeserializer(), "from");
op.add(Builder::minScore, JsonpDeserializer.doubleDeserializer(), "min_score");
op.add(Builder::postFilter, Query._DESERIALIZER, "post_filter");
op.add(Builder::searchAfter, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "search_after");
op.add(Builder::searchAfter, JsonpDeserializer.arrayDeserializer(FieldValue._DESERIALIZER), "search_after");
op.add(Builder::size, JsonpDeserializer.integerDeserializer(), "size");
op.add(Builder::sort, JsonpDeserializer.arrayDeserializer(SortOptions._DESERIALIZER), "sort");
op.add(Builder::trackScores, JsonpDeserializer.booleanDeserializer(), "track_scores");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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;
Expand Down Expand Up @@ -98,7 +99,7 @@ public class Hit<TDocument> implements PlainJsonSerializable {
@Nullable
private final Long version;

private final List<String> sort;
private final List<FieldValue> sort;

@Nullable
private final JsonpSerializer<TDocument> tDocumentSerializer;
Expand Down Expand Up @@ -266,7 +267,7 @@ public final Long version() {
/**
* API name: {@code sort}
*/
public final List<String> sort() {
public final List<FieldValue> sort() {
return this.sort;
}

Expand Down Expand Up @@ -404,8 +405,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();
Expand Down Expand Up @@ -474,7 +475,7 @@ public static class Builder<TDocument> extends ObjectBuilderBase implements Obje
private Long version;

@Nullable
private List<String> sort;
private List<FieldValue> sort;

@Nullable
private JsonpSerializer<TDocument> tDocumentSerializer;
Expand Down Expand Up @@ -703,7 +704,7 @@ public final Builder<TDocument> version(@Nullable Long value) {
* <p>
* Adds all elements of <code>list</code> to <code>sort</code>.
*/
public final Builder<TDocument> sort(List<String> list) {
public final Builder<TDocument> sort(List<FieldValue> list) {
this.sort = _listAddAll(this.sort, list);
return this;
}
Expand All @@ -713,7 +714,7 @@ public final Builder<TDocument> sort(List<String> list) {
* <p>
* Adds one or more values to <code>sort</code>.
*/
public final Builder<TDocument> sort(String value, String... values) {
public final Builder<TDocument> sort(FieldValue value, FieldValue... values) {
this.sort = _listAdd(this.sort, value, values);
return this;
}
Expand Down Expand Up @@ -778,7 +779,7 @@ protected static <TDocument> 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::sort, JsonpDeserializer.arrayDeserializer(FieldValue._DESERIALIZER), "sort");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void shouldReturnMultiSearchesSearchAfter() throws Exception {
assertEquals(1, response.responses().size());
assertEquals(3, response.responses().get(0).result().hits().hits().size());

List<String> sorts = response.responses().get(0).result().hits().hits().get(1).sort();
List<FieldValue> sorts = response.responses().get(0).result().hits().hits().get(1).sort();
RequestItem sortedAfterItemsQuery = createMSearchSortedFuzzyRequest(b -> b.searchAfter(sorts));

MsearchResponse<ShopItem> response2 = sendMSearchRequest(index, List.of(sortedAfterItemsQuery));
Expand Down
Loading