ElasticsearchStatusException[Unable to parse response body] [HTTP/1.1 301 Moved Permanently]

Hello Everyone,

Key Points:

  1. I am able to get response from Elastic search (deployed on AWS) using postman at my machine.
  2. However when I am trying to use elasticsearch API to get the response, I am getting ElasticsearchStatusException[Unable to parse response body].

==========================
Explanation starts from here :

I am hitting my Elasticsearch (deployed on AWS) using springboot microservice, however getting below error :

< ElasticsearchStatusException[Unable to parse response body]; nested: ResponseException[method [POST], host [http://b6vv-eks-kibana.verizon.com], URI [/_search?rest_total_hits_as_int=true&typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 301 Moved Permanently]

/>

Source Code as below :

I am using below source code as my implementation, which is copied from Elasticsearch API (Search API | Java REST Client [7.17] | Elastic)

<
RestHighLevelClient esClient = new RestHighLevelClient(RestClient.builder(new HttpHost("my-elastic-search-host-name")));
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = esClient.search(searchRequest, RequestOptions.DEFAULT);
/>

==================================
Followed elastic community discussion as below :

I checked these link in elastic discussion and did not found helpful.

  1. ElasticsearchStatusException[Unable to parse response body]; nested: ResponseException[method [POST] - #2 by TimV

  2. org.elasticsearch.ElasticsearchStatusException: Unable to parse response body

Please suggest, as all the related help in community is not answered with any user.

Elasticsearch never responds with status code 301, so it seems the problem is that you're talking to something other than Elasticsearch.

1 Like

Thank you David for quick turn around, however my esClient shows it is pointing to my elastic hostname.
I am able to use Elasticsearch with the same hostname.

For reference I am able to get all the indices from my Elasticsearch using the same host name pointing to same esClient.
Please find reference as below :

<
GetIndexRequest indexRequest = new GetIndexRequest("*");
GetIndexResponse response = esClient.indices().get(indexRequest, RequestOptions.DEFAULT);
/>

This issue got fixed using below changes :

<
RestHighLevelClient esClient = new RestHighLevelClient(RestClient.builder(new HttpHost("my-elastic-search-host-name", port, "https")));
/>