Skip to content

Commit 32d5488

Browse files
committed
添加elasticsearch学习代码
Former-commit-id: 6959010
1 parent db08d69 commit 32d5488

5 files changed

Lines changed: 607 additions & 0 deletions

File tree

code/elasticsearch-java/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>caojx.learn</groupId>
6+
<artifactId>elasticsearch-java</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>elasticsearch-java</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>junit</groupId>
20+
<artifactId>junit</artifactId>
21+
<version>3.8.1</version>
22+
</dependency>
23+
24+
<!--elasticsearch-->
25+
<dependency>
26+
<groupId>org.elasticsearch.client</groupId>
27+
<artifactId>transport</artifactId>
28+
<version>5.5.2</version>
29+
</dependency>
30+
31+
<!--json-->
32+
<dependency>
33+
<groupId>com.alibaba</groupId>
34+
<artifactId>fastjson</artifactId>
35+
<version>1.2.46</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>junit</groupId>
39+
<artifactId>junit</artifactId>
40+
<version>RELEASE</version>
41+
</dependency>
42+
43+
</dependencies>
44+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package caojx.learn;
2+
3+
/**
4+
* Hello world!
5+
*
6+
*/
7+
public class App
8+
{
9+
public static void main( String[] args )
10+
{
11+
System.out.println( "Hello World!" );
12+
}
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package caojx.learn.base;
2+
3+
import org.elasticsearch.client.transport.TransportClient;
4+
import org.elasticsearch.common.settings.Settings;
5+
import org.elasticsearch.common.transport.InetSocketTransportAddress;
6+
import org.elasticsearch.transport.client.PreBuiltTransportClient;
7+
8+
import java.net.InetAddress;
9+
10+
/**
11+
* @author caojx
12+
* Created on 2018/3/29 下午下午1:02
13+
*/
14+
public class ConnectTest {
15+
16+
private static String host="192.168.1.108"; // 服务器地址
17+
private static int port=9300; // 端口
18+
19+
public static void main(String[] args) throws Exception{
20+
//这里有个Settings 等后面讲到集群再详解
21+
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
22+
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ConnectTest.host),ConnectTest.port));
23+
System.out.println(client);
24+
client.close();
25+
}
26+
}

0 commit comments

Comments
 (0)