1
我遇到了嵌套聚合問題。這裏是我如何定義我的聚合和我得到的json等價物:嵌套聚合不適用於AggregationContainer
var aggregations = new AggregationDictionary();
var nestedAgg = new AggregationContainer
{
Nested = new NestedAggregation("some_name1")
{
Path = "users",
Aggregations = new TermsAggregation("some_name2")
{
Field = "users.name.keyword",
Size = 100,
Order = new List<TermsOrder> { new TermsOrder() { Key = "_term", Order = SortOrder.Descending } }
}
};
aggregations[aggKey] = nestedAgg;
searchRequest.Aggregations = aggregations;
上面的內容翻譯爲以下json。只顯示路徑和沒有彙總定義:
{
"aggs": {
"some_name1": {
"nested": {
"path": "users"
}
}
}
爲什麼使用'AggregationDictionary'和'AggregationContainer'直接尷尬?我將如何添加多個聚合到我的'SearchRequest'? –
直接使用是有點_awkward_由於幾個原因:)每個聚合類型有一個名稱(因爲它是必需的),但使用'AggregationDictionary'的構造函數,密鑰的名稱將用於聚合的名稱。根據答案,當直接使用'AggregationContainer'時,您需要確保在分配聚合時也設置'Aggregations'和'Meta'屬性。爲了使事情更容易,有從AggregationBase到AggregationContainer和AggregationDictionary的隱式轉換。 –
您可以將彙總與'&&'合併:https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/writing-aggregations.html –