# IndexExists() with wildcard index name always returns true after upgrading to NEST 5.4.0

**URL:** <https://discuss.elastic.co/t/indexexists-with-wildcard-index-name-always-returns-true-after-upgrading-to-nest-5-4-0/94183>\
**Category:** Elasticsearch\
**Created:** [July 22, 2017, 2:04am UTC](https://discuss.elastic.co/t/indexexists-with-wildcard-index-name-always-returns-true-after-upgrading-to-nest-5-4-0/94183 "2017-07-22T02:04:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jqin](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@jqin](https://discuss.elastic.co/u/jqin)\
**Post date:** [July 22, 2017, 2:04am UTC](https://discuss.elastic.co/t/indexexists-with-wildcard-index-name-always-returns-true-after-upgrading-to-nest-5-4-0/94183/1 "2017-07-22T02:04:42Z")

</div>

Hi, I had the following code that used to work in NEST 2.4.1 and Elasticsearch 2.3.1 :  
var indices = Indices.Index("prefix\*");  
while (myClient.IndexExists(indices).Exists) {  
//code to delete them  
}  
I recently upgraded to NEST 5.4.0 and Elasticsearch 5.5.0, and the above code stopped working. The "while" condition is always true and the loop becomes infinite. (I've verified all indices are deleted.) Can anyone tell me why and how to check if indices with a specified prefix exist? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [July 28, 2017, 7:02am UTC](https://discuss.elastic.co/t/indexexists-with-wildcard-index-name-always-returns-true-after-upgrading-to-nest-5-4-0/94183/2 "2017-07-28T07:02:28Z")

</div>

Sadly, this is a bug in Elasticsearch that is due to be fixed in the next release. It's closely related to changes as part of

- [https://github.com/elastic/elasticsearch/pull/25043](https://github.com/elastic/elasticsearch/pull/25043)

and

- [https://github.com/elastic/elasticsearch/pull/23192](https://github.com/elastic/elasticsearch/pull/23192)

In the meantime, if you're rolling with the default behaviour of the client to not throw exceptions, simply issuing

```
client.DeleteIndex("prefix*");

```

will be sufficient to delete the indices, even if they don't exist.

---

<div class="post-metadata">

**Author:** ![jasontedor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasontedor/32/66992_2.png) [@jasontedor](https://discuss.elastic.co/u/jasontedor)\
**Post date:** [July 30, 2017, 5:55am UTC](https://discuss.elastic.co/t/indexexists-with-wildcard-index-name-always-returns-true-after-upgrading-to-nest-5-4-0/94183/3 "2017-07-30T05:55:30Z")

</div>

I initially told @forloop this is a bug but after doing my due diligence here, I'm now going to say that is not and this behavior is intended (so sorry for any confusion this causes you). Instead, to obtain the behavior that you are desiring you should add the parameter `allow_no_indices=false` to the REST request. Yes, this is change from previous behavior for `HEAD` where this was not necessary but it was a bug that `HEAD` and `GET` behaved differently. They are aligned now so, and the behavior you're looking for ways always present on `GET` with `allow_no_indices=false`. I hope that helps clarify the situation for you.

---

<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:** [August 27, 2017, 5:55am UTC](https://discuss.elastic.co/t/indexexists-with-wildcard-index-name-always-returns-true-after-upgrading-to-nest-5-4-0/94183/4 "2017-08-27T05:55:40Z")

</div>

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