ElasticSearch - 过滤类型 [英] ElasticSearch - Filtering the type

查看:118
本文介绍了ElasticSearch - 过滤类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新新旗新新新旗新新旗旗新新旗旗新新旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新200新新新旗旗新旗旗.9:下面的代码检查对象类型是否匹配 ObjectAdo ,它会过滤 ObjectAdo 中具有<新评新醒旗200 200 200 200 200 200 200 200 200 200 200 200 200 200旗新旗p45 200 200 200 200 200 200 200 200 200 200旗新新新新新旗新新200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 -40 200 c $ c> private Func< FilterDescriptor< dynamic>,FilterContainer> Filter()
{
return b => b.Bool(x => x.Must(m => m.Type(typeof(ObjectAdo)),n => n.Term(IsDeleted,false)))新评新新新旗新新新新旗新新旗旗新新旗新新旗新新旗新新旗旗新新旗新新旗旗新新旗新新旗旗新新旗新新旗旗新新旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗新新旗旗新新旗新新200新旗新新旗200新新新200新200新新旗200新新新200新200新新200新新旗200新新新200新200人新200新新200新新旗2001-新新新新200新200新新200新新旗2001-新新新新旗新新200新200新新新200新200新新200新新旗2001-新新新新旗新新200新新200新新200新新旗2001-新新新新旗新新200新新200新新200新200新新200新新200新新200新新200新新200新新200人c $ c> FilterDescriptor 已更改为 QueryContainerDescriptor FilterContainer 现在 QueryContainer 。 X- 2004545 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- X- 20045454545 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- dOPex.pngrel =nofollow noreferrer> https://i.stack.imgur.com/dOPex.png

解决方案

在Elasticsearch 2.0中,查询和过滤器合并成一个,具有查询上下文和过滤器上下文的概念;当包装在bool查询过滤器子句中时,查询/过滤器位于过滤器上下文中,因此不会计算相关性分数,并且它将被缓存。



NEST 2.x向前与Elasticsearch 2.0中的更改一致,并具有查询( QueryContainer QueryContainerDescriptor< T> 等),可以在查询和过滤器上下文中使用。



将此应用于您的过滤器意味着将其更改为以下与NEST 5.x

  private Func< QueryContainerDescriptor< dynamic>,QueryContainer> Filter()
{
return b => b.Bool(x => x
.Filter(
f => f.Type(t => t.Value(typeof(ObjectAdo))),
f => f .Term(IsDeleted,false)

);
}

s 一个lambda表达式来设置可用选项。


I have upgraded my elasticsearch from v1.9 to v5 and I have noticed that a lot of things have changed.

If I were to take an example from v1.9: The below code checks whether the object type matches ObjectAdo and it filters the items within ObjectAdo that have the IsDeleted field as false.

private Func<FilterDescriptor<dynamic>, FilterContainer> Filter()
        {
            return b => b.Bool(x => x.Must(m => m.Type(typeof(ObjectAdo)), n => n.Term("IsDeleted", false)));
        }

Now, after upgrading from v1.9 to v5, I noticed that FilterDescriptor got changed to QueryContainerDescriptor and FilterContainer is now QueryContainer. Now I am unable to perform the same operation as before because .Type(typeof(ObjectAdo) is no longer available.

So I am wondering if there is an alternative solution to check the object type.

https://i.stack.imgur.com/dOPex.png

解决方案

In Elasticsearch 2.0, queries and filters merged into one, with the notion of a query context and a filter context; when wrapped in a bool query filter clause, a query/filter is in a filter context so relevance scores will not be calculated and it will be cacheable.

NEST 2.x onwards aligns with the change in Elasticsearch 2.0 and has queries (QueryContainer, QueryContainerDescriptor<T>, etc.) that can be used in both query and filter contexts.

Applying this to your filter, would mean changing it to the following with NEST 5.x

private Func<QueryContainerDescriptor<dynamic>, QueryContainer> Filter()
{
    return b => b.Bool(x => x
        .Filter(
            f => f.Type(t => t.Value(typeof(ObjectAdo))),
            f => f.Term("IsDeleted", false)
        )
    );
}

The syntax for a type query has changed a little to take a lambda expression to set available options.

这篇关于ElasticSearch - 过滤类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆