# Terms Aggregation on Array of String

**URL:** <https://discuss.elastic.co/t/terms-aggregation-on-array-of-string/195775>\
**Category:** Elasticsearch\
**Created:** [August 19, 2019, 4:07pm UTC](https://discuss.elastic.co/t/terms-aggregation-on-array-of-string/195775 "2019-08-19T16:07:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayabal\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayabal_k/32/41905_2.png) [@Jayabal\_K](https://discuss.elastic.co/u/Jayabal_K)\
**Post date:** [August 19, 2019, 4:07pm UTC](https://discuss.elastic.co/t/terms-aggregation-on-array-of-string/195775/1 "2019-08-19T16:07:55Z")

</div>

```
POST /test/log
    {
      "msg": ["text","text"]
    }

```

I have indexed the above document and tried term aggregation

```
   GET /test/_search
    {
      "aggs": {
        "NAME": {
         "terms": {
           "field": "msg.keyword"
           
         }
        }
      }
    }

```

output :

```
     "aggregations": {
        "NAME": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": [
            {
              "key": "text",
              "doc_count": 1
            }
          ]
        }
      }

```

My expected result could be

```
 "aggregations": {
    "NAME": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "text",
          **"doc_count": 2**
        }
      ]
    }

```

}  
I am expecting to get doc\_count as `2` since it has two occurrence of "text".

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 20, 2019, 7:24am UTC](https://discuss.elastic.co/t/terms-aggregation-on-array-of-string/195775/2 "2019-08-20T07:24:53Z")

</div>

hey,

the `doc_count` is the number of documents falling into this bucket. While a document could fall into two different buckets, it can only fall once into a single bucket. Check out the value count aggregation.

--Alex

---

<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:** [September 17, 2019, 7:24am UTC](https://discuss.elastic.co/t/terms-aggregation-on-array-of-string/195775/3 "2019-09-17T07:24:56Z")

</div>

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