Hi, I'm migrating from HLRC to ES8.1. We used to pass json data for settings and mappings in source.
HLRC Code
PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName);
request.source(templateJson, XContentType.JSON);
putTemplateResponse = restClient.indices().putTemplate(request, RequestOptions.DEFAULT);
where templateJson is
{
"index_patterns":"appcache*",
"settings":{
"number_of_shards":2,
"max_result_window":2147483647,
"mapping.total_fields.limit":2000000
},
"mappings":{
"dynamic":"false",
"properties":{
"key":{
"properties":{
"entityId":{
"type":"long"
},
"entityNr":{
"type":"long"
},
"sessionId":{
"type":"long"
}
}
},
"timeOfCreation":{
"index":true,
"type":"date",
"format":"yyyy-MM-dd'T'HH:mm:ss.SSSZ||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
There is no option to add json data as per doc PutIndexTemplateRequest (java-client 8.1.0 API)
So i tried to breakdown json, but were unable to build properties, Is there any reference for the same, or any other way to build?
ES 8.1.0 Client
IndexTemplateMapping indexTemplateMapping = new IndexTemplateMapping.Builder()
.settings(s -> s.shards(2).maxResultWindow(2147483647).maxScriptFields(2000000))
.mappings(m -> m
//.properties unable to structure properties for json
.dynamic(DynamicMapping.False)
).build();
PutIndexTemplateResponse putIndexTemplateResponse =
esClient.indices().putIndexTemplate(new PutIndexTemplateRequest.Builder()
.indexPatterns("appcache*")
.template(indexTemplateMapping)
.name(templateName).build());