Elasticsearch.Net-从v1.9升级到v5.4后的更改 [英] Elasticsearch.Net - Changes after upgrading from v1.9 to v5.4
问题描述
从v1.9升级到v5.4后,我注意到ES发生了很多变化.
I have noticed a lot of changes in ES after upgrading it from v1.9 to v5.4.
我仍然对ES中的查询技术有疑问.在v1.9中,我注意到过滤器"选项有所不同.
I am still having doubts about the querying techniques in ES. In v1.9 I have noticed that the Filter option differs.
我想知道如何在v5.4中复制以下代码
I am wondering how I can replicate the below code in v5.4
searchDescriptor.Query(q => q.Filtered(m => m.Query(n => matchQuery).Filter(o => o.And(filterContainer.ToArray()))))
我在这里看到Filter(o => o.And(filterContainer.ToArray())
如何用v5.4进行And
或Or
操作?
Here I see Filter(o => o.And(filterContainer.ToArray())
how is it possible to do an And
or an Or
operation with v5.4?
Filter(o => o.And(filterContainer.ToArray())
是否表示数组中的每个项目都用And
操作符绑定?
Does Filter(o => o.And(filterContainer.ToArray())
indicate that each item in the array are bound with an And
operaton?
推荐答案
.And()
和.Or()
在Elasticsearch 2.0中已弃用,在5.0中已删除.您可以将它们替换为
.And()
and .Or()
were deprecated in Elasticsearch 2.0 and removed in 5.0. You can replace them with a bool
query
- 对于
.Or()
,请使用.Should()
.
.And()
,如果需要评分,请使用.Must()
.如果不需要评分,请使用.Filter()
.
- for
.And()
, if you require scoring, then used.Must()
. If you don't require scoring, use.Filter()
. - for
.Or()
, use.Should()
.
bool
查询可以嵌套,因此可以创建复杂的复合查询.
bool
queries can be nested, so it's possible to create complex compound queries.
searchDescriptor.Query(q => q.Filtered(m => m.Query(n => matchQuery).Filter(o => o.And(filterContainer.ToArray()))))
searchDescriptor.Query(q => q.Filtered(m => m.Query(n => matchQuery).Filter(o => o.And(filterContainer.ToArray()))))
变成类似
var matchQuery = new MatchQuery { Field = "field", Query = "query" };
var filterContainer = new QueryContainer[] {
new TermQuery { Field = "field", Value = "value" }
};
client.Search<Message>(s => s
.Query(q => q
.Bool(b => b
.Must(matchQuery)
.Filter(filterContainer)
)
)
);
过滤的查询在2.0中已弃用,在5.0中已删除.
filtered queries were deprecated in 2.0 and removed in 5.0.
在这里我看到Filter(o => o.And(filterContainer.ToArray())如何使用v5.4进行与"或或"运算?
Here I see Filter(o => o.And(filterContainer.ToArray()) how is it possible to do an And or an Or operation with v5.4?
Filter(o => o.And(filterContainer.ToArray())是否表示数组中的每个项目都以And操作符绑定?
Does Filter(o => o.And(filterContainer.ToArray()) indicate that each item in the array are bound with an And operaton?
对于这些,将它们传递给bool
查询过滤子句,它们是连接的,即和.如果需要or
子句,则可以将bool
查询与过滤子句嵌套在bool
查询应子句中.
For these, pass them to a bool
query filter clauses, which are conjunctive i.e. and'ed. If you need to or
clauses, you can nest bool
queries with filter clauses within a bool
query should clauses.
这篇关于Elasticsearch.Net-从v1.9升级到v5.4后的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!