【问题标题】:Composite Aggregation with After functionality具有 After 功能的复合聚合
【发布时间】:2019-03-27 10:04:12
【问题描述】:

我正在寻找与 NEST lib 一起使用后功能的代码 sn-p。 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html#_after.

提前感谢代码 sn-p

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    您可以将先前复合聚合中的 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

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 2019-05-06
      相关资源
      最近更新 更多