Hi
I did a one click deployment of elastic search cluster on Google cloud. It is using 2.4.4 version of elastic search and i am using 5.4.0 version in pom.xml
org.elasticsearch.client
transport
5.4.0
I keep on getting NoNodeAvailableException always. I am doing Post call and here is the code for that.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
LOG.info("Entered doPost");
String urlPath = req.getPathInfo();
String id = urlPath.split("/")[1];
if(StringUtils.isNotBlank(id)) {
LOG.info("Reached here");
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch-cluster")
.put("client.transport.sniff",true)
.build();
Client client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("xx.xx.xx.10"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("xx.xx.xx.11"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("xx.xx.xx.12"), 9300));
try {
if (req.getInputStream() != null) {
BufferedReader in = new BufferedReader(
new InputStreamReader(req.getInputStream()));
String inputLine;
StringBuffer sdf = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
sdf.append(inputLine);
}
in.close();
String json = sdf.toString();
if (StringUtils.isNotBlank(json)) {
IndexResponse response = client.prepareIndex("twitter","tweet",id).setSource(json).execute().actionGet();
//
// Index name
String _index = response.getIndex();
// Type name
String _type = response.getType();
// Document ID (generated or not)
String _id = response.getId();
// Version (if it's the first time you index this document, you will get: 1)
long _version = response.getVersion();
// status has stored current instance statement.
RestStatus status = response.status();
Response response1 = Response.builder().index(_index).type1(_type).version(_version).id(_id).status(status).build();
String ress = new Gson().toJson(response1);
LOG.info("*****ress***** " + ress);
if (StringUtils.isNotBlank(ress)) {
LOG.info("response " + ress);
resp.setStatus(HttpServletResponse.SC_CREATED);
PrintWriter out = resp.getWriter();
out.println(ress);
out.close();
out.flush();
resp.getWriter().close();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
client.close();
}
Your help would really appreciated.
Regards
Rohit