How to write date range query in Nest ElasticSearch client?

时间:2023-03-09 03:35:53
How to write date range query in Nest ElasticSearch client?

Looking at the source code, there are two overloads of the OnField method. When I use the the that takes Linq expression parameter, the query does not return any data. But I was able to make it work with the other overload, which takes string value, where I am passing the field name of the elasticsearch document as a string. Here's the query that returns expected results:

var resultSet = _elasticSearchClient.Search<Amqp>(q => q.Query
(p => p.Range(v => v.OnField("LogGenerationTime").GreaterOrEquals(lowerBound))).Size(10000));