gpt4 book ai didi

elasticsearch - 具有After功能的复合聚合

转载 作者:行者123 更新时间:2023-12-03 01:31:59 25 4
gpt4 key购买 nike

我正在寻找带有NEST lib的After功能用法的代码片段。
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html#_after

预先感谢您的代码片段

最佳答案

您可以将以前的组合聚合中的CompositeKey传递为新的组合聚合的.After()参数。例如

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool);
var client = new ElasticClient(settings);

var searchResponse = client.Search<object>(s => s
.From(0)
.AllIndices()
.AllTypes()
.Aggregations(a => a
.Composite("composite_agg", c => c
.Sources(so => so
.DateHistogram("date", dh => dh
.Field("timestamp")
.Interval("1d")
)
.Terms("product", t => t
.Field("product")
)
)
)
)
);

var compositeAgg = searchResponse.Aggregations.Composite("composite_agg");

searchResponse = client.Search<object>(s => s
.From(0)
.AllIndices()
.AllTypes()
.Aggregations(a => a
.Composite("composite_agg", c => c
.Sources(so => so
.DateHistogram("date", dh => dh
.Field("timestamp")
.Interval("1d")
)
.Terms("product", t => t
.Field("product")
)
)
.After(compositeAgg.AfterKey) // <-- pass the after key from previous agg response
)
)
);

假设您正在使用Elasticsearch 6.x(必须使用Composite Aggregation),请将NEST客户端更新为最新版本(当前为6.6.0),因为它包含 bug fix for a CompositeKey with null values

关于elasticsearch - 具有After功能的复合聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55366028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com