ElasticSearch 8.5 and Java Client Error ""com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Client'

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

I guess this API is still in dev phase and not GA.When I debugged the code and went through library classes it showed and response of 400 that is Bad request.Now I don't know how and why it is showing me a bad request
private Response performRequest(final NodeTuple<Iterator> tuple, final InternalRequest request, Exception previousException)
Class RestClient
httpResponse = client.execute(context.requestProducer, context.asyncResponseConsumer, context.context, null).get();
Library builds following request and sends ignore without me setting this in...,making the whole debugging bit more difficult than it really is..

Request{method='POST', endpoint='/search-profile/_search', params={typed_keys=true, ignore=400,401,403,404,405}, entity=[Content-Type: application/vnd.elasticsearch+json; compatible-with=8,Content-Length: 56,Chunked: false], options=RequestOptions{headers=X-Elastic-Client-Meta: es=8.5.1,jv=19,hl=2,t=8.5.1,hc=4.1.5,User-Agent: elastic-java/8.5.1 (Java/19.0.1),Accept: application/vnd.elasticsearch+json; compatible-with=8}}

Response I get:

HTTP/1.0 400 Bad Request [Chunked: false]

1 Like

Also getting the same error.

any answer for this?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.