0

I have elasticsearch 8.6.1 version installed. I'm trying to add data using java API client. Code snippet is :

restClient = restClientBuilder.build();
client = new ElasticsearchClient(new RestClientTransport(restClient, new JacksonJsonpMapper())); 

// dummy data
Employee emp = new Employee("E01", (short)32, "Sunil Kumar"); 
        
try {
    client.index(i -> i
                    .index("employee")
                    .id(emp.getEmpID())
                    .document(emp));
    } catch (ElasticsearchException | IOException e) {}

But while performing basic index operation giving Error:
Unable to execute bulk request. co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch._types.ShardStatistics: jakarta.json.JsonException: Unable to get a JsonProvider. Check your classpath or thread context classloader. (JSON path: items[0]._shards.total) (line no=1, column no=155, offset=-1)

Following are depedency jars in classpath:

  1. elasticsearch-java-8.6.2.jar
  2. jackson-databind-2.12.3.jar
  3. jakarta.json-api-2.0.1.jar

Please help on how it can be resolved.

1 Answer 1

0

I resolved the issue. The way to solve the problem is to add the provider classes implementation library. As explained here https://github.com/elastic/elasticsearch-java/pull/63 an implementation of provider class is Eclipse Parsson. So adding the dependency of provider implementation 'org.eclipse.parsson:parsson:1.1.1' and the api interface 'jakarta.json:jakarta.json-api:2.1.1' is a working solution.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.