简体   繁体   中英

How do we create an IndexRequest in Java for ElasticSearch 7.4.2 Java High Level REST Client?

I am trying to insert data into ElasticSearch (version 7.4.2) hosted on bonsai.io cloud. When I try to create an IndexRequest & IndexResponse in my client code in Java (Java High Level REST client), there is no import available for both IndexRequest & IndexResponse.

My pom.xml has the following dependencies:

  <dependencies>
     <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>7.4.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.25</version>
    </dependency>

  </dependencies>

I even tried adding the below dependency to my pom.xml

<dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>7.4.2</version>
  </dependency>

Can somebody help me solve this issue in 7.4.2 version?

Please check this GitHub repo which is using ES 7.3 with java high-level rest client. You can change the ES client version in pom.xml and ready to go, as these are just minor version change, there isn't really any change in IndexRequest and indexResponse APIs.

Please see this of com.indore.GalaxyApp#createIndex method, where IndexRequest is created.

You can change your elasticsearch details config.yml and read the README section on how to start the app.

Let me know if you need more information.

Error occurred as the maven build was unable to read the jar manifest for following 2 jar files.

1) .m2/repository/org/elasticsearch/elasticsearch/7.4.2/elasticsearch-7.4.2.jar 2) .m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/7.4.2/elasticsearch-rest-high-level-client-7.4.2.jar

Solved the error by deleting the .m2 directory locally. Running the pom.xml after this as a maven build fixed the error and the above 2 jars were installed correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM