in src/es_pii_tool/helpers/elastic_api.py [0:0]
def verify_index(client: 'Elasticsearch', index: str) -> bool:
"""Verify the index exists and is an index, not an alias
:param client: A client connection object
:param index: The index to check
:type client: :py:class:`~.elasticsearch.Elasticsearch`
:type index: str
"""
logger.debug('Verifying index: %s', index)
retval = True
response = {}
try:
response = dict(
client.indices.get_settings(
index=index, expand_wildcards=['open', 'hidden']
)
)
except (ApiError, NotFoundError, TransportError, BadRequestError) as err:
logger.error("Index: '%s' not found. Error: %s", index, err)
retval = False
logger.debug(response)
if len(list(response.keys())) > 1:
# We have more than one key, that means we hit an alias
logger.error('Index %s is one member of an alias.', index)
retval = False
elif list(response.keys())[0] != index:
# There's a 1 to 1 alias, but it is not the index name
logger.error('Index %s is an alias.', index)
retval = False
return retval