i run the es on docker , and it worked well
when i wanna use java client it throw exception:
NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{fe2lzyyASMa7y-5slCY0rw}{localhost}{127.0.0.1:9300}]]
this is my pom parts:
and this is my code:
@RunWith(SpringRunner.class)
@SpringBootTest
public class Test1ApplicationTests {
private static TransportClient client;
@Before
public void before() {
try {
client = new PreBuiltTransportClient(
Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", true)
.build())
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
@Test
public void CreateJSON() {
String json = "{" +
"\"user\":\"kimchy\"," +
"\"postDate\":\"2013-01-30\"," +
"\"message\":\"trying out Elasticsearch\"" +
"}";
IndexResponse response = client.prepareIndex("twitter", "tweet")
.setSource(json, XContentType.JSON)
.get();
System.out.println(response.getResult());
}
}