Multi term Sources NEST v6.8

Trying to Write NEST Query in C# for the following DSL

GET staff/_search
{
  "size": 0, 
"aggregations" : {
    "groupby" : {
      "composite" : {
        "size" : 1000,
        "sources" : [
          {
            "437" : {
              "terms" : {
                "field" : "id.keyword",
                "missing_bucket" : true,
                "order" : "asc"
              }
            }
          },
          {
            "439" : {
              "terms" : {
                "field" : "salary",
                "missing_bucket" : true,
                "order" : "asc"
              }
            }
          }
        ]
      }
    }
  }
}

Trying to write as :

var result = _connection.Search<staff>(Id => Id.Index("staff").Size(0)
    .Aggregations(a => a.Composite("groupBy",
                    c => c.Sources(s =>
                                   s.Terms("id", t => 
                                   t.Field(f => f.id.Suffix("keyword"))
                                   &&
                                   s.Terms("id", t =>
                                   t.Field(f => f.salary)
                                   )
                                  )
                                )
                 )
        );

Getting error : Getting error : Operator '&&' cannot be applied to operands of type TermsCompositeAggregationSourceDescriptor and CompositeAggregationSourceDescriptor

It would be

var searchResponse = client.Search<staff>(s => s
    .Index("staff")
    .AllTypes()
    .Size(0)
    .Aggregations(a => a
        .Composite("groupby", c => c
            .Size(1000)
            .Sources(so => so
                .Terms("437", ts => ts
                    .Field("id.keyword")
                    .MissingBucket()
                    .Order(Nest.SortOrder.Ascending)
                )
                .Terms("439", ts => ts
                    .Field("salary")
                    .MissingBucket()
                    .Order(Nest.SortOrder.Ascending)
                )
            )
        )
    )
);

which produces

POST http://localhost:9200/staff/_search?typed_keys=true 
{
  "aggs": {
    "groupBy": {
      "composite": {
        "size": 1000,
        "sources": [
          {
            "437": {
              "terms": {
                "field": "id.keyword",
                "missing_bucket": true,
                "order": "asc"
              }
            }
          },
          {
            "439": {
              "terms": {
                "field": "salary",
                "missing_bucket": true,
                "order": "asc"
              }
            }
          }
        ]
      }
    }
  },
  "size": 0
}

Take a look at the Composite Aggregation example usage documentation.

It worked
Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.