Search in sources :

Example 1 with StatsAggregate

use of org.opensearch.client.opensearch._types.aggregations.StatsAggregate in project opensearch-java by opensearch-project.

the class BuiltinTypesTest method testNullableDouble.

@Test
public void testNullableDouble() {
    StatsAggregate stats;
    // Regular values
    stats = StatsAggregate.statsAggregateOf(b -> // Parent classes can't have an overloaded "of" method
    b.count(10).min(1.0).avg(1.5).max(2.0).sum(5.0));
    stats = checkJsonRoundtrip(stats, "{\"count\":10,\"min\":1.0,\"max\":2.0,\"avg\":1.5,\"sum\":5.0}");
    assertEquals(10, stats.count());
    assertEquals(1.0, stats.min(), 0.01);
    assertEquals(1.5, stats.avg(), 0.01);
    assertEquals(2.0, stats.max(), 0.01);
    assertEquals(5.0, stats.sum(), 0.01);
    // Missing values (JSON null, Java infinite)
    String json = "{\"count\":0,\"min\":null,\"max\":null,\"avg\":null,\"sum\":0.0}";
    stats = fromJson(json, StatsAggregate.class);
    assertEquals(0, stats.count());
    assertTrue(Double.isInfinite(stats.min()));
    assertEquals(0.0, stats.avg(), 0.01);
    assertTrue(Double.isInfinite(stats.max()));
    assertEquals(0.0, stats.sum(), 0.01);
    // We don't serialize finite default values as null
    assertEquals("{\"count\":0,\"min\":null,\"max\":null,\"avg\":0.0,\"sum\":0.0}", toJson(stats));
}
Also used : IndexSettings(org.opensearch.client.opensearch.indices.IndexSettings) List(java.util.List) FieldValue(org.opensearch.client.opensearch._types.FieldValue) SearchRequest(org.opensearch.client.opensearch.core.SearchRequest) SortOptions(org.opensearch.client.opensearch._types.SortOptions) SortOrder(org.opensearch.client.opensearch._types.SortOrder) StatsAggregate(org.opensearch.client.opensearch._types.aggregations.StatsAggregate) Test(org.junit.Test) StringStatsAggregate(org.opensearch.client.opensearch._types.aggregations.StringStatsAggregate) SpanGapQuery(org.opensearch.client.opensearch._types.query_dsl.SpanGapQuery) StatsAggregate(org.opensearch.client.opensearch._types.aggregations.StatsAggregate) StringStatsAggregate(org.opensearch.client.opensearch._types.aggregations.StringStatsAggregate) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Test (org.junit.Test)1 FieldValue (org.opensearch.client.opensearch._types.FieldValue)1 SortOptions (org.opensearch.client.opensearch._types.SortOptions)1 SortOrder (org.opensearch.client.opensearch._types.SortOrder)1 StatsAggregate (org.opensearch.client.opensearch._types.aggregations.StatsAggregate)1 StringStatsAggregate (org.opensearch.client.opensearch._types.aggregations.StringStatsAggregate)1 SpanGapQuery (org.opensearch.client.opensearch._types.query_dsl.SpanGapQuery)1 SearchRequest (org.opensearch.client.opensearch.core.SearchRequest)1 IndexSettings (org.opensearch.client.opensearch.indices.IndexSettings)1