Opensearch stored indices and documents are lost after restarting the opensearch server

I’m using Opensearch 1.0.0 on Docker. I’m using python client for opensearch. As in the documentation for python client, I’m running the following code block


from opensearchpy import OpenSearch

host = 'localhost'
port = 9200
auth = ('admin', 'admin')

client = OpenSearch(
    hosts = [{'host': host, 'port': port}],
    http_compress = True, # enables gzip compression for request bodies
    http_auth = auth,
    # client_cert = client_cert_path,
    # client_key = client_key_path,
    use_ssl = True,
    verify_certs = False,
    ssl_assert_hostname = False,
    ssl_show_warn = False
)

index_name = 'python-test-index'
index_body = {
  'settings': {
    'index': {
      'number_of_shards': 4
    }
  }
}

response = client.indices.create(index_name, body=index_body)
print('\nCreating index:')
print(response)

When I run this for the first time, It runs fine. And gives the following output.

Creating index:
{'acknowledged': True, 'shards_acknowledged': True, 'index': 'python-test-index'}

And if I tries to run it more then once, It throws a error indication that the index is already there. That is what I expected.

But If I ran the same block after stopping the docker container and restarting it, It creates the index again, Which means the existing index and data has gone after restarting the container.

How to create a permanent index in opensearch via python client?

Thank you

Hi ,

I am also using opensearch, python client for pushing data to index.
It works fine for me.

My Opensearch version -2.0.0, use docker-compose.yml from site.

Docker-Desktop Version- 4.8.0
OS -Windows 10