Skip to content

Commit 409b0a2

Browse files
committed
Add missed fields to MultisearchBody: collapse, version, timeout
Signed-off-by: Andriy Redko <[email protected]>
1 parent 5714df5 commit 409b0a2

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
3535

3636
### Added
3737
- Add missed fields to MultisearchBody: seqNoPrimaryTerm, storedFields, explain, fields, indicesBoost ([#914](https://github.com/opensearch-project/opensearch-java/pull/914))
38+
- Add missed fields to MultisearchBody: collapse, version, timeout ([#916](https://github.com/opensearch-project/opensearch-java/pull/916)
3839

3940
### Dependencies
4041
- Bumps `io.github.classgraph:classgraph` from 4.8.161 to 4.8.165

java-client/src/main/java/org/opensearch/client/opensearch/core/msearch/MultisearchBody.java

+107
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.opensearch.client.opensearch._types.query_dsl.FieldAndFormat;
5050
import org.opensearch.client.opensearch._types.query_dsl.Query;
5151
import org.opensearch.client.opensearch.core.SearchRequest.Builder;
52+
import org.opensearch.client.opensearch.core.search.FieldCollapse;
5253
import org.opensearch.client.opensearch.core.search.Highlight;
5354
import org.opensearch.client.opensearch.core.search.SourceConfig;
5455
import org.opensearch.client.opensearch.core.search.Suggester;
@@ -111,6 +112,15 @@ public class MultisearchBody implements JsonpSerializable {
111112

112113
private final List<Map<String, Double>> indicesBoost;
113114

115+
@Nullable
116+
private final FieldCollapse collapse;
117+
118+
@Nullable
119+
private final Boolean version;
120+
121+
@Nullable
122+
private final String timeout;
123+
114124
// ---------------------------------------------------------------------------------------------
115125

116126
private MultisearchBody(Builder builder) {
@@ -134,6 +144,9 @@ private MultisearchBody(Builder builder) {
134144
this.explain = builder.explain;
135145
this.fields = ApiTypeHelper.unmodifiable(builder.fields);
136146
this.indicesBoost = ApiTypeHelper.unmodifiable(builder.indicesBoost);
147+
this.collapse = builder.collapse;
148+
this.version = builder.version;
149+
this.timeout = builder.timeout;
137150
}
138151

139152
public static MultisearchBody of(Function<Builder, ObjectBuilder<MultisearchBody>> fn) {
@@ -298,6 +311,36 @@ public final List<Map<String, Double>> indicesBoost() {
298311
return this.indicesBoost;
299312
}
300313

314+
/**
315+
* API name: {@code collapse}
316+
*/
317+
@Nullable
318+
public final FieldCollapse collapse() {
319+
return this.collapse;
320+
}
321+
322+
/**
323+
* If true, returns document version as part of a hit.
324+
* <p>
325+
* API name: {@code version}
326+
*/
327+
@Nullable
328+
public final Boolean version() {
329+
return this.version;
330+
}
331+
332+
/**
333+
* Specifies the period of time to wait for a response from each shard. If no
334+
* response is received before the timeout expires, the request fails and
335+
* returns an error. Defaults to no timeout.
336+
* <p>
337+
* API name: {@code timeout}
338+
*/
339+
@Nullable
340+
public final String timeout() {
341+
return this.timeout;
342+
}
343+
301344
/**
302345
* Serialize this object to JSON.
303346
*/
@@ -453,6 +496,21 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
453496
}
454497
generator.writeEnd();
455498
}
499+
500+
if (this.collapse != null) {
501+
generator.writeKey("collapse");
502+
this.collapse.serialize(generator, mapper);
503+
}
504+
505+
if (this.version != null) {
506+
generator.writeKey("version");
507+
generator.write(this.version);
508+
}
509+
510+
if (this.timeout != null) {
511+
generator.writeKey("timeout");
512+
generator.write(this.timeout);
513+
}
456514
}
457515

458516
// ---------------------------------------------------------------------------------------------
@@ -518,6 +576,15 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<M
518576
@Nullable
519577
private List<Map<String, Double>> indicesBoost;
520578

579+
@Nullable
580+
private FieldCollapse collapse;
581+
582+
@Nullable
583+
private Boolean version;
584+
585+
@Nullable
586+
private String timeout;
587+
521588
/**
522589
* API name: {@code aggregations}
523590
* <p>
@@ -861,6 +928,43 @@ public final Builder indicesBoost(Map<String, Double> value, Map<String, Double>
861928
return this;
862929
}
863930

931+
/**
932+
* API name: {@code collapse}
933+
*/
934+
public final Builder collapse(@Nullable FieldCollapse value) {
935+
this.collapse = value;
936+
return this;
937+
}
938+
939+
/**
940+
* API name: {@code collapse}
941+
*/
942+
public final Builder collapse(Function<FieldCollapse.Builder, ObjectBuilder<FieldCollapse>> fn) {
943+
return this.collapse(fn.apply(new FieldCollapse.Builder()).build());
944+
}
945+
946+
/**
947+
* If true, returns document version as part of a hit.
948+
* <p>
949+
* API name: {@code version}
950+
*/
951+
public final Builder version(@Nullable Boolean value) {
952+
this.version = value;
953+
return this;
954+
}
955+
956+
/**
957+
* Specifies the period of time to wait for a response from each shard. If no
958+
* response is received before the timeout expires, the request fails and
959+
* returns an error. Defaults to no timeout.
960+
* <p>
961+
* API name: {@code timeout}
962+
*/
963+
public final Builder timeout(@Nullable String value) {
964+
this.timeout = value;
965+
return this;
966+
}
967+
864968
/**
865969
* Builds a {@link MultisearchBody}.
866970
*
@@ -909,6 +1013,9 @@ protected static void setupMultisearchBodyDeserializer(ObjectDeserializer<Multis
9091013
JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringMapDeserializer(JsonpDeserializer.doubleDeserializer())),
9101014
"indices_boost"
9111015
);
1016+
op.add(Builder::collapse, FieldCollapse._DESERIALIZER, "collapse");
1017+
op.add(Builder::version, JsonpDeserializer.booleanDeserializer(), "version");
1018+
op.add(Builder::timeout, JsonpDeserializer.stringDeserializer(), "timeout");
9121019
}
9131020

9141021
}

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractMultiSearchRequestIT.java

+14
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.opensearch.client.opensearch.core.msearch.MultiSearchResponseItem;
3737
import org.opensearch.client.opensearch.core.msearch.MultisearchBody;
3838
import org.opensearch.client.opensearch.core.msearch.RequestItem;
39+
import org.opensearch.client.opensearch.core.search.FieldCollapse;
3940
import org.opensearch.client.opensearch.core.search.Highlight;
4041
import org.opensearch.client.opensearch.core.search.HighlightField;
4142
import org.opensearch.client.opensearch.core.search.Hit;
@@ -269,6 +270,19 @@ public void shouldReturnMultiSearchesIndicesBoost() throws Exception {
269270
assertEquals(3, response.responses().get(0).result().hits().hits().size());
270271
}
271272

273+
public void shouldReturnMultiSearchesCollapse() throws Exception {
274+
String index = "multiple_searches_request_indices_boost";
275+
createTestDocuments(index);
276+
277+
RequestItem sortedItemsQuery = createMSearchFuzzyRequest(
278+
b -> b.collapse(FieldCollapse.of(f -> f.field("name"))).version(true).timeout("5s")
279+
);
280+
281+
MsearchResponse<ShopItem> response = sendMSearchRequest(index, List.of(sortedItemsQuery));
282+
assertEquals(1, response.responses().size());
283+
assertEquals(3, response.responses().get(0).result().hits().hits().size());
284+
}
285+
272286
private void assertResponseSources(MultiSearchResponseItem<ShopItem> response) {
273287
List<Hit<ShopItem>> hitsWithHighlights = response.result().hits().hits();
274288
assertEquals(2, hitsWithHighlights.size());

0 commit comments

Comments
 (0)