Elasticsearch indices to be created with number_of_replicas as default as 0.
AmirSabjan opened this issue · comments
Description:
Currently, Elasticsearch indices created through Haystack use the default cluster setting of 1 replica shard. For Haystack deployments, it's desirable to have the option to create indices with 0 replicas to optimize resource utilisation.
Proposed Change:
Modify Haystack's self._client.indices.create(index=index, body=settings) call to accept a parameter specifying the desired number of replicas. This parameter should then be incorporated into the settings body passed to the Elasticsearch API.
Example Code:
Python
class ElasticsearchDocumentStore:
def __init__(self, *, hosts: Optional[Hosts] = None, index: str = "default", number_of_replicas=0, **kwargs):
"""
Creates an Elasticsearch index with the specified number of replicas.
Args:
index (str): The name of the index to create.
number_of_replicas (int, optional): The desired number of replicas for the index. Defaults to 0.
"""
settings = {
"number_of_replicas": number_of_replicas
}
if not self._client.indices.exists(index=index):
self._client.indices.create(index=index, body=settings)