Creating Indices with types using Java API

Hi guys,

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

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...");
        throw e;

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

Thanks David. The information was very helpful.

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

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.


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