public async Task CanGetAggregationsAsync()
        {
            var utcNow       = SystemClock.UtcNow;
            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1)), o => o.ImmediateConsistency());

            Assert.NotNull(yesterdayLog?.Id);

            var result = await _dailyRepository.CountBySearchAsync(null, aggregations : "cardinality:companyId max:createdUtc");

            Assert.Equal(2, result.Aggregations.Count);
            var cardinalityAgg = result.Aggregations.Cardinality("cardinality_companyId");

            Assert.NotNull(cardinalityAgg);
            Assert.Equal(1, cardinalityAgg.Value.GetValueOrDefault());

            var maxAgg = result.Aggregations.Max <DateTime>("max_createdUtc");

            Assert.NotNull(maxAgg);
            Assert.True(yesterdayLog.CreatedUtc.Subtract(maxAgg.Value).TotalSeconds < 1);
        }
Beispiel #2
0
        public async Task CanGetAggregations()
        {
            var utcNow       = SystemClock.UtcNow;
            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1)));

            Assert.NotNull(yesterdayLog?.Id);

            await _client.RefreshAsync();

            var result = await _dailyRepository.CountBySearchAsync(null, aggregations : "cardinality:companyId max:createdUtc");

            Assert.Equal(2, result.Aggregations.Count);
            var cardinalityAgg = result.Aggregations.FirstOrDefault(a => a.Key == "cardinality_companyId");

            Assert.NotNull(cardinalityAgg);
            Assert.Equal(1, cardinalityAgg.Value.Value);

            var maxAgg = result.Aggregations.FirstOrDefault(a => a.Key == "max_createdUtc");

            Assert.NotNull(maxAgg);
            Assert.True(maxAgg.Value.Value.HasValue);
            Assert.True(yesterdayLog.CreatedUtc.Subtract(__unixEpoch.AddMilliseconds(maxAgg.Value.Value.Value)).TotalSeconds < 1);
        }
Beispiel #3
0
        public async Task CountByQueryWithTimeSeriesAsync()
        {
            Assert.Equal(0, await _dailyRepository.CountAsync());

            var utcNow       = SystemClock.UtcNow;
            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1)), o => o.ImmediateConsistency());

            Assert.NotNull(yesterdayLog?.Id);

            var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default, o => o.ImmediateConsistency());

            Assert.NotNull(nowLog?.Id);

            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(null, "id:test"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(null, $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "createdUtc"), $"id:{nowLog.Id}"));
            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), (LogEvent l) => l.CreatedUtc), $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), "CREATEDUTC")));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "CreatedUtc")));
        }
Beispiel #4
0
        public async Task CountByQueryWithTimeSeries()
        {
            Assert.Equal(0, await _dailyRepository.CountAsync());

            var utcNow       = SystemClock.UtcNow;
            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1)));

            Assert.NotNull(yesterdayLog?.Id);

            var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default);

            Assert.NotNull(nowLog?.Id);

            await _client.RefreshAsync();

            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(null, "id:test"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(null, $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "created"), $"id:{nowLog.Id}"));
            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), "created"), $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), "created")));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "created")));
        }