org.elasticsearch.common.transport.InetSocketTransportAddress 在 Elasticsearch 6 上找不到

org.elasticsearch.common.transport.InetSocketTransportAddress not found on Elasticsearch 6

我的代码在 elasticsearch 5 中运行良好,但是当我从 5 升级到 6 时。它正在显示

org.elasticsearch.common.transport.InetSocketTransportAddress not found

完整的堆栈跟踪:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project elastic-store: Compilation failure
[ERROR] /home/elastic/elastic-store/src/main/java/com/qw/psence/store/es/common/ESClient.java:[12,42] cannot find symbol
[ERROR] symbol:   class InetSocketTransportAddress
[ERROR] location: package org.elasticsearch.common.transport
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]

谁能帮我解决这个问题?

注意:Elaticsearch jar 没问题。

Elastic search 6.0 已删除 InetSocketTransportAddress class。我已经通过将 InetSocketTransportAddress class 替换为 TransportAddress class.

解决了这个问题
// on startup

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        .addTransportAddress(new TransportAddress(InetAddress.getByName("host1"), 9300))
        .addTransportAddress(new TransportAddress(InetAddress.getByName("host2"), 9300));

// on shutdown

client.close();

针对该问题提供了许多解决方案,但我收到此错误是因为,当我尝试使用 SpringBoot 进行基本的 elasticsearch 配置时:

我忘了启动elasticsearch...

:脸掌:

所以,只是:

  1. 在 Elasticsearch 安装目录的 bin 文件夹中打开命令行*
  2. 输入elasticsearch
  3. 按回车键

为确保其正常运行,请在浏览器中打开 http://localhost:9200/。你应该得到一个 JSON 包含名称、cluster_name、elasticsearch 版本等的响应

*(On Windows) 打开 ES_INSTALLATION_DIR\elasticsearch-x.x.x\bin 文件夹,按住 Shift 键,右键单击文件夹区域,然后从下拉菜单中选择 select Open command window here

在我的例子中,问题是由 spring-boot-dependencies 拉入我的项目的 elasticsearch 版本冲突。如果您的 pom 没有继承自 spring-boot-starter-parent 而是使用 dependencyManagement 部分导入 spring-boot-dependencies 并且您需要在类路径上使用旧版本的 elasticsearch 那么这里是解决方案:InetSocketTransportAddress.始终 运行 mvn -Dverbose=true help:effective-pom 并检查有效的 pom 是否存在冲突。 -Dverbose=true 在这里很关键。它允许查看不需要的依赖项来自何处。