I am trying to use Elasticsearch 8.5 and its associated RestClient.I am having some difficulties using it and I am not able to make sense of this as to why this error message will be thrown.Looking for some guidance on how to move ahead on this.
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
RestClientBuilder builder = RestClient.builder(
new HttpHost("somehost", 443))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder
.setDefaultCredentialsProvider(credentialsProvider));
RestClient restClient = builder.build();
System.out.println(restClient.getNodes());
System.out.println(restClient.isRunning());
try{
ElasticsearchTransport transport = new RestClientTransport(
restClient,
new JacksonJsonpMapper()
);
ElasticsearchClient esClient = new ElasticsearchClient(transport);
// IndexRequest<Profile> request=new IndexRequest.Builder<Profile>().index("");
// esClient.index()
//index th edata first
// User user=new User("Bhanu","Marwaha");
//
// IndexResponse response = esClient.index(i -> i
// .index("user")
// .id("1")
// .document(user)
// );
TermQuery termQuery= QueryBuilders.term().field("title").value("Rocky Mountain").build();
SearchRequest searchRequest = new SearchRequest.Builder().index("search-profile").query(termQuery._toQuery())
.build();
SearchResponse<Places> response=null;
try {
response= esClient.search(searchRequest, Places.class);
response.hits().hits().stream().forEach(modelHit -> System.out.println(modelHit.source().getVisitors()));
}
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
Error I get:
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Client': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (ByteArrayInputStream); line: 1, column: 8]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2391)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:745)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidToken(UTF8StreamJsonParser.java:3635)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2734)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:902)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:794)
at co.elastic.clients.json.jackson.JacksonJsonpParser.fetchNextToken(JacksonJsonpParser.java:89)
... 8 more