@@ -54,18 +54,8 @@ def _create_item_index(self):
54
54
def create_item (self , model : stac_types .Item , ** kwargs ):
55
55
"""Create item."""
56
56
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
61
57
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 ()
69
59
70
60
if not self .client .exists (index = "stac_collections" , id = model ["collection" ]):
71
61
raise ForeignKeyError (f"Collection { model ['collection' ]} does not exist" )
@@ -75,13 +65,7 @@ def create_item(self, model: stac_types.Item, **kwargs):
75
65
f"Item { model ['id' ]} in collection { model ['collection' ]} already exists"
76
66
)
77
67
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 )
85
69
86
70
self .client .index (
87
71
index = "stac_items" , doc_type = "_doc" , id = model ["id" ], document = data
@@ -162,25 +146,25 @@ def __attrs_post_init__(self):
162
146
settings = ElasticsearchSettings ()
163
147
self .client = settings .create_client
164
148
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
+ # )
184
168
185
169
def _preprocess_item (self , model : stac_types .Item , base_url ) -> stac_types .Item :
186
170
"""Preprocess items to match data model."""
@@ -212,7 +196,8 @@ def _preprocess_item(self, model: stac_types.Item, base_url) -> stac_types.Item:
212
196
213
197
def bulk_item_insert (self , items : Items , ** kwargs ) -> str :
214
198
"""Bulk item insertion using es."""
215
- self ._create_item_index ()
199
+ transactions_client = TransactionsClient ()
200
+ transactions_client ._create_item_index ()
216
201
try :
217
202
base_url = str (kwargs ["request" ].base_url )
218
203
except Exception :
0 commit comments