Mocking an Aggregation

I'm trying to mock an Aggregation result for a Unit Test.

        var mockedSearchResponse = SearchResponse.of(r -> r
                .took(10)
                .timedOut(false)
                .hits(h -> h
                        .total(t -> t.value(8).relation(TotalHitsRelation.Eq))
                        .hits(Collections.emptyList()))
                .aggregations(Map.of(
                        "memUsagePctAvg", new Aggregate("avg", JsonData.of(0.01)),
                        "cpuTotalAvg", new Aggregate("avg", JsonData.of(0.0)))
                )
                .shards(s -> s
                        .total(1)
                        .failed(0)
                        .successful(1))
        );

However, there is an issue with calling new Aggregate(). It puts my "avg" kind into the _customKind field, and sets the Aggregate _kind to Kind._Custom.

Is there an example somewhere that uses the Aggregate.of() function instead.

Answering my own quetsion:

        return SearchResponse.of(r -> r
                .took(10)
                .timedOut(false)
                .hits(h -> h
                        .total(t -> t.value(5).relation(TotalHitsRelation.Eq))
                        .hits(Collections.emptyList()))
                .aggregations("cpuSystemAvg", a -> a
                        .avg(v -> v
                                .value(METRIC_VALUE)))
                .aggregations("systemLoad1", a -> a
                        .avg(v -> v
                                .value(METRIC_VALUE)))
                .aggregations("upTime", a -> a
                        .max(v -> v
                                .value(UPTIME_MSEC)))
                .shards(s -> s
                        .total(1)
                        .failed(0)
                        .successful(1))
        );

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.