# Keyword field on bucket aggregation

**URL:** <https://discuss.elastic.co/t/keyword-field-on-bucket-aggregation/106135>\
**Category:** Elasticsearch\
**Created:** [November 2, 2017, 7:47am UTC](https://discuss.elastic.co/t/keyword-field-on-bucket-aggregation/106135 "2017-11-02T07:47:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aarjan](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@aarjan](https://discuss.elastic.co/u/aarjan)\
**Post date:** [November 2, 2017, 7:47am UTC](https://discuss.elastic.co/t/keyword-field-on-bucket-aggregation/106135/1 "2017-11-02T07:47:11Z")

</div>

I have explained a short version of a much bigger problem.

I have two indices, **sam** & **sam-2**.  
There is a **user** field in both indices, **sam** with mapping type as **keyword** only...  
**sam-2** with multiple fields mapping type, **text** and **keyword**.

Now, i try to visualize the data with a common index pattern **sam\*** for both indices in DataTable.

For selecting **user.keyword** as **term** in **bucket-aggregation** , I get value of **user.keyword** displayed for the **sam-2** ,whereas nil for **sam**.  
Both have same number of documents.

Screenshot:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/9/19520317fbb83ded738df901d023d05bae3e93d1.png)

I don't understand, why i get nil for **keyword** mapping type.  
Isn't keyword datatype used for aggregations.

---

<div class="post-metadata">

**Author:** ![aarjan](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@aarjan](https://discuss.elastic.co/u/aarjan)\
**Post date:** [November 2, 2017, 9:58am UTC](https://discuss.elastic.co/t/keyword-field-on-bucket-aggregation/106135/2 "2017-11-02T09:58:13Z")

</div>

Found the solution.  
Since the sam-2 doesnot have any field called 'keyword', it will surely show nil.

So, now if i need to aggregate on the user field, i need to use the **user** not user.keyword on sam-2 and **user.keyword** in sam.

---

<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:** [November 30, 2017, 9:58am UTC](https://discuss.elastic.co/t/keyword-field-on-bucket-aggregation/106135/3 "2017-11-30T09:58:45Z")

</div>

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