30
30
31
31
import logging
32
32
33
- from elasticsearch import Elasticsearch , logger as elastic_logger
33
+ from elasticsearch import (
34
+ Elasticsearch ,
35
+ NotFoundError ,
36
+ logger as elastic_logger
37
+ )
34
38
from elasticsearch .helpers import streaming_bulk , BulkIndexError
35
39
36
40
from msc_pygeoapi .connector .base import BaseConnector
@@ -146,7 +150,7 @@ def exists(self, index_name):
146
150
147
151
:param index: index name
148
152
149
- :return : `bool` of result
153
+ :returns : `bool` of result
150
154
"""
151
155
152
156
return self .Elasticsearch .indices .exists (index = index_name )
@@ -183,7 +187,7 @@ def create_template(self, name, settings):
183
187
:param name: `str` index template name
184
188
:param settings: `dict` settings dictionnary for index template
185
189
186
- :return : `bool` of index template creation status
190
+ :returns : `bool` of index template creation status
187
191
"""
188
192
189
193
if not self .Elasticsearch .indices .exists_template (name = name ):
@@ -197,7 +201,7 @@ def delete_template(self, name):
197
201
198
202
:param name: `str` index template name
199
203
200
- :return : `bool` of index template deletion status
204
+ :returns : `bool` of index template deletion status
201
205
"""
202
206
203
207
if self .Elasticsearch .indices .exists_template (name = name ):
@@ -214,7 +218,7 @@ def create_alias(self, alias, index, overwrite=False):
214
218
:param overwrite: `bool` indicating whether to overwrite alias if it
215
219
already exists
216
220
217
- :return : `bool` of index alias creation status
221
+ :returns : `bool` of index alias creation status
218
222
"""
219
223
220
224
if not self .Elasticsearch .indices .exists_alias (name = alias ):
@@ -234,6 +238,25 @@ def create_alias(self, alias, index, overwrite=False):
234
238
235
239
return True
236
240
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
+
237
260
def submit_elastic_package (
238
261
self , package , request_size = 10000 , refresh = False
239
262
):
@@ -302,7 +325,7 @@ def update_by_query(self, query, name):
302
325
:param query: `str` query template
303
326
:param name: `str` index name
304
327
305
- :return : `bool` of index update status
328
+ :returns : `bool` of index update status
306
329
"""
307
330
308
331
self .Elasticsearch .update_by_query (
0 commit comments