We are migrating our Nest 1.0 to NEST 2.0, In previous version we were having a query like this:
container = new QueryContainer();
container = new QueryDescriptor<BaseModel>().Range(qs => qs.OnField(f => f.PublishedDate).LowerOrEquals(TimeZoneInfo.ConvertTimeToUtc(DateTime.Now)));
if (!string.IsNullOrEmpty(contentType) && !contentType.ToLower().Equals("all"))
{
container &= new QueryDescriptor<BaseModel>().QueryString(qs => qs.OnFields(f => f.ContentType).Query(contentType));
}
In NEST 2.0 QueryDescriptor Class is not available, How Can we perform similar action in NEST 2.0?
Apply few changes to your code and you will be good:
QueryDescriptor<>
to QueryContainerDescriptor
DateRange(..)
instead of Range(..)
OnFields(..)
methods have been changed to Fields(..)
all aroundLowerOrEquals(..)
with LessThanOrEquals(..)
Something like:
container = new QueryContainer();
container = new QueryContainerDescriptor<BaseModel>().DateRange(qs => qs.Field(f => f.PublishedDate).LessThanOrEquals(TimeZoneInfo.ConvertTimeToUtc(DateTime.Now)));
if (!string.IsNullOrEmpty(contentType) && !contentType.ToLower().Equals("all"))
{
container &= new QueryDescriptor<BaseModel>().QueryString(qs => qs.OnFields(f => f.ContentType).Query(contentType));
}
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With