# Aggregation-keywords

**URL:** <https://discuss.elastic.co/t/aggregation-keywords/160300>\
**Category:** Elasticsearch\
**Created:** [December 11, 2018, 6:32am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300 "2018-12-11T06:32:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raghunadhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raghunadhan/32/44239_2.png) [@Raghunadhan](https://discuss.elastic.co/u/Raghunadhan)\
**Post date:** [December 11, 2018, 6:32am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/1 "2018-12-11T06:32:22Z")

</div>

Dear All,

What does term and keyword mean that are used in aggregation query,

Please find the example below

GET /bank/\_search  
{  
"size": 0,  
"aggs": {  
"group\_by\_state": {  
"terms": {  
"field": "state.keyword"  
},  
"aggs": {  
"average\_balance": {  
"avg": {  
"field": "balance"  
}  
}  
}  
}  
}  
}

---

<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:** [December 11, 2018, 6:52am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/2 "2018-12-11T06:52:49Z")

</div>

I guess you meant `terms` and `state.keyword`.

- `terms`: that's a terms aggregation: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)
- `state.keyword` is the field name you want to compute the terms aggregation on

If you are not defining any mapping in elasticsearch, then elasticsearch tries to automatically guess the mapping for you. If you sent a text within a `state` field, then elasticsearch created 2 fields behind the scene `state` and `state.keyword`. The former is more for full text search, the later more for computing aggregations, do sorting...

You can look at the mapping by doing:

```
GET /bank/_mapping
```

---

<div class="post-metadata">

**Author:** ![Raghunadhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raghunadhan/32/44239_2.png) [@Raghunadhan](https://discuss.elastic.co/u/Raghunadhan)\
**Post date:** [December 11, 2018, 7:04am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/3 "2018-12-11T07:04:11Z")

</div>

> [@dadoonet](#):
>
> `terms` : that's a terms aggregation

what does that multi-bucket value source based aggregation mean ,i don't understand  
`terms` : that's a terms aggregation,bucket.And in some cases we done use state.keyword why its is .Please explain.I just now started to learn elasticsearch

---

<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:** [December 11, 2018, 8:30am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/4 "2018-12-11T08:30:34Z")

</div>

I don't understand the question.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

Then from that tell me what you don't understand.

---

<div class="post-metadata">

**Author:** ![Raghunadhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raghunadhan/32/44239_2.png) [@Raghunadhan](https://discuss.elastic.co/u/Raghunadhan)\
**Post date:** [December 14, 2018, 4:23am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/5 "2018-12-14T04:23:29Z")

</div>

What does 'terms' and 'keyword' mean used in aggregation script for example see below example.And then don't understand the concept given in the above link given b you

GET /bank/\_search  
{  
"size": 0,  
"aggs": {  
"group\_by\_state": {  
"terms": {  
"field": "state.keyword"  
},  
"aggs": {  
"average\_balance": {  
"avg": {  
"field": "balance"  
}  
}  
}  
}  
}  
}

---

<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:** [December 14, 2018, 5:27am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/6 "2018-12-14T05:27:15Z")

</div>

I already answered to this question here: [Aggregation-keywords](https://discuss.elastic.co/t/aggregation-keywords/160300/2?u=dadoonet)

I don't understand what you don't understand in my answer.

May be someone else understand what the problem is?

---

<div class="post-metadata">

**Author:** ![Raghunadhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raghunadhan/32/44239_2.png) [@Raghunadhan](https://discuss.elastic.co/u/Raghunadhan)\
**Post date:** [December 14, 2018, 6:37am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/7 "2018-12-14T06:37:58Z")

</div>

When should we use aggregation keyword

---

<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:** [December 14, 2018, 6:51am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/8 "2018-12-14T06:51:37Z")

</div>

There's no keyword aggregation if this is what you meant.

You need to run aggregation on fields which have a keyword datatype.

---

<div class="post-metadata">

**Author:** ![Emma543](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@Emma543](https://discuss.elastic.co/u/Emma543)\
**Post date:** [December 14, 2018, 7:02am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/9 "2018-12-14T07:02:35Z")

</div>

Thank You so much for this post... [psiphon](https://www.psiphon.onl)

---

<div class="post-metadata">

**Author:** ![Raghunadhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raghunadhan/32/44239_2.png) [@Raghunadhan](https://discuss.elastic.co/u/Raghunadhan)\
**Post date:** [December 14, 2018, 7:05am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/10 "2018-12-14T07:05:20Z")

</div>

Dear David.

`state.keyword` in this "state" is a field and why does we use "keyword" word that is as  
field.keyword

---

<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:** [December 14, 2018, 7:34am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/11 "2018-12-14T07:34:12Z")

</div>

In case you missed what I explained earlier:

> If you are not defining any mapping in elasticsearch, then elasticsearch tries to automatically guess the mapping for you. If you sent a text within a `state` field, then elasticsearch created 2 fields behind the scene `state` and `state.keyword` . The former is more for full text search, the later more for computing aggregations, do sorting...
> 
> You can look at the mapping by doing:
> 
> ```auto
> GET /bank/_mapping
> 
> ```

---

<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:** [January 11, 2019, 7:34am UTC](https://discuss.elastic.co/t/aggregation-keywords/160300/12 "2019-01-11T07:34:14Z")

</div>

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