我尝试转换此代码块但无法找到要更换的正确定义。已过滤接受操作< FilteredQueryDescriptor< T>>选择。 我已升级到NEST版本5.5.0,这是我尝试使用更高版本的NEST转换为工作的代码块:
UserView defaultUserView = new UserView();
SearchDescriptor<MyOrder> _searchDesc = new SearchDescriptor<MyOrder>();
_searchDesc = _searchDesc
.Index(MyIndex)
.Type(MyType)
.Query(mq => mq.Filtered(QueryDescriptor(defaultView)))
.SearchType(SearchType.Count)
这是QueryDescriptor:
private Func<SearchDescriptor<MyOrder>, SearchDescriptor<MyOrder>> QueryDescriptor(UserView userView)
{
Func<SearchDescriptor<MyOrder>, SearchDescriptor<MyOrder>> result;
result = delegate(SearchDescriptor<MyOrder> descriptor)
{
descriptor.Query
(
query => query.MatchAll()
)
.Query(f => f.Bool(CommonHelper.GetFilters(userView)));
return descriptor;
};
return result;
}
编辑:这是CommonHelper.GetFilters(userView):
public static class CommonHelper
{
public static Func<BoolQueryDescriptor<MyOrder>, BoolQueryDescriptor<MyOrder>> GetFilters(UserView userView)
{
Func<BoolQueryDescriptor<MyOrder>, BoolQueryDescriptor<MyOrder>>
result= delegate (BoolQueryDescriptor<MyOrder> descriptor)
{
switch (userView.UserView)
{
case UserView.1:
descriptor.Must(OldDefaultFilter());
break;
case UserView.2:
descriptor.Must(OldDefaultFilter())
.MustNot(MustNotDefaultFilter());
break;
}
return descriptor;
};
return result;
} }
答案 0 :(得分:1)
FilteredQueryDescriptor<T>
在NEST 2.x中已弃用,并已在NEST 5.x中删除,与各个主要版本中Elasticsearch的更改一致。
继续前进,使用bool
查询而不是查询的must
子句和过滤器的filter
子句。