Skip to content

Commit

Permalink
Fix MultisearchBody as well
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Oct 9, 2024
1 parent 54e62d4 commit 055224a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
- Added `hashCode` and `equals` implementations ([#312](https://github.com/opensearch-project/opensearch-java/pull/312))
- Added `sortVals` to `Hit` to allow retrieving non-string sort values ([#1224](https://github.com/opensearch-project/opensearch-java/pull/1224))
- Added `searchAfterVals` to `MultisearchBody` to allow passing arbitrary `FieldValue`s to `search_after` ([#1224](https://github.com/opensearch-project/opensearch-java/pull/1224))

### Dependencies
- Bumps `org.junit:junit-bom` from 5.10.3 to 5.11.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Map;
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;
Expand All @@ -44,11 +45,13 @@
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;
import org.opensearch.client.opensearch._types.query_dsl.FieldAndFormat;
import org.opensearch.client.opensearch._types.query_dsl.Query;
import org.opensearch.client.opensearch.core.SearchRequest;
import org.opensearch.client.opensearch.core.search.FieldCollapse;
import org.opensearch.client.opensearch.core.search.Highlight;
import org.opensearch.client.opensearch.core.search.Rescore;
Expand Down Expand Up @@ -77,7 +80,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 @@ -201,8 +204,19 @@ public final Query postFilter() {

/**
* API name: {@code search_after}
*
* <p><b>NOTE: In version 3.0.0 of opensearch-java, this method will instead return a {@code List<FieldValue>}.</b></p>
*/
public final List<String> searchAfter() {
return this.searchAfter.stream().map(FieldValue::_toJsonString).collect(Collectors.toList());
}

/**
* API name: {@code search_after}
*
* <p><b>NOTE: In version 3.0.0 of opensearch-java, this method will be renamed to replace {@link #searchAfter()}.</b></p>
*/
public final List<FieldValue> searchAfterVals() {
return this.searchAfter;
}

Expand Down Expand Up @@ -407,8 +421,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 +592,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 @@ -715,18 +729,46 @@ public final Builder postFilter(Function<Query.Builder, ObjectBuilder<Query>> fn
* API name: {@code search_after}
* <p>
* Adds all elements of <code>list</code> to <code>searchAfter</code>.
*
* <p><b>NOTE: In version 3.0.0 of opensearch-java, this method will instead accept a {@code List<FieldValue>}.</b></p>
*/
public final Builder searchAfter(List<String> list) {
this.searchAfter = _listAddAll(this.searchAfter, list);
this.searchAfter = _listAddAll(this.searchAfter, FieldValue::of, list);
return this;
}

/**
* API name: {@code search_after}
* <p>
* Adds one or more values to <code>searchAfter</code>.
*
* <p><b>NOTE: In version 3.0.0 of opensearch-java, this method will instead accept values of type {@code FieldValue}.</b></p>
*/
public final Builder searchAfter(String value, String... values) {
this.searchAfter = _listAdd(this.searchAfter, FieldValue::of, value, values);
return this;
}

/**
* API name: {@code search_after}
* <p>
* Adds all elements of <code>list</code> to <code>searchAfter</code>.
*
* <p><b>NOTE: In version 3.0.0 of opensearch-java, this method will be renamed to replace {@link #searchAfter(List)}.</b></p>
*/
public final Builder searchAfterVals(List<FieldValue> list) {
this.searchAfter = _listAddAll(this.searchAfter, list);
return this;
}

/**
* API name: {@code search_after}
* <p>
* Adds one or more values to <code>searchAfter</code>.
*
* <p><b>NOTE: In version 3.0.0 of opensearch-java, this method will be renamed to replace {@link #searchAfter(String, String...)}.</b></p>
*/
public final Builder searchAfterVals(FieldValue value, FieldValue... values) {
this.searchAfter = _listAdd(this.searchAfter, value, values);
return this;
}
Expand Down Expand Up @@ -1092,7 +1134,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::searchAfterVals, 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

0 comments on commit 055224a

Please sign in to comment.