无法在 Nest 中 select 进行子聚合
Can't select sub aggregation in Nest
我在 Elastic 查询中得到了这些结果:
"Results" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "73c47133-8656-45e7-9499-14f52df07b70",
"doc_count" : 1,
"foo" : {
"doc_count" : 40,
"bar" : {
"doc_count" : 1,
"customscore" : {
"value" : 10.496919917864476
}
}
}
}
]
我正在尝试获取匿名对象列表,其中 key
字段作为键,customscore
字段作为值。
无论我尝试什么,我似乎都无法在 Nest 中编写访问 customscore
值的代码。显然,我是世界上第一个在 Nest 库中使用嵌套聚合的人。要么,要么文档非常缺乏。我可以轻松到达 Buckets:
response?.Aggregations.Terms("Results").Buckets;
但我不知道如何处理这个对象。 Buckets
包含几个对象,我认为我可以通过这样做来导航:
bucketObject["foo"]["bar"]["customscore"]
但显然不是。我已经找到了使用 for 循环的解决方案、使用长 Linq 查询的解决方案,而且所有这些对我来说似乎都是 return null
。我错过了什么?
假设以下查询,我认为将匹配问题
中的响应
var client = new ElasticClient();
var response = client.Search<object>(s => s
.Index("some_index")
.Aggregations(a => a
.Terms("Results", t => t
.Field("some_field")
.Aggregations(aa => aa
.Filter("foo", f => f
.Filter(q => q.MatchAll())
.Aggregations(aaa => aaa
.Filter("bar", ff => ff
.Filter(q => q.MatchAll())
.Aggregations(aaaa => aaaa
.ValueCount("customscore", vc => vc
.Field("some_other_field")
)
)
)
)
)
)
)
)
);
获取匿名类型的集合是
var kvs = response.Aggregations.Terms("Results").Buckets
.Select(b => new
{
key = b.Key,
value = b.Filter("foo").Filter("bar").ValueCount("customscore").Value
});
.Aggregations
exposes methods that convert the IAggregate
response to the expected type
我在 Elastic 查询中得到了这些结果:
"Results" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "73c47133-8656-45e7-9499-14f52df07b70",
"doc_count" : 1,
"foo" : {
"doc_count" : 40,
"bar" : {
"doc_count" : 1,
"customscore" : {
"value" : 10.496919917864476
}
}
}
}
]
我正在尝试获取匿名对象列表,其中 key
字段作为键,customscore
字段作为值。
无论我尝试什么,我似乎都无法在 Nest 中编写访问 customscore
值的代码。显然,我是世界上第一个在 Nest 库中使用嵌套聚合的人。要么,要么文档非常缺乏。我可以轻松到达 Buckets:
response?.Aggregations.Terms("Results").Buckets;
但我不知道如何处理这个对象。 Buckets
包含几个对象,我认为我可以通过这样做来导航:
bucketObject["foo"]["bar"]["customscore"]
但显然不是。我已经找到了使用 for 循环的解决方案、使用长 Linq 查询的解决方案,而且所有这些对我来说似乎都是 return null
。我错过了什么?
假设以下查询,我认为将匹配问题
中的响应var client = new ElasticClient();
var response = client.Search<object>(s => s
.Index("some_index")
.Aggregations(a => a
.Terms("Results", t => t
.Field("some_field")
.Aggregations(aa => aa
.Filter("foo", f => f
.Filter(q => q.MatchAll())
.Aggregations(aaa => aaa
.Filter("bar", ff => ff
.Filter(q => q.MatchAll())
.Aggregations(aaaa => aaaa
.ValueCount("customscore", vc => vc
.Field("some_other_field")
)
)
)
)
)
)
)
)
);
获取匿名类型的集合是
var kvs = response.Aggregations.Terms("Results").Buckets
.Select(b => new
{
key = b.Key,
value = b.Filter("foo").Filter("bar").ValueCount("customscore").Value
});
.Aggregations
exposes methods that convert the IAggregate
response to the expected type