# How to create index with a keyword field through Java API

**URL:** https://discuss.elastic.co/t/how-to-create-index-with-a-keyword-field-through-java-api/93741
**Category:** Elasticsearch
**Created:** [July 19, 2017, 10:55am UTC](https://discuss.elastic.co/t/how-to-create-index-with-a-keyword-field-through-java-api/93741 "2017-07-19T10:55:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nitin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nitin/32/20151_2.png) [@nitin](https://discuss.elastic.co/u/nitin)
#### Post date: [July 19, 2017, 10:55am UTC](https://discuss.elastic.co/t/how-to-create-index-with-a-keyword-field-through-java-api/93741/1 "2017-07-19T10:55:34Z")

</div>

Hi,  
I am creating my index using following command:  
CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName).addMapping(documentType, XContentFactory.jsonBuilder().startObject().startObject(documentType).startObject("properties").startObject("completion\_suggest").field("type", "completion").endObject().endObject().endObject().endObject());

I have a field named category on which I want to do aggregation. ElasticSearch tells me that it is text type so I should enable field data on this field or create keyword field on this.  
Can somebody let me know how can it be done through above Java code?

Thanks,  
Nitin

---

<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: [August 16, 2017, 10:56am UTC](https://discuss.elastic.co/t/how-to-create-index-with-a-keyword-field-through-java-api/93741/2 "2017-08-16T10:56:13Z")

</div>

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