# Elasticsearch aggregation not hits

**URL:** <https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182>\
**Category:** Elasticsearch\
**Created:** [November 26, 2018, 12:50pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182 "2018-11-26T12:50:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![limengmingx](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@limengmingx](https://discuss.elastic.co/u/limengmingx)\
**Post date:** [November 26, 2018, 12:50pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182/1 "2018-11-26T12:50:04Z")

</div>

I want to use aggregation to statistic how many types in my data ,but failed with command , the command hits nothing

```
GET /_search
     {
      "size": 0,
      "aggs": {
        "aggs_name": {
          "terms": {
            "field": "type"
          }
        }
      }
    }

```

and my data is like this:

```
 {

    "_index": "indexname",

    "_type": "doc",

    "_id": "",

    "_version": 1,

    "_score": 1,

    "_source": {

    "type":"type_A"

    }
    }

```

have I missed something necessary ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 26, 2018, 1:27pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182/2 "2018-11-26T13:27:18Z")

</div>

What is the error message?

---

<div class="post-metadata">

**Author:** ![limengmingx](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@limengmingx](https://discuss.elastic.co/u/limengmingx)\
**Post date:** [November 26, 2018, 1:33pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182/3 "2018-11-26T13:33:27Z")

</div>

actually there are no error through the elasticsearch header ,here are the results

{

- "took": 3,
- "timed\_out": false,
- "\_shards": {
  - "total": 35,
  - "successful": 35,
  - "skipped": 0,
  - "failed": 0},

- "hits": {
  - "total": 0,
  - "max\_score": null,
  - "hits": }

}

---

<div class="post-metadata">

**Author:** ![limengmingx](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@limengmingx](https://discuss.elastic.co/u/limengmingx)\
**Post date:** [November 26, 2018, 1:35pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182/4 "2018-11-26T13:35:34Z")

</div>

I execute the command via elasticsearch header, here are the result

{  
"took": 25,  
"timed\_out": false,  
"\_shards": {  
"total": 35,  
"successful": 30,  
"skipped": 0,  
"failed": 5,  
"failures": [  
{  
"shard": 0,  
"index": "indexname",  
"node": "61impylyQ2iHT\_KPVZ2kig",  
"reason": {  
"type": "illegal\_argument\_exception",  
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [D010010] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."  
}  
}  
]  
},  
"hits": {  
"total": 0,  
"max\_score": 0,  
"hits":   
},  
"aggregations": {  
"aggs\_name": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets":   
}  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 26, 2018, 1:47pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182/5 "2018-11-26T13:47:44Z")

</div>

You need to change the mapping for the field `type` to `keyword` if you want to compute aggregations.  
If you are using default mapping, try to run the agg on `type.keyword` instead.

---

<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:** [December 24, 2018, 1:47pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-not-hits/158182/6 "2018-12-24T13:47:46Z")

</div>

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