kouchengxing 4 лет назад
Родитель
Сommit
6be66f87ee

+ 14 - 5
dgtis-modules/dgtis-modules-data/pom.xml

@@ -77,14 +77,23 @@
             <artifactId>dgtis-common-redis</artifactId>
         </dependency>
 
-
         <dependency>
-            <groupId>org.elasticsearch.client</groupId>
-            <artifactId>transport</artifactId>
-            <version>7.6.2</version>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.3</version>
         </dependency>
 
-
+        <dependency>
+            <groupId>com.arronlong</groupId>
+            <artifactId>httpclientutil</artifactId>
+            <version>1.0.4</version>
+        </dependency>
+        <!--        工具集-->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.3.8</version>
+        </dependency>
 
 
     </dependencies>

+ 26 - 6
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/api/DocumentApiController.java

@@ -1,11 +1,13 @@
 package com.dgtis.data.api;
 
+import com.arronlong.httpclientutil.HttpClientUtil;
+import com.arronlong.httpclientutil.common.HttpConfig;
+import com.arronlong.httpclientutil.exception.HttpProcessException;
+import com.dgtis.common.core.utils.DateUtils;
 import com.dgtis.common.core.web.controller.BaseController;
 import com.dgtis.common.core.web.domain.AjaxResult;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.elasticsearch.action.get.GetResponse;
-import org.elasticsearch.client.transport.TransportClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -26,22 +28,40 @@ import org.springframework.web.bind.annotation.ResponseBody;
 @RequestMapping("/api")
 public class DocumentApiController extends BaseController {
 
-    @Autowired
-    private TransportClient transportClient;
+   /* @Autowired
+    private TransportClient transportClient;*/
 
     @Autowired
     private ObjectMapper objectMapper;
 
-    @GetMapping("/getIndex")
+    /*@GetMapping("/getIndex")
     @ResponseBody
     public AjaxResult getIndex() {
 
         GetResponse response = transportClient.prepareGet("shanglifeecif.individual","default_type_", "1").get();
         String result = response.getSourceAsString();
         return AjaxResult.success(result);
-    }
+    }*/
 
+    @GetMapping("/getIndex")
+    @ResponseBody
+    public AjaxResult getById() {
+        // 获取索引的别名,字段,创建时间
+        System.out.println(DateUtils.getTime());
+        HttpConfig config = HttpConfig.custom().url("http://10.32.2.231:9200/shanglifeecif.individual/_search?from=1&size=10");
+        System.out.println(DateUtils.getTime());
+        String jsonStr = null;
+        try {
+
+            jsonStr = HttpClientUtil.get(config);
+            System.out.println(DateUtils.getTime());
+        } catch (HttpProcessException e) {
+            e.printStackTrace();
+            return null;
+        }
 
+        return AjaxResult.success(jsonStr);
+    }
 
 
 

+ 14 - 12
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/config/ElasticSearchConfig.java

@@ -1,3 +1,4 @@
+/*
 package com.dgtis.data.config;
 
 
@@ -12,6 +13,7 @@ import org.springframework.context.annotation.Configuration;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
+*/
 /**
  * @author koucx
  * @version 1.0
@@ -20,18 +22,11 @@ import java.net.UnknownHostException;
  * @copyright (c) 2019 LuoYang DGT Co'Ltd Inc. All rights reserved.
  * @date 2021-01-21
  * @since JDK1.8
- */
+ *//*
+
 @Configuration
 public class ElasticSearchConfig {
 
-    @Value("${elasticsearch.host}")
-    private String esHost;
-
-    @Value("${elasticsearch.port}")
-    private int esPort;
-
-    @Value("${elasticsearch.cluster.name}")
-    private String esName;
 
     @Bean
     public TransportClient esClient() throws UnknownHostException {
@@ -39,15 +34,22 @@ public class ElasticSearchConfig {
         try {
             Settings settings = Settings.builder()
                     .put("client.transport.sniff", true)
-                    .put("cluster.name", this.esName)
+                    .put("cluster.name", "cluster")
                     .build();
 
-            TransportAddress master = new TransportAddress(InetAddress.getByName(esHost), esPort);
+            TransportAddress master = new TransportAddress(InetAddress.getByName("10.32.2.230"), 9300);
+            TransportAddress master2 = new TransportAddress(InetAddress.getByName("10.32.2.231"), 9300);
+            TransportAddress master3 = new TransportAddress(InetAddress.getByName("10.32.2.232"), 9300);
+            TransportAddress master4 = new TransportAddress(InetAddress.getByName("10.32.2.233"), 9300);
+            TransportAddress master5 = new TransportAddress(InetAddress.getByName("10.32.2.234"), 9300);
 
-            client = new PreBuiltTransportClient(settings).addTransportAddress(master);
+            client = new PreBuiltTransportClient(settings).
+                    addTransportAddress(master).addTransportAddress(master2).
+                    addTransportAddress(master3).addTransportAddress(master4).addTransportAddress(master5);
         } catch (Exception e) {
             e.printStackTrace();
         }
         return client;
     }
 }
+*/

+ 1 - 1
dgtis-modules/dgtis-modules-data/src/main/resources/bootstrap.yml

@@ -9,7 +9,7 @@ elasticsearch:
   cluster:
     name: cluster
   host: 10.32.2.230
-  port: 9200
+  port: 9300
 
 # Spring
 spring: