Skip to content

Commit

Permalink
Changed SearchAfter field type to FieldValue instead of String (#769)
Browse files Browse the repository at this point in the history
* Changed SearchAfter of SearchRequest type to FieldValue instead of String

Signed-off-by: channel-dante <[email protected]>

* apply spotlessApply

Signed-off-by: channel-dante <[email protected]>

* move log from 2.x to 3.0 on changelog

Signed-off-by: channel-dante <[email protected]>

* add UPGRADING.md

Signed-off-by: channel-dante <[email protected]>

* update UPGRADING.md

Signed-off-by: channel-dante <[email protected]>

---------

Signed-off-by: channel-dante <[email protected]>
  • Loading branch information
channel-dante authored Dec 26, 2023
1 parent 3f9a00c commit 3738026
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This section is for maintaining a changelog for all breaking changes for the cli

### Changed
- Migrate client transports to Apache HttpClient / Core 5.x ([#246](https://github.com/opensearch-project/opensearch-java/pull/246))
- Changed SearchAfter of SearchRequest type to FieldValue instead of String ([#769](https://github.com/opensearch-project/opensearch-java/pull/769))

### Deprecated
- Deprecate RestClientTransport ([#536](https://github.com/opensearch-project/opensearch-java/pull/536))
Expand Down
20 changes: 20 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# UPGRADING

## [UPGRADING 2.x to 3.0]
### SearchAfter of SearchRequest type
- Changed SearchAfter of SearchRequest type to FieldValue instead of String ([#769](https://github.com/opensearch-project/opensearch-java/pull/769))
- Consider using `FieldValue.of` to make string type values compatible.

Before:
```
.searchAfter("string")
.searchAfter("string1", "string2")
.searchAfter(List.of("String"))
```

After:
```
.searchAfter(FieldValue.of("string"))
.searchAfter(FieldValue.of("string1"), FieldValue.of("string2"))
.searchAfter(List.of(FieldValue.of("String")))
```
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.opensearch._types.ErrorResponse;
import org.opensearch.client.opensearch._types.ExpandWildcard;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch._types.RequestBase;
import org.opensearch.client.opensearch._types.ScriptField;
import org.opensearch.client.opensearch._types.SearchType;
Expand Down Expand Up @@ -184,7 +185,7 @@ public class SearchRequest extends RequestBase implements JsonpSerializable {
@Nullable
private final Time scroll;

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

@Nullable
private final SearchType searchType;
Expand Down Expand Up @@ -678,7 +679,7 @@ public final Time scroll() {
/**
* API name: {@code search_after}
*/
public final List<String> searchAfter() {
public final List<FieldValue> searchAfter() {
return this.searchAfter;
}

Expand Down Expand Up @@ -966,8 +967,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 @@ -1173,7 +1174,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<S
private Time scroll;

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

@Nullable
private SearchType searchType;
Expand Down Expand Up @@ -1860,7 +1861,7 @@ public final Builder scroll(Function<Time.Builder, ObjectBuilder<Time>> 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 @@ -1870,7 +1871,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 @@ -2142,7 +2143,7 @@ protected static void setupSearchRequestDeserializer(ObjectDeserializer<SearchRe
op.add(Builder::rescore, JsonpDeserializer.arrayDeserializer(Rescore._DESERIALIZER), "rescore");
op.add(Builder::runtimeMappings, JsonpDeserializer.stringMapDeserializer(RuntimeField._DESERIALIZER), "runtime_mappings");
op.add(Builder::scriptFields, JsonpDeserializer.stringMapDeserializer(ScriptField._DESERIALIZER), "script_fields");
op.add(Builder::searchAfter, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "search_after");
op.add(Builder::searchAfter, JsonpDeserializer.arrayDeserializer(FieldValue._DESERIALIZER), "search_after");
op.add(Builder::seqNoPrimaryTerm, JsonpDeserializer.booleanDeserializer(), "seq_no_primary_term");
op.add(Builder::size, JsonpDeserializer.integerDeserializer(), "size");
op.add(Builder::slice, SlicedScroll._DESERIALIZER, "slice");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.opensearch.client.opensearch.core;

import org.junit.Test;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SearchRequestTest extends ModelTestCase {
@Test
public void afterSearch() {
SearchRequest request = new SearchRequest.Builder().searchAfter(FieldValue.of(1), FieldValue.of("string")).build();

assertEquals("{\"search_after\":[1,\"string\"]}", toJson(request));
}
}

0 comments on commit 3738026

Please sign in to comment.