I'm using the Python ElasticSearch DSL library to interface with an ElasticSearch cluster.
I use the Document ViewModel that the library provides through the base class elasticsearch_dsl.DocType and was using DocType.init() to create my indices previously:
import elasticsearch_dsl as dsl
class SomeDocument(dsl.DocType):
class Meta:
doc_type = some_document
index = some_document
instance = SomeDocument()
instance.init()
But now I want to add an alias to the indices created here on Elastic's initialization, as well as change the number of shards of the indices. The code that I've come up for that is:
import elasticsearch_dsl as dsl
class SomeDocument(dsl.DocType):
class Meta:
doc_type = some_document
index = some_document
instance = SomeDocument()
doc_index = dsl.Index('some_document_v1')
doc_index.aliases(some_document={})
if not doc_index.exists():
doc_index.create()
My hope is that the SomeDocument ViewModel uses the some_document index for its requests, although some_document is now an alias that points to the index some_document_v1.
When I try to run this code, I get:
index some_document_v1 already exists
Even though I am checking index.exists() before calling index.create(). If I clear the ElasticSearch instance of its data, the server just crashes and responds 400 Bad Request to any request I send to it.
What am I doing wrong here?