我正在尝试使用Java连接到Elasticsearch。这是我的代码的一部分:
private static TransportClient client = null;
public BooleanQuery() {
try {
client = new PreBuiltTransportClient(Settings.EMPTY);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
当我运行此程序时,我得到以下异常:
Exception in thread "main" java.lang.NoSuchMethodError: com.carrotsearch.hppc.ObjectHashSet.equals(Ljava/lang/Object;Ljava/lang/Object;)Z
at com.carrotsearch.hppc.ObjectHashSet.add(ObjectHashSet.java:159)
at com.carrotsearch.hppc.ObjectHashSet.addAll(ObjectHashSet.java:189)
at com.carrotsearch.hppc.ObjectHashSet.from(ObjectHashSet.java:544)
at org.elasticsearch.index.mapper.MapperService.<clinit>(MapperService.java:101)
at org.elasticsearch.common.settings.IndexScopedSettings.<clinit>(IndexScopedSettings.java:60)
at org.elasticsearch.common.settings.SettingsModule.<init>(SettingsModule.java:69)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:138)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:265)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:130)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:116)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:106)
at com.accenture.poc.elasticsearch.BooleanQuery.<init>(BooleanQuery.java:29)
at com.accenture.poc.DataProcessor.main(DataProcessor.java:134)
这是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.accenture</groupId>
<artifactId>poc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>poc</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>info.debatty</groupId>
<artifactId>java-string-similarity</artifactId>
<version>RELEASE</version>
</dependency>
<!-- Dependencies of Wiki -->
<!-- https://mvnrepository.com/artifact/org.fusesource.jdbm/jdbm -->
<dependency>
<groupId>org.fusesource.jdbm</groupId>
<artifactId>jdbm</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.bluestemsoftware.open.maven.tparty</groupId>
<artifactId>xerces-impl</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-compress</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.marmotta</groupId>
<artifactId>marmotta-loader-hbase</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!-- Elasticsearch dependency -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
</project>
错误指向&#34; client = new PreBuiltTransportClient(Settings.EMPTY);&#34;。我不确定这意味着什么?我没有找到任何与此相关的在线信息。任何帮助表示赞赏。
答案 0 :(得分:1)
运行mvn dependency:tree -Dverbose
显示有com.carrotsearch:hppc:jar
的两个版本,(0.4.2,0.7.1)。后者附带了elasticsearch依赖项。第一个来自org.apache.marmotta:marmotta-loader-hbase:jar
。
所以我怀疑你的构建中有hppc.jar
的两个版本,因为当你添加弹性搜索依赖项时,你没有执行干净(mvn clean
)。
因此,请尝试重新构建项目,然后重试:
mvn clean package