【发布时间】:2017-10-19 03:22:37
【问题描述】:
我正在使用 C# 的 Nest 库查询 ElasticSearch,以获取具有多个枢轴的图形数据。每个枢轴都是查询上的嵌套术语聚合,并且使用一个或两个枢轴可以正常工作。但是,一旦我到达三个枢轴,SearchRequest 对象将不会生成进一步的聚合。
构建聚合的代码如下所示:
TermsAggregation topTermAgg = null;
TermsAggregation currentAgg = null;
foreach (var pivotName in activePivots)
{
newTermAgg = new TermsAggregation("pivot")
{
Field = pivot.ToString().ToLower()
};
if (topTermAgg == null)
{
topTermAgg = newTermAgg;
}
else
{
currentAgg.Aggregations = newTermAgg;
}
currentAgg = newTermAgg;
}
SearchRequest 本身非常简单:
var searchRequest = new SearchRequest(Indices.Index("a", "b", "c"))
{
Size = 0,
Aggregations = topTermAgg,
Query = query,
};
不幸的是,当转换为字符串时,3 个或更多枢轴的 SearchRequest 看起来像这样(通过 nestClient.Serializer.SerializeToString(searchRequest)):
{
"size": 0,
"query": {
"bool": <Fairly complex query, that works fine. It's the aggregation that has the problem.>
},
"aggs": {
"pivot": {
"terms": {
"field": "pivot1"
},
"aggs": {
"pivot": {
"terms": {
"field": "pivot2"
}
}
}
}
}
}
当我在调试器中检查 searchRequest 对象时,它肯定有 3 个或更多聚合。这是怎么回事,如何让 3 个或更多嵌套术语聚合正常工作?
我使用的是 Nest 5.01 版。
【问题讨论】:
标签: elasticsearch nest