@@ -54,6 +54,21 @@ 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
+ self ._create_item_index ()
58
+
59
+ # If a feature collection is posted
60
+ if model ["type" ] == "FeatureCollection" :
61
+ bulk_client = BulkTransactionsClient ()
62
+ processed_items = [
63
+ bulk_client ._preprocess_item (item , base_url )
64
+ for item in model ["features" ]
65
+ ]
66
+ return_msg = f"Successfully added { len (processed_items )} items."
67
+ bulk_client .bulk_sync (processed_items )
68
+
69
+ return return_msg
70
+
71
+ # If a single item is posted
57
72
item_links = ItemLinks (
58
73
collection_id = model ["collection" ], item_id = model ["id" ], base_url = base_url
59
74
).create_links ()
@@ -79,8 +94,6 @@ def create_item(self, model: stac_types.Item, **kwargs):
79
94
if "created" not in model ["properties" ]:
80
95
model ["properties" ]["created" ] = str (now )
81
96
82
- self ._create_item_index ()
83
-
84
97
self .client .index (
85
98
index = "stac_items" , doc_type = "_doc" , id = model ["id" ], document = model
86
99
)
@@ -101,6 +114,7 @@ def create_collection(self, model: stac_types.Collection, **kwargs):
101
114
self .client .index (
102
115
index = "stac_collections" , doc_type = "_doc" , id = model ["id" ], document = model
103
116
)
117
+ return CollectionSerializer .db_to_stac (model , base_url )
104
118
105
119
def update_item (self , model : stac_types .Item , ** kwargs ):
106
120
"""Update item."""
@@ -208,6 +222,13 @@ def _preprocess_item(self, model: stac_types.Item, base_url) -> stac_types.Item:
208
222
wave .update ({k : v })
209
223
return model
210
224
225
+ def bulk_sync (self , processed_items ):
226
+ """Elasticsearch bulk insertion."""
227
+ actions = [
228
+ {"_index" : "stac_items" , "_source" : item } for item in processed_items
229
+ ]
230
+ helpers .bulk (self .client , actions )
231
+
211
232
def bulk_item_insert (self , items : Items , ** kwargs ) -> str :
212
233
"""Bulk item insertion using es."""
213
234
self ._create_item_index ()
@@ -220,21 +241,6 @@ def bulk_item_insert(self, items: Items, **kwargs) -> str:
220
241
]
221
242
return_msg = f"Successfully added { len (processed_items )} items."
222
243
223
- # helpers.bulk(
224
- # self.client,
225
- # processed_items,
226
- # index="stac_items",
227
- # doc_type="_doc",
228
- # request_timeout=200,
229
- # )
230
-
231
- def bulk_sync (processed_items ):
232
- actions = [
233
- {"_index" : "stac_items" , "_source" : item } for item in processed_items
234
- ]
235
-
236
- helpers .bulk (self .client , actions )
237
-
238
- bulk_sync (processed_items )
244
+ self .bulk_sync (processed_items )
239
245
240
246
return return_msg
0 commit comments