in utils/es.py [0:0]
def get_tsdb_config(client: Elasticsearch, data_stream_name: str, docs_index: int, settings_mappings_index: int):
"""
Get the index name where documents are placed, and mappings and settings for the new TSDB index.
:param client: ES client.
:param data_stream_name:
:param docs_index: number of the index in the data stream with the documents to be moved to the TSDB index.
:param settings_mappings_index: number of the index for the settings and mappings for the TSDB index.
:return: documents index name, settings and mappings for the TSDB index.
"""
data_stream = client.indices.get_data_stream(name=data_stream_name)
n_indexes = len(data_stream["data_streams"][0]["indices"])
# Get the index to use for document retrieval
if docs_index == -1:
docs_index = 0
elif docs_index >= n_indexes:
print("ERROR: Data stream {} has {} indexes. Documents index number {} is not valid.".format(data_stream_name,
n_indexes,
docs_index))
exit(0)
# Get index to use for settings/mappings
if settings_mappings_index == -1:
settings_mappings_index = n_indexes - 1
elif settings_mappings_index >= n_indexes:
print("ERROR: Data stream {} has {} indexes. Settings/mappings index number {} is not valid.".format(
data_stream_name, n_indexes, settings_mappings_index))
exit(0)
docs_index_name = data_stream["data_streams"][0]["indices"][docs_index]["index_name"]
settings_mappings_index_name = data_stream["data_streams"][0]["indices"][settings_mappings_index]["index_name"]
print("Index being used for the documents is {}.".format(docs_index_name))
print("Index being used for the settings and mappings is {}.".format(settings_mappings_index_name))
print()
mappings = client.indices.get_mapping(index=settings_mappings_index_name)[settings_mappings_index_name]["mappings"]
settings = client.indices.get_settings(index=settings_mappings_index_name)[settings_mappings_index_name]["settings"]
settings = get_tsdb_settings(mappings, settings)
return docs_index_name, mappings, settings