【问题标题】:elasticsearch nest 7.1 aggregation Fields generic shorthand field expressionelasticsearch nest 7.1 聚合字段通用速记字段表达式
【发布时间】:2020-01-19 20:28:28
【问题描述】:

所以读到这里:

https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.x/field-inference.html

给定一个类

public class MyData {
    public Guid UserId { get; set; }
    public decimal Value { get; set; }
}

我希望能够做类似的事情:

var fieldExpression = Field<MyData >(p => p.Value);

但我收到The non-generic type Field cannot be used with type arguments 的错误。

我正在使用 Nest 7.1.0。

我的目标是能够创建一个方法,该方法可以传入聚合和查询,然后组合成在嵌套 ElasticClient 的实例上运行。

类似(我认为)

            var sr = new SearchRequest<MyData>
            {
                Aggregations = new ChildrenAggregation("name_of_child_agg", typeof(decimal?))
                {
                    Aggregations =
                        new AverageAggregation("average_per_child", Field<MyData>(p => p.value))
                        && new MaxAggregation("max_per_child", Field<MyData>(p => p.value))
                        && new MinAggregation("min_per_child", Field<MyData>(p => p.value))
                }
            };

_client.Search<MyData>(sr);

【问题讨论】:

    标签: elasticsearch nest elasticsearch-aggregation


    【解决方案1】:

    如文档中所述,您需要添加 static import 才能使用相同的样式编写代码

    using static Nest.Infer;
    

    否则需要使用简单的new Field(..)实例化

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-18
    • 2016-11-23
    • 2015-07-30
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    相关资源
    最近更新 更多