1 public class ESIndexMapping {
2
3 private static String host="192.168.56.3";
4 private static int port=9300;
5
6 public static final String CLUSTER_NAME = "my-application";
7
8 private TransportClient client=null;
9
10 private static Settings settings= Settings.builder()
11 .put("cluster.name",CLUSTER_NAME)
12 .put("client.transport.sniff", true)
13 .build();
14
15
16 @SuppressWarnings({ "resource", "unchecked" })
17 @Before
18 public void getClient() throws Exception {
19 try {
20 client = new PreBuiltTransportClient(settings)
21 .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host),port));
22 } catch (Exception e) {
23
24 e.printStackTrace();
25 }
26 }
27
28
29 @After
30 public void close() {
31 if(client!=null) {
32 client.close();
33 }
34 }
35 }