RestHighLevelClient - Unable to parse response body

I'm new to ES and wiring up my first sample in a Java Spring Boot app. I'm using the pure
RestHighLevelClient approach but seem to keep getting a Unable to parse response body message when I call the client.

I'm a bit stuck on how to populate SearchResponse, any thoughts on how to troubleshoot?

// Config class

   @Bean
    public RestHighLevelClient client() {
        return new RestHighLevelClient(RestClient.builder(new HttpHost(hostUrl, port, scheme)));
    }
	
// Proxy class

    public List<ResidentModel> getInitialSample() {

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.termQuery("first_name", "john"));
        searchSourceBuilder.from(0);
        searchSourceBuilder.size(5);
        SearchRequest searchRequest = new SearchRequest(new String[] {"myresidents"}, searchSourceBuilder);

        SearchResponse searchResponse = null;
        try{
            searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        }catch (ElasticsearchException ex){
            DebugFailedQuery(ex);
        }
        if(searchResponse!=null){
            SearchHits hits = searchResponse.getHits();
        }
        return null;        // still need to deserialize the response.
    }

I figured it out. Elastic was installed on a Kubernetes cluster I was trying to hit elasticsearch.mycompany.com:80 and the NginX ingress controller was not configured with SSL but had the following flag set trying to redirect access.

nginx.ingress.kubernetes.io/force-ssl-redirect: "true"

So if you get a "Unable to parse response body" message (mine was from the request not the response) and if you spot a " 308 Permanent Redirect" in the stack trace, the issues could be on the server hosting elastic.

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