How to add multiple types to an index Elasticsearch 6.4


(Sanjay Kumar BG) #1

I am using Elasticsearch6.4 Java High Level REST Client.
I am creating a index per customer and trying to add multiple types in that on demand.

My code for adding type for a module goes like this

RestHighLevelClient client = IndexUtils.getIndexClient();
boolean exists = false;
exists = checkIndexExists(client,request,exists);
if(exists){
try {
PutMappingRequest prequest = new PutMappingRequest(indexName);
prequest.updateAllTypes(true);
prequest.type(indexType);
prequest.source(jsonMap);
client.indices().putMapping(prequest, RequestOptions.DEFAULT);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
CreateIndexRequest createrequest = new CreateIndexRequest(indexName);
createrequest.mapping(mapping,XContentType.JSON);
try {
client.indices().create(createrequest, RequestOptions.DEFAULT);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I am getting an exception Rejecting mapping update to [customer_13] as the final mapping would have more than 1 type

I understand this support is removed in elasticsearch6.x, but what is the alternative way to achieve this?


NoClassDefFoundError InternalLoggerFactory on tomcat start
(David Pilato) #2

Read https://www.elastic.co/guide/en/elasticsearch/reference/6.4/removal-of-types.html


(Sanjay Kumar BG) #3

Thank u, that was very helpful


(system) #4

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