Skip to content

Commit

Permalink
add aliasing functionality for climate archive loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Dukestep committed Apr 3, 2024
1 parent c2869f6 commit 8eb4c6e
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 38 deletions.
35 changes: 29 additions & 6 deletions msc_pygeoapi/connector/elasticsearch_.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@

import logging

from elasticsearch import Elasticsearch, logger as elastic_logger
from elasticsearch import (
Elasticsearch,
NotFoundError,
logger as elastic_logger
)
from elasticsearch.helpers import streaming_bulk, BulkIndexError

from msc_pygeoapi.connector.base import BaseConnector
Expand Down Expand Up @@ -146,7 +150,7 @@ def exists(self, index_name):
:param index: index name
:return: `bool` of result
:returns: `bool` of result
"""

return self.Elasticsearch.indices.exists(index=index_name)
Expand Down Expand Up @@ -183,7 +187,7 @@ def create_template(self, name, settings):
:param name: `str` index template name
:param settings: `dict` settings dictionnary for index template
:return: `bool` of index template creation status
:returns: `bool` of index template creation status
"""

if not self.Elasticsearch.indices.exists_template(name=name):
Expand All @@ -197,7 +201,7 @@ def delete_template(self, name):
:param name: `str` index template name
:return: `bool` of index template deletion status
:returns: `bool` of index template deletion status
"""

if self.Elasticsearch.indices.exists_template(name=name):
Expand All @@ -214,7 +218,7 @@ def create_alias(self, alias, index, overwrite=False):
:param overwrite: `bool` indicating whether to overwrite alias if it
already exists
:return: `bool` of index alias creation status
:returns: `bool` of index alias creation status
"""

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

return True

def get_alias_indices(self, alias):
"""
get index(es) associated with an alias
:param alias: `str` alias name
:returns: `list` of index names associated with alias
"""

try:
index_list = list(
self.Elasticsearch.indices.get_alias(name=alias).keys()
)
except NotFoundError:
LOGGER.warning(f'Alias {alias} not found')
return None

return index_list

def submit_elastic_package(
self, package, request_size=10000, refresh=False
):
Expand Down Expand Up @@ -302,7 +325,7 @@ def update_by_query(self, query, name):
:param query: `str` query template
:param name: `str` index name
:return: `bool` of index update status
:returns: `bool` of index update status
"""

self.Elasticsearch.update_by_query(
Expand Down
Loading

0 comments on commit 8eb4c6e

Please sign in to comment.