DateRange Query in NEST

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

qbb.Bool(
    qbm =>
    qbm.Must(
        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?

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

DateMath.Now.Add(TimeSpan.FromDays(8)).RoundTo(TimeUnit.Day)

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

DateTime.UtcNow.Date.AddDays(-8)

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!

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