diff --git a/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs b/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs index 84c4fab2870..98f0c138d72 100644 --- a/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs +++ b/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs @@ -11,6 +11,14 @@ namespace Nest { public class NodeUsageInformation { + /// + /// Aggregation usage. + /// + /// Available in Elasticsearch 7.8.0+ + /// + [DataMember(Name ="aggregations")] + public IReadOnlyDictionary> Aggregations { get; internal set; } + [DataMember(Name ="rest_actions")] public IReadOnlyDictionary RestActions { get; internal set; } diff --git a/tests/Tests/Cluster/NodesUsage/NodesUsageApiTests.cs b/tests/Tests/Cluster/NodesUsage/NodesUsageApiTests.cs index 8ca53885ac1..46905e3d452 100644 --- a/tests/Tests/Cluster/NodesUsage/NodesUsageApiTests.cs +++ b/tests/Tests/Cluster/NodesUsage/NodesUsageApiTests.cs @@ -7,8 +7,10 @@ using Elasticsearch.Net; using FluentAssertions; using Nest; +using Tests.Core.Client; using Tests.Core.Extensions; using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; using Tests.Framework.EndpointTests; using Tests.Framework.EndpointTests.TestState; @@ -24,6 +26,21 @@ public NodesUsageApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(c protected override HttpMethod HttpMethod => HttpMethod.GET; protected override string UrlPath => "/_nodes/usage"; + protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) + { + var searchResponse = client.Search(s => s + .Size(0) + .Aggregations(a => a + .Average("avg_commits", avg => avg + .Field(f => f.NumberOfCommits) + ) + ) + ); + + if (!searchResponse.IsValid) + throw new Exception($"Exception when setting up {nameof(NodesUsageApiTests)}: {searchResponse.DebugInformation}"); + } + protected override LazyResponses ClientUsage() => Calls( (client, f) => client.Nodes.Usage(), (client, f) => client.Nodes.UsageAsync(), @@ -43,9 +60,15 @@ protected override void ExpectResponse(NodesUsageResponse response) response.Nodes.Should().NotBeNull(); response.Nodes.Should().HaveCount(1); - response.Nodes.First().Value.Timestamp.Should().BeBefore(DateTimeOffset.UtcNow); - response.Nodes.First().Value.Since.Should().BeBefore(DateTimeOffset.UtcNow); - response.Nodes.First().Value.RestActions.Should().NotBeNull(); + var firstNode = response.Nodes.First(); + firstNode.Value.Timestamp.Should().BeBefore(DateTimeOffset.UtcNow); + firstNode.Value.Since.Should().BeBefore(DateTimeOffset.UtcNow); + firstNode.Value.RestActions.Should().NotBeNull(); + + if (TestClient.Configuration.InRange(">=7.8.0")) + { + firstNode.Value.Aggregations.Should().NotBeNull().And.ContainKey("avg"); + } } } }