Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the alternative to QueryDescriptor nest 2.x

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?

like image 937
Saurabh Sashank Avatar asked Dec 25 '22 04:12

Saurabh Sashank


1 Answers

Apply few changes to your code and you will be good:

  1. Change QueryDescriptor<> to QueryContainerDescriptor
  2. Use DateRange(..) instead of Range(..)
  3. OnFields(..) methods have been changed to Fields(..) all around
  4. Finally, replace LowerOrEquals(..) 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.

like image 88
Rob Avatar answered Jan 06 '23 15:01

Rob