vernedeng commented on code in PR #9057:
URL: https://github.com/apache/inlong/pull/9057#discussion_r1378740033


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/es/ElasticsearchApi.java:
##########
@@ -147,93 +180,90 @@ 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}");
+        final String url = esConfig.getOneHttpUrl() + "/" + indexName;
+        ElasticsearchCreateIndexResponse response = 
HttpUtils.request(esConfig.getRestClient(), url, HttpMethod.PUT,
+                mapping.toString(), getHttpHeaders(),
+                new 
ParameterizedTypeReference<ElasticsearchCreateIndexResponse>() {
+                });
+        LOG.info("create {}:{}", indexName, response.getIndex());
     }
 
     /**
-     * Get fields
+     * Get mapping map.
      *
-     * @param indexName The index name of Elasticsearch
-     * @return a {@link Map} collection that contains {@link String}
-     *     as key and {@link MappingMetaData} as value.
-     * @throws IOException The exception may throws
+     * @param indexName elasticsearch index name
+     * @return map of elasticsearch index mapping info
      */
-    public Map<String, MappingMetaData> getFields(String indexName) throws 
IOException {
-        GetMappingsRequest request = new 
GetMappingsRequest().indices(indexName);
-        return getEsClient().indices().getMapping(request, 
RequestOptions.DEFAULT).mappings();
+    public Map<String, Map<String, String>> getMappingMap(String indexName) 
throws Exception {
+        final String url = esConfig.getOneHttpUrl() + "/" + indexName + 
"/_mapping";
+        JsonObject result = HttpUtils.request(esConfig.getRestClient(), url, 
HttpMethod.GET, null, getHttpHeaders(),

Review Comment:
   why not define a POJO to process the response



-- 
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]

Reply via email to