vernedeng commented on code in PR #9057:
URL: https://github.com/apache/inlong/pull/9057#discussion_r1508478377
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/es/ElasticsearchApi.java:
##########
@@ -147,93 +182,101 @@ private List<String>
getMappingInfo(List<ElasticsearchFieldInfo> fieldsInfo) {
}
/**
- * Create index and mapping
+ * Create index and mapping by REST API.
*
* @param indexName Index name of creating
* @param fieldInfos Field infos
- * @throws IOException The exception may throws
+ * @throws Exception The exception may throws
*/
- public void createIndexAndMapping(String indexName,
- List<ElasticsearchFieldInfo> fieldInfos) throws IOException {
- CreateIndexRequest createIndexRequest = new
CreateIndexRequest(indexName);
+ public void createIndexAndMapping(String indexName,
List<ElasticsearchFieldInfo> fieldInfos) throws Exception {
List<String> fieldList = getMappingInfo(fieldInfos);
- StringBuilder mapping = new StringBuilder().append("{\n
\"properties\" : {\n")
- .append(StringUtils.join(fieldList, ",\n")).append("\n
}\n}");
- createIndexRequest.mapping(mapping.toString(), XContentType.JSON);
-
- CreateIndexResponse createIndexResponse = getEsClient().indices()
- .create(createIndexRequest, RequestOptions.DEFAULT);
- LOG.info("create {}:{}", indexName,
createIndexResponse.isAcknowledged());
+ StringBuilder mapping = new
StringBuilder().append("\n{\"mappings\":\n{\n\"properties\":{\n")
+ .append(StringUtils.join(fieldList,
",\n")).append("\n}\n}\n}");
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]