# Creating Indices with types using Java API

**URL:** https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263
**Category:** Elasticsearch
**Created:** [February 6, 2019, 10:42am UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263 "2019-02-06T10:42:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Chandan\_Ray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandan_ray/32/40399_2.png) [@Chandan\_Ray](https://discuss.elastic.co/u/Chandan_Ray)
#### Post date: [February 6, 2019, 10:42am UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263/1 "2019-02-06T10:42:19Z")

</div>

Hi guys,

I am using RestHighLevelClient for Elasticsearch 5.6 but I am not able create indices using the API.  
Help.

---

<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: [February 6, 2019, 11:06am UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263/2 "2019-02-06T11:06:18Z")

</div>

Probably this version of the client does not support this api so you need to use the low level one and manage that by yourself.

Something like:

```
    try {
        Response response = lowLevelClient.performRequest("PUT", "/" + index,
                Collections.emptyMap(), createEntity(indexSettings));
        logger.trace("create index response: {}", asMap(response));
    } catch (ResponseException e) {
        if (e.getResponse().getStatusLine().getStatusCode() == 400 &&
                (e.getMessage().contains("index_already_exists_exception") || // ES 5.x
                        e.getMessage().contains("IndexAlreadyExistsException") )) { // ES 1.x and 2.x
            if (!ignoreErrors) {
                throw new RuntimeException("index already exists");
            }
            logger.trace("index already exists. Ignoring error...");
            return;
        }
        throw e;
    }
```

---

<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: [February 6, 2019, 11:07am UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263/3 "2019-02-06T11:07:10Z")

</div>

Or upgrade the server to 6.6 and the client as well. It has been implemented in 6.6

---

<div class="post-metadata">

### Author: ![Chandan\_Ray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandan_ray/32/40399_2.png) [@Chandan\_Ray](https://discuss.elastic.co/u/Chandan_Ray)
#### Post date: [February 6, 2019, 12:20pm UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263/4 "2019-02-06T12:20:47Z")

</div>

Thanks David. The information was very helpful.

---

<div class="post-metadata">

### Author: ![Chandan\_Ray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandan_ray/32/40399_2.png) [@Chandan\_Ray](https://discuss.elastic.co/u/Chandan_Ray)
#### Post date: [February 6, 2019, 12:40pm UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263/5 "2019-02-06T12:40:06Z")

</div>

> [@dadoonet](#):
>
> Collections.emptyMap()

Are we using this parameter to provide the "type" and "properties" mapping.

---

<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: [February 6, 2019, 1:26pm UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263/6 "2019-02-06T13:26:26Z")

</div>

In case you need some other methods, here is a class I wrote which adds some support for few other methods which are not supported by the HLClient v5.

> <https://github.com/dadoonet/fscrawler/blob/master/elasticsearch-client/elasticsearch-client-v5/src/main/java/fr/pilato/elasticsearch/crawler/fs/client/v5/ElasticsearchClientV5.java>

HTH

---

<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: [March 6, 2019, 1:26pm UTC](https://discuss.elastic.co/t/creating-indices-with-types-using-java-api/167263/7 "2019-03-06T13:26:33Z")

</div>

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