# Multi term Sources NEST v6.8

**URL:** https://discuss.elastic.co/t/multi-term-sources-nest-v6-8/188172
**Category:** Elasticsearch
**Created:** [June 30, 2019, 5:11am UTC](https://discuss.elastic.co/t/multi-term-sources-nest-v6-8/188172 "2019-06-30T05:11:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mkhayyam\_q](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mkhayyam\_q](https://discuss.elastic.co/u/mkhayyam_q)
#### Post date: [June 30, 2019, 5:11am UTC](https://discuss.elastic.co/t/multi-term-sources-nest-v6-8/188172/1 "2019-06-30T05:11:42Z")

</div>

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

```auto
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 :

```auto
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**

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [July 1, 2019, 4:08am UTC](https://discuss.elastic.co/t/multi-term-sources-nest-v6-8/188172/2 "2019-07-01T04:08:02Z")

</div>

It would be

```auto
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

```json
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](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/composite-aggregation-usage.html).

---

<div class="post-metadata">

### Author: ![mkhayyam\_q](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mkhayyam\_q](https://discuss.elastic.co/u/mkhayyam_q)
#### Post date: [July 1, 2019, 11:13am UTC](https://discuss.elastic.co/t/multi-term-sources-nest-v6-8/188172/3 "2019-07-01T11:13:41Z")

</div>

> [@forloop](#):
>
> POST [http://localhost:9200/staff/\_search?typed\_keys=true](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 }

It worked  
Thanks.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 29, 2019, 11:13am UTC](https://discuss.elastic.co/t/multi-term-sources-nest-v6-8/188172/4 "2019-07-29T11:13:49Z")

</div>

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