|
|
@@ -0,0 +1,53 @@
|
|
|
+package com.dgtis.data.config;
|
|
|
+
|
|
|
+
|
|
|
+import org.elasticsearch.client.transport.TransportClient;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.common.transport.TransportAddress;
|
|
|
+import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+
|
|
|
+import java.net.InetAddress;
|
|
|
+import java.net.UnknownHostException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author koucx
|
|
|
+ * @version 1.0
|
|
|
+ * @descption: TODO
|
|
|
+ * @company 神州数码通用软件(洛阳)有限公司
|
|
|
+ * @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 {
|
|
|
+ TransportClient client = null;
|
|
|
+ try {
|
|
|
+ Settings settings = Settings.builder()
|
|
|
+ .put("client.transport.sniff", true)
|
|
|
+ .put("cluster.name", this.esName)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ TransportAddress master = new TransportAddress(InetAddress.getByName(esHost), esPort);
|
|
|
+
|
|
|
+ client = new PreBuiltTransportClient(settings).addTransportAddress(master);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return client;
|
|
|
+ }
|
|
|
+}
|