# Check if index exist in elasticsearch 8.2

**URL:** <https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 22, 2022, 3:13pm UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356 "2022-05-22T15:13:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![avnere](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@avnere](https://discuss.elastic.co/u/avnere)\
**Post date:** [May 22, 2022, 3:13pm UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/1 "2022-05-22T15:13:24Z")

</div>

Hi,

How do I check if index exist in JAVA API 8.2.

In v.7.x I used:

```auto
GetIndexRequest request = new GetIndexRequest("yourindexname");
restHighLevelclient.indices().exists(request, RequestOptions.DEFAULT);

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 22, 2022, 6:30pm UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/2 "2022-05-22T18:30:04Z")

</div>

Hi!!  
Try:

> var result = client.indices().exists(ExistsRequest.of(e -\> e.index("name\_index")));

---

<div class="post-metadata">

**Author:** ![avnere](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@avnere](https://discuss.elastic.co/u/avnere)\
**Post date:** [May 23, 2022, 6:21am UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/3 "2022-05-23T06:21:11Z")

</div>

RestHighLevelClient is deprecated in 8.2 so I cant use client.indices().exists.  
RestHighLevelClient is changed to RestClient.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 23, 2022, 11:26am UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/4 "2022-05-23T11:26:58Z")

</div>

My code is Java API Client

---

<div class="post-metadata">

**Author:** ![avnere](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@avnere](https://discuss.elastic.co/u/avnere)\
**Post date:** [May 23, 2022, 11:59am UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/5 "2022-05-23T11:59:16Z")

</div>

version 8.2?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 23, 2022, 12:39pm UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/6 "2022-05-23T12:39:25Z")

</div>

> [@avnere](#):
>
> versão 8.2?

Yes.

---

<div class="post-metadata">

**Author:** ![avnere](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@avnere](https://discuss.elastic.co/u/avnere)\
**Post date:** [May 23, 2022, 2:22pm UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/7 "2022-05-23T14:22:37Z")

</div>

what is the client object in:

```auto
var result = client.indices().exists(ExistsRequest.of(e -> e.index("name_index")));

```

I just find out that the new way is:

````auto
Response response = client.performRequest(new Request("HEAD", "/" + index));
	return response.getStatusLine().getStatusCode() == 200;```
````

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 23, 2022, 2:32pm UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/8 "2022-05-23T14:32:57Z")

</div>

> [@avnere](#):
>
> Acabei de descobrir que a nova maneira é:

You are using low-level client.

My code:

```
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
ElasticsearchClient client = new ElasticsearchClient(transport);
BooleanResponse result = client.indices().exists(ExistsRequest.of(e -> e.index("xpto")));
System.out.println("Exists indices: " + result.value());

```

---

<div class="post-metadata">

**Author:** ![anime\_lover](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anime_lover/32/100265_2.png) [@anime\_lover](https://discuss.elastic.co/u/anime_lover)\
**Post date:** [May 24, 2022, 11:47am UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/9 "2022-05-24T11:47:07Z")

</div>

how to pass security parameter in this case ...username and password of Elasticsearch

---

<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:** [June 21, 2022, 11:47am UTC](https://discuss.elastic.co/t/check-if-index-exist-in-elasticsearch-8-2/305356/10 "2022-06-21T11:47:50Z")

</div>

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