File tree Expand file tree Collapse file tree 4 files changed +52
-52
lines changed
elasticsearch/stac_fastapi/elasticsearch
opensearch/stac_fastapi/opensearch
sfeos_helpers/stac_fastapi/sfeos_helpers Expand file tree Collapse file tree 4 files changed +52
-52
lines changed Original file line number Diff line number Diff line change 2121 ElasticsearchSettings as SyncElasticsearchSettings ,
2222)
2323from stac_fastapi .sfeos_helpers import filter
24+ from stac_fastapi .sfeos_helpers .database_logic_helpers import (
25+ create_index_templates_shared ,
26+ )
2427from stac_fastapi .sfeos_helpers .mappings import (
2528 COLLECTIONS_INDEX ,
2629 DEFAULT_SORT ,
27- ES_COLLECTIONS_MAPPINGS ,
28- ES_ITEMS_MAPPINGS ,
29- ES_ITEMS_SETTINGS ,
3030 ITEM_INDICES ,
3131 ITEMS_INDEX_PREFIX ,
3232 Geometry ,
@@ -51,22 +51,7 @@ async def create_index_templates() -> None:
5151 None
5252
5353 """
54- client = AsyncElasticsearchSettings ().create_client
55- await client .indices .put_index_template (
56- name = f"template_{ COLLECTIONS_INDEX } " ,
57- body = {
58- "index_patterns" : [f"{ COLLECTIONS_INDEX } *" ],
59- "template" : {"mappings" : ES_COLLECTIONS_MAPPINGS },
60- },
61- )
62- await client .indices .put_index_template (
63- name = f"template_{ ITEMS_INDEX_PREFIX } " ,
64- body = {
65- "index_patterns" : [f"{ ITEMS_INDEX_PREFIX } *" ],
66- "template" : {"settings" : ES_ITEMS_SETTINGS , "mappings" : ES_ITEMS_MAPPINGS },
67- },
68- )
69- await client .close ()
54+ await create_index_templates_shared (settings = AsyncElasticsearchSettings ())
7055
7156
7257async def create_collection_index () -> None :
Original file line number Diff line number Diff line change 2121)
2222from stac_fastapi .opensearch .config import OpensearchSettings as SyncSearchSettings
2323from stac_fastapi .sfeos_helpers import filter
24+ from stac_fastapi .sfeos_helpers .database_logic_helpers import (
25+ create_index_templates_shared ,
26+ )
2427from stac_fastapi .sfeos_helpers .mappings import (
2528 COLLECTIONS_INDEX ,
2629 DEFAULT_SORT ,
@@ -51,23 +54,7 @@ async def create_index_templates() -> None:
5154 None
5255
5356 """
54- client = AsyncSearchSettings ().create_client
55- await client .indices .put_template (
56- name = f"template_{ COLLECTIONS_INDEX } " ,
57- body = {
58- "index_patterns" : [f"{ COLLECTIONS_INDEX } *" ],
59- "mappings" : ES_COLLECTIONS_MAPPINGS ,
60- },
61- )
62- await client .indices .put_template (
63- name = f"template_{ ITEMS_INDEX_PREFIX } " ,
64- body = {
65- "index_patterns" : [f"{ ITEMS_INDEX_PREFIX } *" ],
66- "settings" : ES_ITEMS_SETTINGS ,
67- "mappings" : ES_ITEMS_MAPPINGS ,
68- },
69- )
70- await client .close ()
57+ await create_index_templates_shared (settings = AsyncSearchSettings ())
7158
7259
7360async def create_collection_index () -> None :
Original file line number Diff line number Diff line change 1+ """Shared code for elasticsearch/ opensearch database logic."""
2+
3+ from typing import Any
4+
5+ from stac_fastapi .sfeos_helpers .mappings import (
6+ COLLECTIONS_INDEX ,
7+ ES_COLLECTIONS_MAPPINGS ,
8+ ES_ITEMS_MAPPINGS ,
9+ ES_ITEMS_SETTINGS ,
10+ ITEMS_INDEX_PREFIX ,
11+ )
12+
13+
14+ async def create_index_templates_shared (settings : Any ) -> None :
15+ """
16+ Create index templates for the Collection and Item indices.
17+
18+ Returns:
19+ None
20+
21+ """
22+ client = settings .create_client
23+ await client .indices .put_index_template (
24+ name = f"template_{ COLLECTIONS_INDEX } " ,
25+ body = {
26+ "index_patterns" : [f"{ COLLECTIONS_INDEX } *" ],
27+ "template" : {"mappings" : ES_COLLECTIONS_MAPPINGS },
28+ },
29+ )
30+ await client .indices .put_index_template (
31+ name = f"template_{ ITEMS_INDEX_PREFIX } " ,
32+ body = {
33+ "index_patterns" : [f"{ ITEMS_INDEX_PREFIX } *" ],
34+ "template" : {"settings" : ES_ITEMS_SETTINGS , "mappings" : ES_ITEMS_MAPPINGS },
35+ },
36+ )
37+ await client .close ()
Original file line number Diff line number Diff line change 1- import os
21import uuid
32
43import pytest
54from stac_pydantic import api
65
7- from ..conftest import MockRequest , database
6+ from stac_fastapi .sfeos_helpers .mappings import (
7+ COLLECTIONS_INDEX ,
8+ ES_COLLECTIONS_MAPPINGS ,
9+ ES_ITEMS_MAPPINGS ,
10+ index_alias_by_collection_id ,
11+ )
812
9- if os .getenv ("BACKEND" , "elasticsearch" ).lower () == "opensearch" :
10- from stac_fastapi .opensearch .database_logic import (
11- COLLECTIONS_INDEX ,
12- ES_COLLECTIONS_MAPPINGS ,
13- ES_ITEMS_MAPPINGS ,
14- index_alias_by_collection_id ,
15- )
16- else :
17- from stac_fastapi .elasticsearch .database_logic import (
18- COLLECTIONS_INDEX ,
19- ES_COLLECTIONS_MAPPINGS ,
20- ES_ITEMS_MAPPINGS ,
21- index_alias_by_collection_id ,
22- )
13+ from ..conftest import MockRequest , database
2314
2415
2516@pytest .mark .asyncio
You can’t perform that action at this time.
0 commit comments