diff --git a/src/Nest/Aggregations/AggregationContainer.cs b/src/Nest/Aggregations/AggregationContainer.cs index 9f458c98e9d..7fa1e8d55cc 100644 --- a/src/Nest/Aggregations/AggregationContainer.cs +++ b/src/Nest/Aggregations/AggregationContainer.cs @@ -295,7 +295,15 @@ public class AggregationContainer : IAggregationContainer { public IAdjacencyMatrixAggregation AdjacencyMatrix { get; set; } - public AggregationDictionary Aggregations { get; set; } + // This is currently used to support deserializing the response from SQL Translate, + // which forms a response which uses "aggregations", rather than "aggs". Longer term + // it would be preferred to address that in Elasticsearch itself. + [DataMember(Name = "aggregations")] + private AggregationDictionary _aggs; + + // ReSharper disable once ConvertToAutoProperty + public AggregationDictionary Aggregations { get => _aggs; set => _aggs = value; } + public IAverageAggregation Average { get; set; } public IAverageBucketAggregation AverageBucket { get; set; } diff --git a/src/Nest/Search/Search/SearchRequest.cs b/src/Nest/Search/Search/SearchRequest.cs index 06ae8d30a32..f2b846e852d 100644 --- a/src/Nest/Search/Search/SearchRequest.cs +++ b/src/Nest/Search/Search/SearchRequest.cs @@ -180,8 +180,15 @@ public partial interface ISearchRequest : ISearchRequest { } [DataContract] public partial class SearchRequest { + // This is currently used to support deserializing the response from SQL Translate, + // which forms a response which uses "aggregations", rather than "aggs". Longer term + // it would be preferred to address that in Elasticsearch itself. + [DataMember(Name = "aggregations")] + private AggregationDictionary _aggs; + /// - public AggregationDictionary Aggregations { get; set; } + // ReSharper disable once ConvertToAutoProperty + public AggregationDictionary Aggregations { get => _aggs; set => _aggs = value; } /// public IFieldCollapse Collapse { get; set; } /// diff --git a/tests/Tests.Reproduce/GithubIssue5201.cs b/tests/Tests.Reproduce/GithubIssue5201.cs new file mode 100644 index 00000000000..5085894d2c5 --- /dev/null +++ b/tests/Tests.Reproduce/GithubIssue5201.cs @@ -0,0 +1,55 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using System; +using System.Text; +using System.Threading.Tasks; +using Elastic.Elasticsearch.Xunit.XunitPlumbing; +using Elastic.Transport; +using Elasticsearch.Net; +using FluentAssertions; +using Nest; + +namespace Tests.Reproduce +{ + public class GitHubIssue5201 + { + private static readonly byte[] ResponseBytes = Encoding.UTF8.GetBytes(@"{ + ""size"" : 0, + ""_source"" : false, + ""stored_fields"" : ""_none_"", + ""aggregations"" : { + ""groupby"" : { + ""composite"" : { + ""size"" : 1000, + ""sources"" : [ + { + ""ccf51bfa"" : { + ""terms"" : { + ""field"" : ""id"", + ""missing_bucket"" : true, + ""order"" : ""asc"" + } + } + } + ] + } + } + } + }"); + + [U] public async Task DeserializeAggregations() + { + var pool = new SingleNodeConnectionPool(new Uri($"http://localhost:9200")); + var settings = new ConnectionSettings(pool, new InMemoryConnection(ResponseBytes)); + var client = new ElasticClient(settings); + + var translateResponseAsync = await client.Sql.TranslateAsync(t => t.Query("select UDFvarchar1, count(1) from interactions group by UDFvarchar1 order by UDFvarchar1")); + translateResponseAsync.Result.Aggregations.Should().NotBeNull(); + + var translateResponse = client.Sql.Translate(t => t.Query("select UDFvarchar1, count(1) from interactions group by UDFvarchar1 order by UDFvarchar1")); + translateResponse.Result.Aggregations.Should().NotBeNull(); + } + } +}