1

I am trying to connect to Elasticsearch using Java. Here is the part of my code:

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();
        }
    }

When I run this program, I am getting the below exception:

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)

Here is my 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>

The error is pointing to the line "client = new PreBuiltTransportClient(Settings.EMPTY);". I'm not sure what it means? I didn't find anything online related to this. Any help is appreciated.

2
  • 1
    can you post your pom.xml too? Commented Sep 28, 2017 at 20:57
  • @pleft I have added my pom.xml. It has other dependencies related to the other methods of my eclipse project Commented Sep 28, 2017 at 21:03

1 Answer 1

1

Running an mvn dependency:tree -Dverbose reveals that there are 2 versions of com.carrotsearch:hppc:jar, (0.4.2, 0.7.1). The latter one comes with the addition of the elasticsearch dependencies. The first one comes from org.apache.marmotta:marmotta-loader-hbase:jar.

So I suspect that you have both versions of hppc.jar in your build, because by the time you added the elastic search dependencies you did not perform a clean (mvn clean).

So try clean building your project again and try again:

mvn clean package

Sign up to request clarification or add additional context in comments.

2 Comments

When I do mvn clean package, I am getting compilation errors like: [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] error reading C:\Users\njaiswal\.m2\repository\org\apache\ant\ant\1.10.1\ant-1.10.1.jar; invalid LOC header (bad signature)
This means that the ant jar is corrupted. Delete the ant folder from your m2 repo and let maven download it again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.