# Agregation on cURL

**URL:** <https://discuss.elastic.co/t/agregation-on-curl/185040>\
**Category:** Elasticsearch\
**Created:** [June 10, 2019, 5:45pm UTC](https://discuss.elastic.co/t/agregation-on-curl/185040 "2019-06-10T17:45:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![schneider](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schneider](https://discuss.elastic.co/u/schneider)\
**Post date:** [June 10, 2019, 5:45pm UTC](https://discuss.elastic.co/t/agregation-on-curl/185040/1 "2019-06-10T17:45:48Z")

</div>

I have a field named "remetente" containing e-mails, i want do agroup then by de top 10 higher hits between them, this is the cURL:

```
curl -XGET "http://localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
	"group_by_state": {
		"terms": {
		"field": "remetente"
		}
	}
  }
}'

```

but running this comand, return e following error:

```
`{"took":1019,"timed_out":false,"_shards": 
{"total":17,"successful":12,"skipped":0,"failed":5,"failures": 
[{"shard":0,"index":"imsva_message","node":"NYJSJOgHTXCdT8OW73dAxQ","reason" : 
{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by 
default. Set fielddata=true on [remetente] 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":11585745,"max_score":0.0,"hits": 
[]},"aggregations":{"group_by_state": 
{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]}}}
```

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [June 11, 2019, 2:28am UTC](https://discuss.elastic.co/t/agregation-on-curl/185040/2 "2019-06-11T02:28:17Z")

</div>

The problem here is that you are trying to do Terms Aggregation over an analyzed field, which is not supported by default.

There are two possible workarounds here:

1. Aggregate over a `keyword` field instead of `text`. If you have used standard dynamic mapping then you probably have the `remetente.keyword` field. Try aggregating over this field. If this does not exists, then you need to create a field of type `keyword` and use that field for aggregation.
2. If you really need to aggregate over an analyzed field (i.e. of type `text`) then you can still do it by setting `fielddata: true` in this `remetente` field mapping. But keep in mind that this can potentially use lots of heap memory which will lead to GC pressure and cause performance issues.

You can learn more about fielddata here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html)

---

<div class="post-metadata">

**Author:** ![schneider](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schneider](https://discuss.elastic.co/u/schneider)\
**Post date:** [June 11, 2019, 3:54pm UTC](https://discuss.elastic.co/t/agregation-on-curl/185040/3 "2019-06-11T15:54:43Z")

</div>

Thank you thiago, now it's working.  
Brigadão mano vi que você e de SP kk.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [June 11, 2019, 3:55pm UTC](https://discuss.elastic.co/t/agregation-on-curl/185040/4 "2019-06-11T15:55:30Z")

</div>

I am glad your problem is solved!

Sou do RJ 🙂

---

<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 9, 2019, 3:55pm UTC](https://discuss.elastic.co/t/agregation-on-curl/185040/5 "2019-07-09T15:55:30Z")

</div>

Closed on July 9, 2019, 3:55pm UTC

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