Пример #1
0
        public async Task AggregateAsyncByDescriptorShouldSucceed()
        {
            var descriptor1 = new SearchDescriptor <MockDocument>();
            var descriptor2 = new SearchDescriptor <MockDocument>();

            descriptor1
            .Aggregations(a => a
                          .Terms("is_active",
                                 t => t
                                 .Field(f => f.IsActive)
                                 )
                          );
            descriptor2
            .Aggregations(a => a
                          .Terms("is_active",
                                 t => t
                                 .Field(f => f.IsActive)
                                 )
                          )
            .Query(q => q
                   .Term(t => t
                         .Field(f => f.Name)
                         .Value("xyz")
                         )
                   )
            ;

            var aggs1 = await _mockRepo.AggregateAsync(descriptor1);

            var aggs2 = await _mockRepo.AggregateAsync(descriptor2);

            var res1 = new List <dynamic>();

            foreach (var bucket in (List <IBucket>)((BucketAggregate)aggs1.Aggregations["is_active"]).Items)
            {
                res1.Add(new {
                    ((KeyedBucket <object>)bucket).Key,
                    Count = ((KeyedBucket <object>)bucket).DocCount
                });
            }

            Assert.NotNull(aggs1);
            Assert.True(aggs1.Aggregations.ContainsKey("is_active"));

            Assert.NotEmpty(res1);
            Assert.Equal(2, res1.Count);

            Assert.NotNull(aggs2);
            Assert.False(aggs2.Aggregations.ContainsKey("is_active"));
        }