示例#1
0
        public async Task CanGetDateHistogramWithCardinalityAggregationsAsync()
        {
            const int eventCount = 100;

            await CreateDataAsync(eventCount, false);

            Log.SetLogLevel <EventRepository>(LogLevel.Trace);

            var result = await _eventRepository.CountBySearchAsync(null, $"project:{TestConstants.ProjectId}", "date:(date cardinality:id) cardinality:id");

            Assert.Equal(eventCount, result.Total);
            Assert.Equal(eventCount, result.Aggregations.DateHistogram("date_date").Buckets.Sum(t => t.Total));
            Assert.Equal(1, result.Aggregations.DateHistogram("date_date").Buckets.First().Aggregations.Count);
            Assert.Equal(eventCount, result.Aggregations.Cardinality("cardinality_id").Value.GetValueOrDefault());
            Assert.Equal(eventCount, result.Aggregations.DateHistogram("date_date").Buckets.Sum(t => t.Aggregations.Cardinality("cardinality_id").Value.GetValueOrDefault()));

            var stacks = await _stackRepository.GetByOrganizationIdAsync(TestConstants.OrganizationId, new PagingOptions().WithLimit(100));

            foreach (var stack in stacks.Documents)
            {
                var stackResult = await _eventRepository.CountBySearchAsync(null, $"stack:{stack.Id}", "cardinality:id");

                Assert.Equal(stack.TotalOccurrences, stackResult.Total);
                Assert.Equal(stack.TotalOccurrences, stackResult.Aggregations.Cardinality("cardinality_id").Value.GetValueOrDefault());
            }
        }
        public async Task CanFindManyAsync()
        {
            await ResetAsync();

            await _repository.RemoveAllAsync();

            await _client.RefreshAsync();

            Assert.Equal(0, await _repository.CountAsync());

            await _repository.AddAsync(StackData.GenerateSampleStacks());

            await _client.RefreshAsync();

            var stacks = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId, new PagingOptions().WithPage(1).WithLimit(1));

            Assert.NotNull(stacks);
            Assert.Equal(3, stacks.Total);
            Assert.Equal(1, stacks.Documents.Count);

            var stacks2 = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId, new PagingOptions().WithPage(2).WithLimit(1));

            Assert.NotNull(stacks);
            Assert.Equal(1, stacks.Documents.Count);

            Assert.NotEqual(stacks.Documents.First().Id, stacks2.Documents.First().Id);

            stacks = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId);

            Assert.NotNull(stacks);
            Assert.Equal(3, stacks.Documents.Count);

            await _repository.RemoveAsync(stacks.Documents);

            await _client.RefreshAsync();

            Assert.Equal(0, await _repository.CountAsync());
            await _repository.RemoveAllAsync();

            await _client.RefreshAsync();
        }