1

Below is the NEST query and aggregations:

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

I have called .Field(p => p.conference.orgNetworkId) followed by .Field(p => p.conference.isWaitingAreaCall) But it seems the NEST client tries to ignore the first field expression.

Is is possible to have multiple fields to be the terms group by?

Xin
  • 33,823
  • 14
  • 84
  • 85

1 Answers1

1

Elasticsearch doesn't support a terms aggregation on multiple fields directly; the calls to .Field(...) within NEST are assignative rather than additive, so the last call will overwrite any previously set values.

In order to aggregate on multiple fields, you can either

  1. Create a composite field at index time that incorporates the values that you wish to aggregate on

    or

  2. Use a Script to generate the terms on which to aggregate at query time, by combining the two field values.

The performance of the first option will be better than the second.

Russ Cam
  • 124,184
  • 33
  • 204
  • 266
  • Thanks, mate. Yes, It behaves something like overwrite the previous `Field` in NEST. – Xin Jan 31 '18 at 22:28