Elastic search create Index is failing

I am trying to create index with High Rest Client, version 6.5.0

CreateIndexRequest createIndexRequest = new CreateIndexRequest();
createIndexRequest.index(indexName);
createIndexRequest.settings(source, XContentType.JSON);
createIndexRequest.mapping(indexType, source, XContentType.JSON);
createIndexRequest.source(source, XContentType.JSON);
try {
client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
I am getting error as -> java.lang.IllegalStateException: mappings for type "books" were already defined

Did I made any mistake?

Delete the index first before creating it.
Otherwise this will conflict.

Actually there is no index in ES, its not even reaching to insert part, actually the error is thrown from createIndexRequest.source(source, XContentType.JSON);

  1. When createIndexRequest.mapping(indexType, source, XContentType.JSON); is executed, the source is put in to map with key as indexType
  2. When createIndexRequest.source(source, XContentType.JSON); is executed, in the api internal call, it is trying to put the source in to map with same key.

Please find below trace:

java.lang.IllegalStateException: mappings for type "taggings" were already defined

at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.mapping(CreateIndexRequest.java:264)
at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.source(CreateIndexRequest.java:394)
at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.source(CreateIndexRequest.java:375)
at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.source(CreateIndexRequest.java:346)

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