6
6
import attr
7
7
import elasticsearch
8
8
from elasticsearch import helpers
9
+ from overrides import overrides
9
10
10
11
from stac_fastapi .elasticsearch .config import ElasticsearchSettings
11
12
from stac_fastapi .elasticsearch .serializers import CollectionSerializer , ItemSerializer
@@ -30,26 +31,87 @@ class TransactionsClient(BaseTransactionsClient):
30
31
settings = ElasticsearchSettings ()
31
32
client = settings .create_client
32
33
33
- def _create_item_index (self ):
34
- mapping = {
35
- "mappings" : {
36
- "properties" : {
37
- "geometry" : {"type" : "geo_shape" },
38
- "id" : {"type" : "text" , "fields" : {"keyword" : {"type" : "keyword" }}},
39
- "properties__datetime" : {
40
- "type" : "text" ,
41
- "fields" : {"keyword" : {"type" : "keyword" }},
42
- },
43
- }
34
+ dynamicTemplates = [
35
+ # Common https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
36
+ {
37
+ "descriptions" : {
38
+ "match_mapping_type" : "string" ,
39
+ "match" : "description" ,
40
+ "mapping" : {"type" : "text" },
41
+ }
42
+ },
43
+ {
44
+ "titles" : {
45
+ "match_mapping_type" : "string" ,
46
+ "match" : "title" ,
47
+ "mapping" : {"type" : "text" },
48
+ }
49
+ },
50
+ # Projection Extension https://github.com/stac-extensions/projection
51
+ {"proj_epsg" : {"match" : "proj:epsg" , "mapping" : {"type" : "integer" }}},
52
+ {
53
+ "proj_projjson" : {
54
+ "match" : "proj:projjson" ,
55
+ "mapping" : {"type" : "object" , "enabled" : False },
56
+ }
57
+ },
58
+ {
59
+ "proj_centroid" : {
60
+ "match_mapping_type" : "string" ,
61
+ "match" : "proj:centroid" ,
62
+ "mapping" : {"type" : "geo_point" },
44
63
}
45
- }
64
+ },
65
+ {
66
+ "proj_geometry" : {
67
+ "match_mapping_type" : "string" ,
68
+ "match" : "proj:geometry" ,
69
+ "mapping" : {"type" : "geo_shape" },
70
+ }
71
+ },
72
+ {
73
+ "no_index_href" : {
74
+ "match" : "href" ,
75
+ "mapping" : {"type" : "text" , "index" : False },
76
+ }
77
+ },
78
+ # Default all other strings not otherwise specified to keyword
79
+ {"strings" : {"match_mapping_type" : "string" , "mapping" : {"type" : "keyword" }}},
80
+ {"numerics" : {"match_mapping_type" : "long" , "mapping" : {"type" : "float" }}},
81
+ ]
82
+
83
+ mappings = {
84
+ "numeric_detection" : False ,
85
+ "dynamic_templates" : dynamicTemplates ,
86
+ "properties" : {
87
+ "geometry" : {"type" : "geo_shape" },
88
+ "assets" : {"type" : "object" , "enabled" : False },
89
+ "links" : {"type" : "object" , "enabled" : False },
90
+ "properties" : {
91
+ "type" : "object" ,
92
+ "properties" : {
93
+ # Common https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
94
+ "datetime" : {"type" : "date" },
95
+ "start_datetime" : {"type" : "date" },
96
+ "end_datetime" : {"type" : "date" },
97
+ "created" : {"type" : "date" },
98
+ "updated" : {"type" : "date" },
99
+ # Satellite Extension https://github.com/stac-extensions/sat
100
+ "sat:absolute_orbit" : {"type" : "integer" },
101
+ "sat:relative_orbit" : {"type" : "integer" },
102
+ },
103
+ },
104
+ },
105
+ }
46
106
47
- _ = self .client .indices .create (
107
+ def _create_item_index (self ):
108
+ self .client .indices .create (
48
109
index = "stac_items" ,
49
- body = mapping ,
110
+ body = self . mappings ,
50
111
ignore = 400 , # ignore 400 already exists code
51
112
)
52
113
114
+ @overrides
53
115
def create_item (self , model : stac_types .Item , ** kwargs ):
54
116
"""Create item."""
55
117
base_url = str (kwargs ["request" ].base_url )
@@ -83,6 +145,7 @@ def create_item(self, model: stac_types.Item, **kwargs):
83
145
)
84
146
return ItemSerializer .db_to_stac (model , base_url )
85
147
148
+ @overrides
86
149
def create_collection (self , model : stac_types .Collection , ** kwargs ):
87
150
"""Create collection."""
88
151
base_url = str (kwargs ["request" ].base_url )
@@ -100,6 +163,7 @@ def create_collection(self, model: stac_types.Collection, **kwargs):
100
163
)
101
164
return CollectionSerializer .db_to_stac (model , base_url )
102
165
166
+ @overrides
103
167
def update_item (self , model : stac_types .Item , ** kwargs ):
104
168
"""Update item."""
105
169
base_url = str (kwargs ["request" ].base_url )
@@ -118,6 +182,7 @@ def update_item(self, model: stac_types.Item, **kwargs):
118
182
# body=model)
119
183
return ItemSerializer .db_to_stac (model , base_url )
120
184
185
+ @overrides
121
186
def update_collection (self , model : stac_types .Collection , ** kwargs ):
122
187
"""Update collection."""
123
188
base_url = str (kwargs ["request" ].base_url )
@@ -130,6 +195,7 @@ def update_collection(self, model: stac_types.Collection, **kwargs):
130
195
131
196
return CollectionSerializer .db_to_stac (model , base_url )
132
197
198
+ @overrides
133
199
def delete_item (self , item_id : str , collection_id : str , ** kwargs ):
134
200
"""Delete item."""
135
201
try :
@@ -138,6 +204,7 @@ def delete_item(self, item_id: str, collection_id: str, **kwargs):
138
204
raise NotFoundError (f"Item { item_id } not found" )
139
205
self .client .delete (index = "stac_items" , doc_type = "_doc" , id = item_id )
140
206
207
+ @overrides
141
208
def delete_collection (self , collection_id : str , ** kwargs ):
142
209
"""Delete collection."""
143
210
try :
@@ -178,6 +245,7 @@ def bulk_sync(self, processed_items):
178
245
]
179
246
helpers .bulk (self .client , actions )
180
247
248
+ @overrides
181
249
def bulk_item_insert (self , items : Items , ** kwargs ) -> str :
182
250
"""Bulk item insertion using es."""
183
251
transactions_client = TransactionsClient ()
0 commit comments