Terms Aggregation on Array of String

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".

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

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