Skip to content

Commit d1ac016

Browse files
committed
Add start and end date to ElasticSearch where clause.
1 parent 6c35224 commit d1ac016

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Serilog.Ui.ElasticSearchProvider/ElasticSearchDbDataProvider.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ public ElasticSearchDbDataProvider(IElasticClient client, ElasticSearchDbOptions
2727
DateTime? startDate = null,
2828
DateTime? endDate = null)
2929
{
30-
return GetLogsAsync(page - 1, count, level, searchCriteria);
30+
return GetLogsAsync(page - 1, count, level, searchCriteria, startDate, endDate);
3131
}
3232

3333
private async Task<(IEnumerable<LogModel>, int)> GetLogsAsync(
3434
int page,
3535
int count,
3636
string level,
3737
string searchCriteria,
38+
DateTime? startDate = null,
39+
DateTime? endDate = null,
3840
CancellationToken cancellationToken = default)
3941
{
4042
var descriptor = new SearchDescriptor<ElasticSearchDbLogModel>()
@@ -58,6 +60,14 @@ public ElasticSearchDbDataProvider(IElasticClient client, ElasticSearchDbOptions
5860
)
5961
);
6062

63+
if (startDate != null)
64+
descriptor.Query(q => q.DateRange(dr =>
65+
dr.Field(f => f.Timestamp).GreaterThanOrEquals(startDate)));
66+
67+
if (endDate != null)
68+
descriptor.Query(q => q.DateRange(dr =>
69+
dr.Field(f => f.Timestamp).LessThanOrEquals(endDate)));
70+
6171
var result = await _client.SearchAsync<ElasticSearchDbLogModel>(descriptor, cancellationToken);
6272

6373
int.TryParse(result?.Total.ToString(), out var total);

0 commit comments

Comments
 (0)