# ElasticSearch aggregation over inner object

**URL:** <https://discuss.elastic.co/t/elasticsearch-aggregation-over-inner-object/51048>\
**Category:** Elasticsearch\
**Created:** [May 26, 2016, 11:14am UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-over-inner-object/51048 "2016-05-26T11:14:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![living\_jordi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/living_jordi/32/61363_2.png) [@living\_jordi](https://discuss.elastic.co/u/living_jordi)\
**Post date:** [May 26, 2016, 11:14am UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-over-inner-object/51048/1 "2016-05-26T11:14:12Z")

</div>

In my ES I've a schema type like this:

```
{
  "index_v1":{
    "mappings":{
      "fuas":{
        "properties":{
          "comment":{
            "type":"string"
          },
          "matter":{
            "type":"string"
          },
          "metainfos":{
            "properties":{
              "department":{
                "type":"string"
              },
              "processos":{
                "type":"string"
              }
            }
          }
        }
      }
    }
  }
}

```

Shortly, `fuas` type has two properties `comment` and `matter` and an inner (not nested) object `metainfos` with several properties `department` and `processos`.

I'd like to know how many `metainfos' fields` are informed with its number of occurrences.

Imagine a document `doc1` with `metainfos: {department: "d1"}` and a `doc2` with `metainfos: {department: "d2", processos: "p1"}`.

Then I'd like to get: `{ department: 2, processos: 1}`.

Any ideas?

---

<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 5, 2017, 10:48pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-over-inner-object/51048/2 "2017-07-05T22:48:51Z")

</div>


