文章目录

  • **java客户端连接elasticsearch报错:Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{weOTC4XgTLe1d-_ApCpjmg}{localhost}{127.0.0.1:8200}]]**
    • 案例一、由于java客户端配置es端口不正确,导致报Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{weOTC4XgTLe1d-_ApCpjmg}{localhost}{127.0.0.1:8200}]]
    • 案例二、由于elasticsearch java客户端settings设置不正确导致报Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{weOTC4XgTLe1d-_ApCpjmg}{localhost}{127.0.0.1:8200}]]

java客户端连接elasticsearch报错:Exception in thread “main” NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{weOTC4XgTLe1d-_ApCpjmg}{localhost}{127.0.0.1:8200}]]

案例一、由于java客户端配置es端口不正确,导致报Exception in thread “main” NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{weOTC4XgTLe1d-_ApCpjmg}{localhost}{127.0.0.1:8200}]]

详细报错信息:

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{weOTC4XgTLe1d-_ApCpjmg}{localhost}{127.0.0.1:8200}]]at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:352)at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:248)at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:57)at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:394)at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:396)at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:385)at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:45)at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:52)at com.troll.bigdata.component.example.elasticsearch.example.ConnectES.main(ConnectES.java:58)

报错代码详细:

import com.google.gson.Gson;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.transport.client.PreBuiltTransportClient;import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;public class ConnectES {public static void main(String[] args) {/*** 官方参考链接* https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html*/// 读取ES配置String host = "localhost";int port = 8200;  //  *说明:* 虚拟机端口映射为 9200->8200,9300->8300// 打印es连接信息System.out.println("host:" + host + ",port:" + port);//        // 获取settingsSettings settings = Settings.builder().put("client.transport.sniff", false).put("cluster.name", "troll_es_dev").build();// 客户端对象TransportClient client = null;// 建立ES连接try {client = new PreBuiltTransportClient(settings).addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));} catch (UnknownHostException e) {e.printStackTrace();}// json拼装String json = "{" +"\"uid\":1,"+"\"user\":\"kimchy\"," +"\"postDate\":\"2013-01-30\"," +"\"message\":\"trying out Elasticsearch\"" +"}";// 执行apiIndexResponse response = client.prepareIndex("twitter", "_doc","1").setSource(json, XContentType.JSON).get();// 提取返回值,放入map,便于查看Map<String,Object> rep = new HashMap<String, Object>();// Index namerep.put("_index",response.getIndex());// Type namerep.put("_type",response.getType());// Document ID (generated or not)rep.put("_id",response.getId());// Versionrep.put("_version",response.getVersion());// status has stored current instance statement.rep.put("status",response.status().getStatus());// 打印返回值,转json是为了方便查看Gson gson = new Gson();System.out.println(gson.toJson(rep));// 释放客户端client.close();}
}

分析问题,需要注意端口号为9300对应的端口,而非9200对应的端口;关于elasticsearch 9200端口和9300端口的区别为:

9200作为Http协议,主要用于外部通讯
9300作为Tcp协议,jar之间就是通过tcp协议通讯
ES集群之间是通过9300进行通讯

这里将8200改为8300即可。

端口号修改后输出为:

{"_index":“twitter-new”,"_type":"_doc","_id":“1”,"_version":11,“status”:200}

案例二、由于elasticsearch java客户端settings设置不正确导致报Exception in thread “main” NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{weOTC4XgTLe1d-_ApCpjmg}{localhost}{127.0.0.1:8200}]]

报错信息:

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{mgnUEG8FSQGqiYp6XPo4hA}{localhost}{127.0.0.1:8300}]]at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:352)at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:248)at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:57)at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:394)at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:396)at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:385)at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:45)at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:52)at com.troll.bigdata.component.example.elasticsearch.example.ConnectES.main(ConnectES.java:59)

报错代码如下:

import com.google.gson.Gson;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.transport.client.PreBuiltTransportClient;import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;public class ConnectES {public static void main(String[] args) {/*** 官方参考链接* https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html*/// 读取ES配置String host = "localhost";int port = 8300;// 打印es连接信息System.out.println("host:" + host + ",port:" + port);// 客户端对象TransportClient client = null;// 建立ES连接try {client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));} catch (UnknownHostException e) {e.printStackTrace();}// json拼装String json = "{" +"\"uid\":1,"+"\"user\":\"kimchy\"," +"\"postDate\":\"2013-01-30\"," +"\"message\":\"trying out Elasticsearch\"" +"}";// 执行apiIndexResponse response = client.prepareIndex("twitter", "_doc","1").setSource(json, XContentType.JSON).get();// 提取返回值,放入map,便于查看Map<String,Object> rep = new HashMap<String, Object>();// Index namerep.put("_index",response.getIndex());// Type namerep.put("_type",response.getType());// Document ID (generated or not)rep.put("_id",response.getId());// Versionrep.put("_version",response.getVersion());// status has stored current instance statement.rep.put("status",response.status().getStatus());// 打印返回值,转json是为了方便查看Gson gson = new Gson();System.out.println(gson.toJson(rep));// 释放客户端client.close();}
}

此处由于elasticsearch java客户端为设置settings导致,将一下代码进行修改即可:

        // 客户端对象TransportClient client = null;// 建立ES连接try {client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));} catch (UnknownHostException e) {e.printStackTrace();}

改为:

       // 获取settingsSettings settings = Settings.builder().put("client.transport.sniff", false).put("cluster.name", "troll_es_dev").build();// 客户端对象TransportClient client = null;// 建立ES连接try {client = new PreBuiltTransportClient(settings).addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));} catch (UnknownHostException e) {e.printStackTrace();}

处理后,问题解决:

{"_index":“twitter-new”,"_type":"_doc","_id":“1”,"_version":11,“status”:200}

Elasticsearch常见报错和处理方法相关推荐

  1. kubeadm常见报错和解决方法

    kubeadm常见报错和解决方法 参考文章: (1)kubeadm常见报错和解决方法 (2)https://www.cnblogs.com/only-me/p/10219903.html 备忘一下.

  2. k8s常见报错以及解决方法(一)

    k8s常见报错以及解决方法(一) 现阶段我们使用k8s集群越来越多,随之而来的是一系列的问题,接下来我向大家来介绍一下我遇到的一些问题以及解决方法 一.报错cannot allocate memory ...

  3. Git常见报错及解决方法

    git常见报错解决方法 1.warning: LF will be replaced by CRLF in .idea/workspace.xml. git config --global core. ...

  4. 【全网最详细yolov6】yoloV6调试记录(含训练自己的数据集及常见报错及解决方法)--持续更新ing

    本文手把手教你如何调试最新的yolov6,复现运行COCO2017及训练自己的数据集,目前该项目刚发布,BUG会比较多,调起来一般不会那么顺利,本文含windows+ubuntu,并给出了一些常见问题 ...

  5. Spark常见报错与问题解决方法

    查看Spark日志与排查报错问题的方法请看:https://blog.csdn.net/qq_33588730/article/details/109353336 1. org.apache.spar ...

  6. Weblogic常见报错以及解决方法[转载]

    最近组织内部进行安全升级,由于目前所接触的项目均使用weblogic中间件部署,出现了一系列问题小问题,再此转载一下常见的错误处理方式以便后续查询.转载 追风若水:https://my.oschina ...

  7. python+appium,常见报错与解决方法

    分享自己用python+appium写移动端自动化脚本出现的报错及解决方法,持续更新,希望对和我一样刚开始学习的同学有所帮助,加油ヾ(◍°∇°◍)ノ゙ 报错一: 关键字:Could not find ...

  8. maven jar包冲突常见报错及解决方法

    见到如下错误,可以想到是不是jar包冲突 1.java.lang.NoSuchMethodError 2.java.lang.ClassNotFoundException 3.java.lang.No ...

  9. ueditor百度编辑器常见报错的解决方法

    如果是第一次使用ueditor百度编辑器,或者对它不熟悉的情况下使用,会出现一些常见问题和报错.怎么使用建议参考ueditor官网,这里只谈一些常见错误. 问题:'UE' is not defind ...

最新文章

  1. 如何快速评估16S rRNA基因引物的覆盖率及特异性
  2. oracle中的备注的配置与查询
  3. php 比较数组中的元素,php – 比较多维数组中的元素
  4. linux中强大且常用命令:find、grep
  5. 飞鸽传书文件传输实现原理
  6. 网站部署后Parser Error Message: Could not load type 的解决方案
  7. Android应用开发之使用Socket进行大文件断点上传续传
  8. 【模板篇】树状数组们(三)
  9. Oracle数据库存储过程 ,去除给定字符串中重复的字符串
  10. 深度学习2.0-21.Keras高层API-compilefitEvaluatePredict
  11. 帆软扩展单元格运算的相关应用
  12. Java全栈程序员之03:Ubuntu下安装idea
  13. 希捷硬盘固件修复工具_希捷发布旗下首款PCIe 4.0固态盘酷玩520:东芝96层TLC、最高5GB/s...
  14. 2020年计算机组装行业,组装电脑已成夕阳产业?DIY装机发展的道路在何方?
  15. 重做完系统后服务器打印机用不,重装系统后打印机不能使用?重装系统后打印机打印乱码...
  16. 〖Python〗-- Django基础
  17. CTF-web-秋名山老司机
  18. LM2596 负载增大,电压降低的问题
  19. vue中对echarts折线图设置基准线/警告线,可在输入框输入想要的值,并改变已有的基准线的值。
  20. 整理了643个计算机夏令营预推免招生项目,特点如下:

热门文章

  1. 女人要记住的亦舒75句话
  2. 俄罗斯 搜索引擎 邮箱创建
  3. MongoDB3.2 - 4.2 新特性解读
  4. 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
  5. 使用Python库valuequant和利润表历史数据计算股权价值
  6. 基于Python的个人足迹地图绘制设计
  7. 实验五 java gui(预习报告)
  8. 密室逃脱2 古堡迷城
  9. 头条号文章原创权益再降低申请门槛,人人都可以申请
  10. Win10设置默认英文输入法