jhorcicka commented on a change in pull request #229: Upgrade to Elasticsearch 
7.3.1
URL: https://github.com/apache/metamodel/pull/229#discussion_r332999097
 
 

 ##########
 File path: 
elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestClient.java
 ##########
 @@ -18,117 +18,80 @@
  */
 package org.apache.metamodel.elasticsearch.rest;
 
-import static java.util.Collections.emptySet;
-
 import java.io.IOException;
-import java.util.Collections;
-import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.http.Header;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.ContentType;
-import org.elasticsearch.action.ActionRequest;
-import org.elasticsearch.action.ActionResponse;
-import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
+import org.apache.http.HttpHost;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
-import org.elasticsearch.action.bulk.BulkRequest;
-import org.elasticsearch.action.delete.DeleteRequest;
-import org.elasticsearch.action.index.IndexRequest;
-import org.elasticsearch.action.main.MainRequest;
-import org.elasticsearch.action.search.ClearScrollRequest;
-import org.elasticsearch.action.search.SearchScrollRequest;
-import org.elasticsearch.client.Request;
-import org.elasticsearch.client.Response;
+import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
+import org.elasticsearch.client.Node;
+import org.elasticsearch.client.RequestOptions;
 import org.elasticsearch.client.RestClient;
 import org.elasticsearch.client.RestHighLevelClient;
-import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.client.indices.GetMappingsRequest;
+import org.elasticsearch.cluster.metadata.MappingMetaData;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * @deprecated Instead of using this class just use the {@link 
RestHighLevelClient} itself. This class was introduced to
+ *             support Elasticsearch 5.6.3, when the {@link 
RestHighLevelClient} didn't offer all needed functionality,
+ *             but now it does, so please use that one instead of this one.
+ */
+@Deprecated
 public class ElasticSearchRestClient extends RestHighLevelClient {
     private static final Logger logger = 
LoggerFactory.getLogger(ElasticSearchRestClient.class);
 
     public ElasticSearchRestClient(final RestClient restClient) {
-        super(restClient);
+        
super(RestClient.builder(restClient.getNodes().stream().map(Node::getHost).toArray(HttpHost[]::new)));
     }
 
     public final boolean refresh(final String indexName, final Header... 
headers) {
         try {
-            return performRequest(new MainRequest(), request -> 
refresh(indexName),
-                    ElasticSearchRestClient::convertResponse, emptySet(), 
headers);
+            indices().refresh(new RefreshRequest(indexName), 
RequestOptions.DEFAULT);
+            return true;
         } catch (IOException e) {
             logger.info("Failed to refresh index \"{}\"", indexName, e);
         }
         return false;
     }
 
-    private static Request refresh(final String indexName) {
-        return new Request(HttpPost.METHOD_NAME, "/" + indexName + 
"/_refresh", Collections.emptyMap(), null);
-    }
-
-    public final boolean delete(final String indexName, final Header... 
headers) throws IOException {
-        return performRequest(new MainRequest(), request -> delete(indexName),
-                ElasticSearchRestClient::convertResponse, emptySet(), headers);
-    }
-
-    private static Request delete(final String indexName) {
-        return new Request(HttpDelete.METHOD_NAME, "/" + indexName, 
Collections.emptyMap(), null);
-    }
-
     public Set<Entry<String, Object>> getMappings(final String indexName, 
final Header... headers) throws IOException {
-        return performRequestAndParseEntity(new GetIndexRequest(), request -> 
getMappings(indexName), (
-                response) -> parseMappings(response, indexName), emptySet(), 
headers);
+        return indices()
+                .getMapping(new GetMappingsRequest().indices(indexName), 
RequestOptions.DEFAULT)
+                .mappings()
+                .entrySet()
+                .stream()
+                .map(ElasticSearchRestClient::convertMapping)
+                .collect(Collectors.toSet());
     }
 
-    private static Request getMappings(final String indexName) {
-        return new Request(HttpGet.METHOD_NAME, "/" + indexName, 
Collections.emptyMap(), null);
+    private static Entry<String, Object> convertMapping(final Entry<String, 
MappingMetaData> entry) {
+        return new Entry<String, Object>() {
+            @Override
+            public String getKey() {
+                return entry.getKey();
+            }
+
+            @Override
+            public Object getValue() {
+                return entry.getValue().getSourceAsMap();
+            }
+
+            @Override
+            public Object setValue(final Object value) {
+                return null;
 
 Review comment:
   OK

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to