DateRange Query in NEST


I am trying to do a DateRangeQuery with NEST. This is my code:

    qbm =>
        qbms =>
        qbms.DateRange(t => t.Field("DateField").GreaterThanOrEquals(DateMath.Now.Add(TimeSpan.FromDays(-8)).RoundTo(TimeUnit.Day)))))

I am trying to select everything dat has a date greater than or equal to 8 days ago. But this code returns a useless error. Does anyone have a tip?

(Russ Cam) #2

What's the error message returned? Is it in the client or returned from Elasticsearch? More detail would be good here.

There is an implicit conversion from DateTime to DateMath, so instead of using


which evaluates to "now+8d/d", you could use


which will evaluate to a specific date .e.g. "2016-11-13T00:00:00Z" for today's date as DateTime.UtcNow


Yes, i indeed solved it like you suggested. Thanks for the reply!

(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.