diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/aggregations/MultiTermsAggregation.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/aggregations/MultiTermsAggregation.java index 2d8803d78..2ff782700 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/aggregations/MultiTermsAggregation.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/aggregations/MultiTermsAggregation.java @@ -23,6 +23,7 @@ package co.elastic.clients.elasticsearch._types.aggregations; +import co.elastic.clients.elasticsearch._types.SortOrder; import co.elastic.clients.json.JsonpDeserializable; import co.elastic.clients.json.JsonpDeserializer; import co.elastic.clients.json.JsonpMapper; @@ -32,6 +33,7 @@ import co.elastic.clients.util.ObjectBuilder; import jakarta.json.stream.JsonGenerator; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.function.Function; import javax.annotation.Nullable; @@ -48,12 +50,39 @@ public class MultiTermsAggregation extends BucketAggregationBase implements AggregationVariant { private final List terms; + @Nullable + private final Integer size; + + @Nullable + private final Integer shardSize; + + @Nullable + private final Boolean showTermDocCountError; + + private final List> order; + + @Nullable + private final Integer minDocCount; + + @Nullable + private final TermsAggregationCollectMode collectMode; + + @Nullable + private final Long shardMinDocCount; + // --------------------------------------------------------------------------------------------- private MultiTermsAggregation(Builder builder) { super(builder); this.terms = ApiTypeHelper.unmodifiableRequired(builder.terms, this, "terms"); + this.size = builder.size; + this.shardSize = builder.shardSize; + this.showTermDocCountError = builder.showTermDocCountError; + this.order = ApiTypeHelper.unmodifiable(builder.order); + this.minDocCount = builder.minDocCount; + this.collectMode = builder.collectMode; + this.shardMinDocCount = builder.shardMinDocCount; } @@ -76,6 +105,44 @@ public final List terms() { return this.terms; } + + @Nullable + public final Integer size() { + return this.size; + } + + /** + * API name: {@code shard_size} + */ + @Nullable + public final Integer shardSize() { + return this.shardSize; + } + + /** + * API name: {@code show_term_doc_count_error} + */ + @Nullable + public final Boolean showTermDocCountError() { + return this.showTermDocCountError; + } + + /** + * API name: {@code min_doc_count} + */ + @Nullable + public final Integer minDocCount() { + return this.minDocCount; + } + + /** + * API name: {@code collect_mode} + */ + @Nullable + public final TermsAggregationCollectMode collectMode() { + return this.collectMode; + } + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { super.serializeInternal(generator, mapper); @@ -90,6 +157,48 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } + if (this.size != null) { + generator.writeKey("size"); + generator.write(this.size); + + } + if (this.shardSize != null) { + generator.writeKey("shard_size"); + generator.write(this.shardSize); + } + if (this.showTermDocCountError != null) { + generator.writeKey("show_term_doc_count_error"); + generator.write(this.showTermDocCountError); + } + if (this.minDocCount != null) { + generator.writeKey("min_doc_count"); + generator.write(this.minDocCount); + } + if (this.collectMode != null) { + generator.writeKey("collect_mode"); + this.collectMode.serialize(generator, mapper); + } + if (this.shardMinDocCount != null) { + generator.writeKey("shard_min_doc_count"); + generator.write(this.shardMinDocCount); + } + if (ApiTypeHelper.isDefined(this.order)) { + generator.writeKey("order"); + generator.writeStartArray(); + for (Map item0 : this.order) { + generator.writeStartObject(); + if (item0 != null) { + for (Map.Entry item1 : item0.entrySet()) { + generator.writeKey(item1.getKey()); + item1.getValue().serialize(generator, mapper); + } + } + generator.writeEnd(); + + } + generator.writeEnd(); + + } } // --------------------------------------------------------------------------------------------- @@ -103,6 +212,26 @@ public static class Builder extends BucketAggregationBase.AbstractBuilder { private List terms; + @Nullable + private Integer size; + + @Nullable + private Integer shardSize; + + @Nullable + private Boolean showTermDocCountError; + + @Nullable + private List> order; + + @Nullable + private Integer minDocCount; + + @Nullable + private TermsAggregationCollectMode collectMode; + + @Nullable + private Long shardMinDocCount; /** * Required - API name: {@code terms} *

@@ -132,6 +261,64 @@ public final Builder terms(Function + */ + public final Builder order(List> list) { + this.order = _listAddAll(this.order, list); + return this; + } + + /** + * API name: {@code min_doc_count} + */ + public final Builder minDocCount(@Nullable Integer value) { + this.minDocCount = value; + return this; + } + + /** + * API name: {@code collect_mode} + */ + public final Builder collectMode(@Nullable TermsAggregationCollectMode value) { + this.collectMode = value; + return this; + } + + /** + * API name: {@code shard_min_doc_count} + */ + public final Builder shardMinDocCount(@Nullable Long value) { + this.shardMinDocCount = value; + return this; + } + @Override protected Builder self() { return this; @@ -161,6 +348,14 @@ public MultiTermsAggregation build() { protected static void setupMultiTermsAggregationDeserializer(ObjectDeserializer op) { BucketAggregationBase.setupBucketAggregationBaseDeserializer(op); op.add(Builder::terms, JsonpDeserializer.arrayDeserializer(MultiTermLookup._DESERIALIZER), "terms"); + op.add(Builder::shardSize, JsonpDeserializer.integerDeserializer(), "shard_size"); + op.add(Builder::showTermDocCountError, JsonpDeserializer.booleanDeserializer(), "show_term_doc_count_error"); + op.add(Builder::size, JsonpDeserializer.integerDeserializer(), "size"); + op.add(Builder::order, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringMapDeserializer(SortOrder._DESERIALIZER)), + "order"); + op.add(Builder::minDocCount, JsonpDeserializer.integerDeserializer(), "min_doc_count"); + op.add(Builder::collectMode, TermsAggregationCollectMode._DESERIALIZER, "collect_mode"); + op.add(Builder::shardMinDocCount, JsonpDeserializer.longDeserializer(), "shard_min_doc_count"); } diff --git a/java-client/src/test/java/co/elastic/clients/documentation/usage/MultiTermsAggregationTest.java b/java-client/src/test/java/co/elastic/clients/documentation/usage/MultiTermsAggregationTest.java new file mode 100644 index 000000000..48b2e24c4 --- /dev/null +++ b/java-client/src/test/java/co/elastic/clients/documentation/usage/MultiTermsAggregationTest.java @@ -0,0 +1,44 @@ +package co.elastic.clients.documentation.usage; + +import co.elastic.clients.elasticsearch._types.SortOrder; +import co.elastic.clients.elasticsearch._types.aggregations.Aggregation; +import co.elastic.clients.elasticsearch._types.aggregations.MultiTermLookup; +import co.elastic.clients.elasticsearch._types.aggregations.MultiTermsAggregation; +import co.elastic.clients.elasticsearch._types.aggregations.TermsAggregationCollectMode; +import co.elastic.clients.elasticsearch.core.SearchRequest; +import co.elastic.clients.elasticsearch.model.ModelTestCase; +import java.util.List; +import java.util.Map; +import org.junit.Test; + +public class MultiTermsAggregationTest extends ModelTestCase { + + @Test + public void testCreateMultiTermsAggregationWithOptionalFields() { + MultiTermsAggregation multiTermsAggregation = new MultiTermsAggregation.Builder() + .terms(new MultiTermLookup.Builder().field("field-1").build(), new MultiTermLookup.Builder().field("field-2").build()) + .size(10) + .shardSize(1) + .showTermDocCountError(false) + .order(List.of(Map.of("field", SortOrder.Asc))) + .minDocCount(1) + .shardMinDocCount(2L) + .collectMode(TermsAggregationCollectMode.DepthFirst) + .build(); + Aggregation aggregation = new Aggregation.Builder().multiTerms(multiTermsAggregation).build(); + SearchRequest request = new SearchRequest.Builder().aggregations(Map.of("multi_terms", aggregation)).build(); + String expectedValue = "{\"aggregations\":{\"multi_terms\":{\"multi_terms\":{\"terms\":[{\"field\":\"field-1\"},{\"field\":\"field-2\"}],\"size\":10,\"shard_size\":1,\"show_term_doc_count_error\":false,\"min_doc_count\":1,\"collect_mode\":\"depth_first\",\"shard_min_doc_count\":2,\"order\":[{\"field\":\"asc\"}]}}}}"; + assertEquals(expectedValue, toJson(request)); + } + + @Test + public void testcreateMultiTermsAggregationWithoutOptionFields() { + MultiTermsAggregation multiTermsAggregation = new MultiTermsAggregation.Builder() + .terms(new MultiTermLookup.Builder().field("field-1").build(), new MultiTermLookup.Builder().field("field-2").build()) + .build(); + Aggregation aggregation = new Aggregation.Builder().multiTerms(multiTermsAggregation).build(); + SearchRequest request = new SearchRequest.Builder().aggregations(Map.of("multi_terms", aggregation)).build(); + String expectedValue = "{\"aggregations\":{\"multi_terms\":{\"multi_terms\":{\"terms\":[{\"field\":\"field-1\"},{\"field\":\"field-2\"}]}}}}"; + assertEquals(expectedValue, toJson(request)); + } +} \ No newline at end of file