如何有条件地将聚合添加到Nest库?

时间:2018-08-09 17:46:59

标签: elasticsearch elasticsearch-net

我正在尝试有条件地添加聚合

var search = new SearchDescriptor<Foo>();

search.Aggregations(agg =>
  agg.Cardinality("dedup", cd => cd.Field(fi => fi.AddressHash).PrecisionThreshold(40000))
  .Filter("dontDedup", fl => fl.Filter(ft => ft.Term(te => te.AddressHash, "00000000000000000000000000000000"))));

其次:

if (someCondition) {
    search.Aggregations(agg => agg
        .Min("min_lat", fl => fl.Field(fi => fi.Latitude))
        .Max("max_lat", fl => fl.Field(fi => fi.Latitude))
        .Min("min_lon", fl => fl.Field(fi => fi.Longitude))
        .Max("max_lon", fl => fl.Field(fi => fi.Longitude))
    );
}

第二条.Aggregations语句从第一条语句中清除“ dedup”和“ dontDedup”聚合。而且似乎没有search.Aggregations.Add(... 可以零散添加.aggregations吗?

0 个答案:

没有答案