What is the alternative to QueryDescriptor nest 2.x

余生长醉 提交于 2019-11-30 18:56:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38136094/what-is-the-alternative-to-querydescriptor-nest-2-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!