是否可以在NEST上查询多个术语字段(.NET)的聚合?

时间:2018-01-30 00:16:40

标签: elasticsearch nest elasticsearch-net

以下是NEST查询和聚合:

IService<ClientSpecificThing>

我已调用 Func<QueryContainerDescriptor<ConferenceWrapper>, QueryContainer> query = q => q.Term(p => p.type, "conference") // && q.Term(p => p.conference.isWaitingAreaCall, true) && q.Range(d => d.Field("conference.lengthSeconds").GreaterThanOrEquals(minSeconds)) && q.DateRange(qd => qd.Field("conference.firstCallerStart").GreaterThanOrEquals(from.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"))) && q.DateRange(qd => qd.Field("conference.firstCallerStart").LessThanOrEquals(to.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"))); Func<AggregationContainerDescriptor<ConferenceWrapper>, IAggregationContainer> waitingArea = a => a .Terms("both", t => t .Field(p => p.conference.orgNetworkId) // seems ignore this field .Field(p => p.conference.isWaitingAreaCall) // .Field(new Field( p => p.conference.orgNetworkId + "-ggg-" + p.conference.networkId) .Size(300) .Aggregations(a2 => a2.Sum("sum-length", d2 => d2.Field("conference.lengthSeconds")))); 后跟.Field(p => p.conference.orgNetworkId)但似乎NEST客户端尝试忽略第一个字段表达式。

是否可以将多个字段作为术语分组?

1 个答案:

答案 0 :(得分:1)

Elasticsearch不直接支持多个字段的术语聚合; NEST中对.Field(...)的调用是赋值的而不是加法的,因此最后一次调用将覆盖任何先前设置的值。

要在多个字段上进行汇总,您可以

  1. 在索引时创建一个复合字段,其中包含您希望在

    上聚合的值

  2. 通过组合两个字段值,使用tp_alloc生成在查询时汇总的字词。

  3. 第一个选项的表现将优于第二个选项。

相关问题