【发布时间】:2019-07-07 17:26:46
【问题描述】:
我正在尝试使用 NEST API 在弹性搜索中使用日期范围搜索。
我知道 ES 在与 Nlog 集成时将时间戳存储在 UTC 中。 但是,我需要在此 @timestamp 字段中进行日期范围搜索。
我写了以下查询:
从日期搜索:
qcd.DateRange(r => r
.Field(f => f.timestamp)
.GreaterThanOrEquals(searchFromDateTime)
.TimeZone("+02:00")
);
迄今为止的搜索:
qcd.DateRange(r => r
.Field(f => f.timestamp)
.LessThanOrEquals(searchToDateTime)
.TimeZone("+02:00")
);
这是查询的其余部分:
searchResponse = (SearchResponse<SearchEventDto>)client.Search<SearchEventDto>(s => s
.Index("logstash-*")
.Type("logevent")
.Query(q => qcd)
);
SearchFromDateTime 或 SearchToDateTime 是 c# 日期。
显然,查询中有问题,因为它没有考虑时差。
例如,由于我是 CET 时间,如果我将 28.06.2019 14:48 作为搜索起始日期,它应该从 28.06.2019 12:48 开始搜索。或者,Search To date 中也应该发生同样的情况。
任何想法,我怎么能做到这一点?
【问题讨论】:
标签: c# elasticsearch nest