# Index keeps getting deleted

**URL:** <https://discuss.elastic.co/t/index-keeps-getting-deleted/317859>\
**Category:** Elasticsearch\
**Created:** [November 1, 2022, 3:18am UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859 "2022-11-01T03:18:56Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [November 3, 2022, 2:05pm UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859/21 "2022-11-03T14:05:01Z")

</div>

> [@shivang.ahd](#):
>
> username i am using is ==\> 'elastic'.  
> What doe the error mean...is there any other username ?

The error 401 means that something is wrong with the authentication, the username or the password, you need to check the password and see if it is correct.

---

<div class="post-metadata">

**Author:** ![shivang.ahd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shivang.ahd/32/110992_2.png) [@shivang.ahd](https://discuss.elastic.co/u/shivang.ahd)\
**Post date:** [November 4, 2022, 4:50pm UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859/22 "2022-11-04T16:50:53Z")

</div>

Hi,

I have double checked -- everything is correct.  
Code is:-

```auto
# connect to ES on localhost on port 9200
from ssl import create_default_context
import ssl
# from elasticsearch.connection import create_ssl_context

es = Elasticsearch([{'host': 'localhost', 'port': 9200,'scheme':'https'}],basic_auth=('username', 'password'),
                    verify_certs=False, ssl_show_warn=True,ca_certs='/home/shivang_ahd1234/cacert.pem') # 'certs/transport.p12' 

if es.ping():
	print('Connected to ES!')
else:
	print('Could not connect!')
	# sys.exit()

print(" *********************************************************************************");
print(es.info())

```

error is:

```auto
Could not connect!
*********************************************************************************
/home/shivang_ahd1234/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
/home/shivang_ahd1234/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
---------------------------------------------------------------------------
AuthenticationException Traceback (most recent call last)
Cell In [11], line 16
     13 # sys.exit()
     15 print(" *********************************************************************************");
---> 16 print(es.info())

File ~/miniconda3/lib/python3.9/site-packages/elasticsearch/_sync/client/utils.py:414, in _rewrite_parameters.<locals>.wrapper.<locals>.wrapped(*args, **kwargs)
    411 except KeyError:
    412 pass
--> 414 return api(*args, **kwargs)

File ~/miniconda3/lib/python3.9/site-packages/elasticsearch/_sync/client/ __init__.py:2296, in Elasticsearch.info(self, error_trace, filter_path, human, pretty)
   2294 __query["pretty"] = pretty
   2295 __headers = {"accept": "application/json"}
-> 2296 return self.perform_request( # type: ignore[return-value]
   2297 "GET", __path, params=__ query, headers=__headers
   2298 )

File ~/miniconda3/lib/python3.9/site-packages/elasticsearch/_sync/client/_base.py:321, in BaseClient.perform_request(self, method, path, params, headers, body)
    318 except (ValueError, KeyError, TypeError):
    319 pass
--> 321 raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
    322 message=message, meta=meta, body=resp_body
    323 )
    325 # 'X-Elastic-Product: Elasticsearch' should be on every 2XX response.
    326 if not self._verified_elasticsearch:
    327 # If the header is set we mark the server as verified.

AuthenticationException: AuthenticationException(401, 'security_exception', 'unable to authenticate user [username] for REST request [/]')

```

Please tell me if there is another way to bypass this..

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [November 4, 2022, 4:54pm UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859/23 "2022-11-04T16:54:48Z")

</div>

> [@shivang.ahd](#):
>
> Please tell me if there is another way to bypass this..

There is no bypass, you are getting authentication error.

What user and password are you using? You need to put them in the `basic_auth` option of your code.

```auto
basic_auth=('username', 'password')

```

`username` should be the username you are going to use, like `elastic` and the password is the password for the `elastic` user.

Are you already doing this? From the error log you shared it seems that you are using the literal values of `username` and `password` instead of the name of your user and its password.

> AuthenticationException: AuthenticationException(401, 'security\_exception', 'unable to authenticate user [username] for REST request [/]')

The error you are getting is an authentication error, something is wrong, you may not be passing the correct username or password.

---

<div class="post-metadata">

**Author:** ![shivang.ahd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shivang.ahd/32/110992_2.png) [@shivang.ahd](https://discuss.elastic.co/u/shivang.ahd)\
**Post date:** [November 4, 2022, 5:00pm UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859/24 "2022-11-04T17:00:30Z")

</div>

Hi,

Thanks a lot. I got my mistake.  
I was using the literal string values 'username' and 'password' instead of passing the variable name **username** and **password**.  
Got the output.

---

<div class="post-metadata">

**Author:** ![rafi138](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafi138/32/124986_2.png) [@rafi138](https://discuss.elastic.co/u/rafi138)\
**Post date:** [August 26, 2023, 10:13am UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859/25 "2023-08-26T10:13:10Z")

</div>

Hi [shivang.ahd](https://discuss.elastic.co/u/shivang.ahd), after adding security, Did your problem solve? I mean the issues of auto deleting index

---

<div class="post-metadata">

**Author:** ![No\_Reply](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/no_reply/32/132670_2.png) [@No\_Reply](https://discuss.elastic.co/u/No_Reply)\
**Post date:** [March 15, 2024, 3:03pm UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859/26 "2024-03-15T15:03:53Z")

</div>

Even I am facing same issues. Elasticsearch is deleting my index after every 3 days. PLease help @leandrojmp

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 15, 2024, 3:17pm UTC](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859/27 "2024-03-15T15:17:50Z")

</div>

Do you have security enambled? Is your cluster open to the internet?

[Previous page](https://discuss.elastic.co/t/index-keeps-getting-deleted/317859.md?page=1)
