简体   繁体   中英

elasticsearch nest 7.1 aggregation Fields generic shorthand field expression

so reading this:

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

given a class of

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

I would expect to be able to do something like:

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

but I get an error of The non-generic type Field cannot be used with type arguments .

I am using Nest 7.1.0.

My goal was to be able to create a method that can have aggregations and queries passed in and then combined into running on a instance of a nest ElasticClient .

something like (I think)

            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);

As stated in the documentation you need to add a static import to be able to write the code using the same style

using static Nest.Infer;

Otherwise you need to use simple new Field(..) instantiation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM