Skip to content

Commit 7002129

Browse files
committed
add aliasing functionality for climate archive loader
1 parent c2869f6 commit 7002129

File tree

2 files changed

+138
-38
lines changed

2 files changed

+138
-38
lines changed

msc_pygeoapi/connector/elasticsearch_.py

+29-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030

3131
import logging
3232

33-
from elasticsearch import Elasticsearch, logger as elastic_logger
33+
from elasticsearch import (
34+
Elasticsearch,
35+
NotFoundError,
36+
logger as elastic_logger
37+
)
3438
from elasticsearch.helpers import streaming_bulk, BulkIndexError
3539

3640
from msc_pygeoapi.connector.base import BaseConnector
@@ -146,7 +150,7 @@ def exists(self, index_name):
146150
147151
:param index: index name
148152
149-
:return: `bool` of result
153+
:returns: `bool` of result
150154
"""
151155

152156
return self.Elasticsearch.indices.exists(index=index_name)
@@ -183,7 +187,7 @@ def create_template(self, name, settings):
183187
:param name: `str` index template name
184188
:param settings: `dict` settings dictionnary for index template
185189
186-
:return: `bool` of index template creation status
190+
:returns: `bool` of index template creation status
187191
"""
188192

189193
if not self.Elasticsearch.indices.exists_template(name=name):
@@ -197,7 +201,7 @@ def delete_template(self, name):
197201
198202
:param name: `str` index template name
199203
200-
:return: `bool` of index template deletion status
204+
:returns: `bool` of index template deletion status
201205
"""
202206

203207
if self.Elasticsearch.indices.exists_template(name=name):
@@ -214,7 +218,7 @@ def create_alias(self, alias, index, overwrite=False):
214218
:param overwrite: `bool` indicating whether to overwrite alias if it
215219
already exists
216220
217-
:return: `bool` of index alias creation status
221+
:returns: `bool` of index alias creation status
218222
"""
219223

220224
if not self.Elasticsearch.indices.exists_alias(name=alias):
@@ -234,6 +238,25 @@ def create_alias(self, alias, index, overwrite=False):
234238

235239
return True
236240

241+
def get_alias_indices(self, alias):
242+
"""
243+
get index(es) associated with an alias
244+
245+
:param alias: `str` alias name
246+
247+
:returns: `list` of index names associated with alias
248+
"""
249+
250+
try:
251+
index_list = list(
252+
self.Elasticsearch.indices.get_alias(name=alias).keys()
253+
)
254+
except NotFoundError:
255+
LOGGER.warning(f'Alias {alias} not found')
256+
return None
257+
258+
return index_list
259+
237260
def submit_elastic_package(
238261
self, package, request_size=10000, refresh=False
239262
):
@@ -302,7 +325,7 @@ def update_by_query(self, query, name):
302325
:param query: `str` query template
303326
:param name: `str` index name
304327
305-
:return: `bool` of index update status
328+
:returns: `bool` of index update status
306329
"""
307330

308331
self.Elasticsearch.update_by_query(

0 commit comments

Comments
 (0)