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

[Backport 2.x] Fix serialization of nested aggregates under SingleBucketAggregateBase (#1350) #1352

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed an issue where `FieldSort` was not implementing `SortOptionsVariant` ([#1323](https://github.com/opensearch-project/opensearch-java/pull/1323))
- Fixed `CreateSnapshotResponse` deserialization when wait_for_completion is false ([#1332](https://github.com/opensearch-project/opensearch-java/pull/1332))
- Fixed `GetSnapshotResponse` deserialization ([#1299](https://github.com/opensearch-project/opensearch-java/pull/1299))
- Fixed serialization of nested aggregates under `SingleBucketAggregateBase` ([#1350](https://github.com/opensearch-project/opensearch-java/pull/1350))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.ExternallyTaggedUnion;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.ObjectDeserializer;
Expand Down Expand Up @@ -71,8 +72,10 @@ public final long docCount() {
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

super.serializeInternal(generator, mapper);

ExternallyTaggedUnion.serializeTypedKeysInner(this.aggregations, generator, mapper);

generator.writeKey("doc_count");
generator.write(this.docCount);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.client.opensearch._types.aggregations;

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

public class FilterAggregateTest extends ModelTestCase {
@Test
public void serializesNestedAggregates() {
String json = "{\"sum#l2_result\":{\"value\":1.0},\"doc_count\":1}";
FilterAggregate aggregate = fromJson(json, FilterAggregate._DESERIALIZER);
assertEquals(json, toJson(aggregate));
}
}
Loading