Skip to content

Commit 0fa2aad

Browse files
committed
clean up transactions
1 parent c0e3361 commit 0fa2aad

File tree

1 file changed

+23
-38
lines changed

1 file changed

+23
-38
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,8 @@ def _create_item_index(self):
5454
def create_item(self, model: stac_types.Item, **kwargs):
5555
"""Create item."""
5656
base_url = str(kwargs["request"].base_url)
57-
item_links = ItemLinks(
58-
collection_id=model["collection"], item_id=model["id"], base_url=base_url
59-
).create_links()
60-
model["links"] = item_links
6157

62-
# elasticsearch doesn't like the fact that some values are float and some were int
63-
if "eo:bands" in model["properties"]:
64-
for wave in model["properties"]["eo:bands"]:
65-
for k, v in wave.items():
66-
if type(v) != str:
67-
v = float(v)
68-
wave.update({k: v})
58+
self._create_item_index()
6959

7060
if not self.client.exists(index="stac_collections", id=model["collection"]):
7161
raise ForeignKeyError(f"Collection {model['collection']} does not exist")
@@ -75,13 +65,7 @@ def create_item(self, model: stac_types.Item, **kwargs):
7565
f"Item {model['id']} in collection {model['collection']} already exists"
7666
)
7767

78-
now = datetime.utcnow().strftime(DATETIME_RFC339)
79-
if "created" not in model["properties"]:
80-
model["properties"]["created"] = str(now)
81-
82-
self._create_item_index()
83-
84-
data = ItemSerializer.stac_to_db(model)
68+
data = ItemSerializer.stac_to_db(model, base_url)
8569

8670
self.client.index(
8771
index="stac_items", doc_type="_doc", id=model["id"], document=data
@@ -162,25 +146,25 @@ def __attrs_post_init__(self):
162146
settings = ElasticsearchSettings()
163147
self.client = settings.create_client
164148

165-
def _create_item_index(self):
166-
mapping = {
167-
"mappings": {
168-
"properties": {
169-
"geometry": {"type": "geo_shape"},
170-
"id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
171-
"properties__datetime": {
172-
"type": "text",
173-
"fields": {"keyword": {"type": "keyword"}},
174-
},
175-
}
176-
}
177-
}
178-
179-
_ = self.client.indices.create(
180-
index="stac_items",
181-
body=mapping,
182-
ignore=400, # ignore 400 already exists code
183-
)
149+
# def _create_item_index(self):
150+
# mapping = {
151+
# "mappings": {
152+
# "properties": {
153+
# "geometry": {"type": "geo_shape"},
154+
# "id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
155+
# "properties__datetime": {
156+
# "type": "text",
157+
# "fields": {"keyword": {"type": "keyword"}},
158+
# },
159+
# }
160+
# }
161+
# }
162+
163+
# _ = self.client.indices.create(
164+
# index="stac_items",
165+
# body=mapping,
166+
# ignore=400, # ignore 400 already exists code
167+
# )
184168

185169
def _preprocess_item(self, model: stac_types.Item, base_url) -> stac_types.Item:
186170
"""Preprocess items to match data model."""
@@ -212,7 +196,8 @@ def _preprocess_item(self, model: stac_types.Item, base_url) -> stac_types.Item:
212196

213197
def bulk_item_insert(self, items: Items, **kwargs) -> str:
214198
"""Bulk item insertion using es."""
215-
self._create_item_index()
199+
transactions_client = TransactionsClient()
200+
transactions_client._create_item_index()
216201
try:
217202
base_url = str(kwargs["request"].base_url)
218203
except Exception:

0 commit comments

Comments
 (0)