# Unable to cast org.elasticsearch.client.RestClient to org.elasticsearch.client.Client

**URL:** https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [August 11, 2020, 5:42am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488 "2020-08-11T05:42:19Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 11, 2020, 5:42am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/1 "2020-08-11T05:42:19Z")

</div>

Hi, In my code I am casting RestClient to Client. I don't see any runtime error but my application is not coming up due to the following error. Can someone help me  
org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [classname]  
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ESClient' defined in URL [\<\>]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.elasticsearch.client.RestClient cannot be cast to org.elasticsearch.client.Client  
Also, I installed ES 7.8.1 version and I do not see org.elasticsearch.client.RestHighLevelClient in my package. Can you please help

---

<div class="post-metadata">

### Author: ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)
#### Post date: [August 11, 2020, 6:17am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/2 "2020-08-11T06:17:13Z")

</div>

Neither `RestClient` or `RestHighLevelClient` implement the `Client` interface. They are different clients with different methods.

You can't cast them like that.

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 11, 2020, 6:18am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/3 "2020-08-11T06:18:34Z")

</div>

Hmm basically I want to replace TransportClient which implements Client interface. How do I replace it so I can cast to Client.

---

<div class="post-metadata">

### Author: ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)
#### Post date: [August 11, 2020, 6:21am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/4 "2020-08-11T06:21:12Z")

</div>

You cannot do a drop in replacement for `TransportClient`. The `RestHighLevelClient` is the closest match, but it is not identical. You will need to make code changes to switch your application to use `RestHighLevelClient` instead.

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 11, 2020, 6:25am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/5 "2020-08-11T06:25:54Z")

</div>

Thank Tim. I am using ES 7.8.1 and in my package I do not find org.ealsticsearch.client.RestHighLevelClient. It is missing. I only see RestClient. Can you suggest what I am missing here.

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 11, 2020, 6:28am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/6 "2020-08-11T06:28:23Z")

</div>

![Screen Shot 2020-08-10 at 11.27.34 PM](https://us1.discourse-cdn.com/elastic/original/3X/9/7/9726229583ce724cfd3493845d34f23a8608b654.png)

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 11, 2020, 6:28am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/7 "2020-08-11T06:28:35Z")

</div>

I just see restclient

---

<div class="post-metadata">

### Author: ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)
#### Post date: [August 11, 2020, 6:35am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/8 "2020-08-11T06:35:48Z")

</div>

This might help: [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.8/\_how\_to\_migrate.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.8/_how_to_migrate.html)

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 11, 2020, 6:51am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/9 "2020-08-11T06:51:43Z")

</div>

Ok. Thanks Tim. Will try adding the dependency

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 11, 2020, 5:31pm UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/10 "2020-08-11T17:31:48Z")

</div>

Also how do I check if indicies and mapping exists in RestHighLevelClient. In transportclient which implements we do something like this client.admin().indices().prepareExists(index);  
How can I do it using RestHighLevelClient. I don't see any such methods. Please suggest

---

<div class="post-metadata">

### Author: ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)
#### Post date: [August 12, 2020, 1:21am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/11 "2020-08-12T01:21:41Z")

</div>

It sounds like you want `client.indices().exists()`

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 12, 2020, 5:36am UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/12 "2020-08-12T05:36:14Z")

</div>

Thanks Tim. Yes, right now modifying the code.

---

<div class="post-metadata">

### Author: ![elastic78](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@elastic78](https://discuss.elastic.co/u/elastic78)
#### Post date: [August 13, 2020, 8:44pm UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/13 "2020-08-13T20:44:21Z")

</div>

Hi Tim, Currently we are using lucene version 6.6.0; do we need to even upgrade lucene to 8.5.1 if we want to upgrade ES to 7.8.1 or it is independent.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 10, 2020, 8:44pm UTC](https://discuss.elastic.co/t/unable-to-cast-org-elasticsearch-client-restclient-to-org-elasticsearch-client-client/244488/14 "2020-09-10T20:44:28Z")

</div>

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