|
41 | 41 | from msc_pygeoapi.util import (
|
42 | 42 | check_es_indexes_to_delete,
|
43 | 43 | configure_es_connection,
|
| 44 | + DATETIME_RFC3339_FMT |
44 | 45 | )
|
45 | 46 |
|
46 | 47 |
|
|
60 | 61 | SETTINGS = {
|
61 | 62 | 'order': 0,
|
62 | 63 | 'version': 1,
|
63 |
| - 'index_patterns': [INDEX_BASENAME], |
| 64 | + 'index_patterns': [f'{INDEX_BASENAME}*'], |
64 | 65 | 'settings': {
|
65 | 66 | 'number_of_shards': 1,
|
66 | 67 | 'number_of_replicas': 0
|
|
98 | 99 | },
|
99 | 100 | 'DATETIME': {
|
100 | 101 | 'type': 'date',
|
101 |
| - 'format': 'strict_date_hour_minute_second||strict_date_optional_time' # noqa |
| 102 | + 'format': 'date_time_no_millis||strict_date_optional_time' # noqa |
102 | 103 | },
|
103 | 104 | 'DATETIME_LST': {
|
104 | 105 | 'type': 'date',
|
@@ -174,7 +175,24 @@ def __init__(self, conn_config={}):
|
174 | 175 | BaseLoader.__init__(self)
|
175 | 176 |
|
176 | 177 | self.conn = ElasticsearchConnector(conn_config)
|
177 |
| - self.conn.create_template(INDEX_BASENAME, SETTINGS) |
| 178 | + |
| 179 | + index_template = self.conn.get_template(INDEX_BASENAME) |
| 180 | + |
| 181 | + # compare index template mappping with mapping defined in SETTINGS |
| 182 | + if index_template: |
| 183 | + # if mappings are different, update the index template |
| 184 | + if ( |
| 185 | + index_template[INDEX_BASENAME]['mappings'] |
| 186 | + != SETTINGS['mappings'] |
| 187 | + ): |
| 188 | + LOGGER.info( |
| 189 | + f'Updating {INDEX_BASENAME} index template with mapping changes in provider.' |
| 190 | + ) |
| 191 | + self.conn.create_template( |
| 192 | + INDEX_BASENAME, SETTINGS, overwrite=True |
| 193 | + ) |
| 194 | + else: |
| 195 | + self.conn.create_template(INDEX_BASENAME, SETTINGS) |
178 | 196 |
|
179 | 197 | self.stations = {}
|
180 | 198 | self.read_stations_list()
|
@@ -284,11 +302,10 @@ def generate_observations(self, filepath):
|
284 | 302 | try:
|
285 | 303 | # Convert timestamp to UTC time.
|
286 | 304 | utc_datetime = delocalize_date(date_)
|
287 |
| - utc_datestamp = utc_datetime.strftime('%Y-%m-%d.%H:%M:%S') |
| 305 | + utc_datestamp = utc_datetime.strftime(DATETIME_RFC3339_FMT) |
288 | 306 | # Generate an ID now that all fields are known.
|
289 | 307 | observation_id = f'{station}.{utc_datestamp}'
|
290 | 308 |
|
291 |
| - utc_datestamp = utc_datestamp.replace('.', 'T') |
292 | 309 | except Exception as err:
|
293 | 310 | LOGGER.error(f'Cannot interpret datetime value {date_} in {filepath}' # noqa
|
294 | 311 | f' due to: {err} (skipping)')
|
|
0 commit comments