# Aggregation with nested properties

**URL:** <https://discuss.elastic.co/t/aggregation-with-nested-properties/204103>\
**Category:** Elasticsearch\
**Created:** [October 17, 2019, 4:59pm UTC](https://discuss.elastic.co/t/aggregation-with-nested-properties/204103 "2019-10-17T16:59:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skouame](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@skouame](https://discuss.elastic.co/u/skouame)\
**Post date:** [October 17, 2019, 4:59pm UTC](https://discuss.elastic.co/t/aggregation-with-nested-properties/204103/1 "2019-10-17T16:59:42Z")

</div>

Hello,  
I have the mapping below:

```
mappings:
properties:
    companyId:
        type: long
    customFields:
        type: nested
        properties:
            id:
                type: long
            customFieldId:
                type: long
            value:
                type: text
                fielddata: true
                analyzer: lower_analyzer
                fields:
                    keyword:
                        type: keyword
                        ignore_above: 256

```

i am try to make an aggregate with the customField properties like this:

```
{
  "query": {
  "match_all": {}
  },
  "size": 0, 
  "aggs": {
    "customFields": {
        "nested": {
        "path": "customFields"
      },
      "aggs": {
        "aggregateResulte": {
          "terms": {
            "script": "doc['customFields.customFieldId'] + ','+ doc['customFields.value']",
            "size": 10
          }
        }
      }
    }
  }
}

```

I would like to match exactly customField propertie include the number of size.

Register I =\> [customFiedId =\> 191, value = "serge"]  
Register II =\> [customFiedId =\> 191, value = "serge"]  
Register III =\> [**customFiedId =\> 191, value = "serge"** , customFiedId =\> 192, value = "serge",]  
Register IV =\> [customFiedId =\> 190, value = "serge", customFiedId =\> 192, value = "serge1",]  
Register V =\> [customFiedId =\> 191, value = "serge", customFiedId =\> 192, value = "serge",]

the result exepeted should be  
**bucket I =\> Register I and Register II**  
**bucket II =\> Register III and Register V**

Because there are the same value and the same number of object, but my request doesn't work well. Like Register III have one value, it appears on the bucket I even the dimension is 2.

thank

---

<div class="post-metadata">

**Author:** ![skouame](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@skouame](https://discuss.elastic.co/u/skouame)\
**Post date:** [October 23, 2019, 3:12pm UTC](https://discuss.elastic.co/t/aggregation-with-nested-properties/204103/2 "2019-10-23T15:12:02Z")

</div>

Some body can help me ?

---

<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:** [November 20, 2019, 3:12pm UTC](https://discuss.elastic.co/t/aggregation-with-nested-properties/204103/3 "2019-11-20T15:12:08Z")

</div>

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