Skip to content

Commit e674381

Browse files
committed
share aggregations mapping
1 parent 30ea1c7 commit e674381

File tree

3 files changed

+75
-140
lines changed

3 files changed

+75
-140
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
populate_sort_shared,
3030
)
3131
from stac_fastapi.sfeos_helpers.mappings import (
32+
AGGREGATION_MAPPING,
3233
COLLECTIONS_INDEX,
3334
DEFAULT_SORT,
3435
ITEM_INDICES,
@@ -135,76 +136,7 @@ def __attrs_post_init__(self):
135136

136137
extensions: List[str] = attr.ib(default=attr.Factory(list))
137138

138-
aggregation_mapping: Dict[str, Dict[str, Any]] = {
139-
"total_count": {"value_count": {"field": "id"}},
140-
"collection_frequency": {"terms": {"field": "collection", "size": 100}},
141-
"platform_frequency": {"terms": {"field": "properties.platform", "size": 100}},
142-
"cloud_cover_frequency": {
143-
"range": {
144-
"field": "properties.eo:cloud_cover",
145-
"ranges": [
146-
{"to": 5},
147-
{"from": 5, "to": 15},
148-
{"from": 15, "to": 40},
149-
{"from": 40},
150-
],
151-
}
152-
},
153-
"datetime_frequency": {
154-
"date_histogram": {
155-
"field": "properties.datetime",
156-
"calendar_interval": "month",
157-
}
158-
},
159-
"datetime_min": {"min": {"field": "properties.datetime"}},
160-
"datetime_max": {"max": {"field": "properties.datetime"}},
161-
"grid_code_frequency": {
162-
"terms": {
163-
"field": "properties.grid:code",
164-
"missing": "none",
165-
"size": 10000,
166-
}
167-
},
168-
"sun_elevation_frequency": {
169-
"histogram": {"field": "properties.view:sun_elevation", "interval": 5}
170-
},
171-
"sun_azimuth_frequency": {
172-
"histogram": {"field": "properties.view:sun_azimuth", "interval": 5}
173-
},
174-
"off_nadir_frequency": {
175-
"histogram": {"field": "properties.view:off_nadir", "interval": 5}
176-
},
177-
"centroid_geohash_grid_frequency": {
178-
"geohash_grid": {
179-
"field": "properties.proj:centroid",
180-
"precision": 1,
181-
}
182-
},
183-
"centroid_geohex_grid_frequency": {
184-
"geohex_grid": {
185-
"field": "properties.proj:centroid",
186-
"precision": 0,
187-
}
188-
},
189-
"centroid_geotile_grid_frequency": {
190-
"geotile_grid": {
191-
"field": "properties.proj:centroid",
192-
"precision": 0,
193-
}
194-
},
195-
"geometry_geohash_grid_frequency": {
196-
"geohash_grid": {
197-
"field": "geometry",
198-
"precision": 1,
199-
}
200-
},
201-
"geometry_geotile_grid_frequency": {
202-
"geotile_grid": {
203-
"field": "geometry",
204-
"precision": 0,
205-
}
206-
},
207-
}
139+
aggregation_mapping: Dict[str, Dict[str, Any]] = AGGREGATION_MAPPING
208140

209141
"""CORE LOGIC"""
210142

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
populate_sort_shared,
3030
)
3131
from stac_fastapi.sfeos_helpers.mappings import (
32+
AGGREGATION_MAPPING,
3233
COLLECTIONS_INDEX,
3334
DEFAULT_SORT,
3435
ES_COLLECTIONS_MAPPINGS,
@@ -148,76 +149,7 @@ def __attrs_post_init__(self):
148149

149150
extensions: List[str] = attr.ib(default=attr.Factory(list))
150151

151-
aggregation_mapping: Dict[str, Dict[str, Any]] = {
152-
"total_count": {"value_count": {"field": "id"}},
153-
"collection_frequency": {"terms": {"field": "collection", "size": 100}},
154-
"platform_frequency": {"terms": {"field": "properties.platform", "size": 100}},
155-
"cloud_cover_frequency": {
156-
"range": {
157-
"field": "properties.eo:cloud_cover",
158-
"ranges": [
159-
{"to": 5},
160-
{"from": 5, "to": 15},
161-
{"from": 15, "to": 40},
162-
{"from": 40},
163-
],
164-
}
165-
},
166-
"datetime_frequency": {
167-
"date_histogram": {
168-
"field": "properties.datetime",
169-
"calendar_interval": "month",
170-
}
171-
},
172-
"datetime_min": {"min": {"field": "properties.datetime"}},
173-
"datetime_max": {"max": {"field": "properties.datetime"}},
174-
"grid_code_frequency": {
175-
"terms": {
176-
"field": "properties.grid:code",
177-
"missing": "none",
178-
"size": 10000,
179-
}
180-
},
181-
"sun_elevation_frequency": {
182-
"histogram": {"field": "properties.view:sun_elevation", "interval": 5}
183-
},
184-
"sun_azimuth_frequency": {
185-
"histogram": {"field": "properties.view:sun_azimuth", "interval": 5}
186-
},
187-
"off_nadir_frequency": {
188-
"histogram": {"field": "properties.view:off_nadir", "interval": 5}
189-
},
190-
"centroid_geohash_grid_frequency": {
191-
"geohash_grid": {
192-
"field": "properties.proj:centroid",
193-
"precision": 1,
194-
}
195-
},
196-
"centroid_geohex_grid_frequency": {
197-
"geohex_grid": {
198-
"field": "properties.proj:centroid",
199-
"precision": 0,
200-
}
201-
},
202-
"centroid_geotile_grid_frequency": {
203-
"geotile_grid": {
204-
"field": "properties.proj:centroid",
205-
"precision": 0,
206-
}
207-
},
208-
"geometry_geohash_grid_frequency": {
209-
"geohash_grid": {
210-
"field": "geometry",
211-
"precision": 1,
212-
}
213-
},
214-
"geometry_geotile_grid_frequency": {
215-
"geotile_grid": {
216-
"field": "geometry",
217-
"precision": 0,
218-
}
219-
},
220-
}
152+
aggregation_mapping: Dict[str, Dict[str, Any]] = AGGREGATION_MAPPING
221153

222154
"""CORE LOGIC"""
223155

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/mappings.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,77 @@ class Geometry(Protocol): # noqa
144144
},
145145
}
146146

147+
# Shared aggregation mapping for both Elasticsearch and OpenSearch
148+
AGGREGATION_MAPPING: Dict[str, Dict[str, Any]] = {
149+
"total_count": {"value_count": {"field": "id"}},
150+
"collection_frequency": {"terms": {"field": "collection", "size": 100}},
151+
"platform_frequency": {"terms": {"field": "properties.platform", "size": 100}},
152+
"cloud_cover_frequency": {
153+
"range": {
154+
"field": "properties.eo:cloud_cover",
155+
"ranges": [
156+
{"to": 5},
157+
{"from": 5, "to": 15},
158+
{"from": 15, "to": 40},
159+
{"from": 40},
160+
],
161+
}
162+
},
163+
"datetime_frequency": {
164+
"date_histogram": {
165+
"field": "properties.datetime",
166+
"calendar_interval": "month",
167+
}
168+
},
169+
"datetime_min": {"min": {"field": "properties.datetime"}},
170+
"datetime_max": {"max": {"field": "properties.datetime"}},
171+
"grid_code_frequency": {
172+
"terms": {
173+
"field": "properties.grid:code",
174+
"missing": "none",
175+
"size": 10000,
176+
}
177+
},
178+
"sun_elevation_frequency": {
179+
"histogram": {"field": "properties.view:sun_elevation", "interval": 5}
180+
},
181+
"sun_azimuth_frequency": {
182+
"histogram": {"field": "properties.view:sun_azimuth", "interval": 5}
183+
},
184+
"off_nadir_frequency": {
185+
"histogram": {"field": "properties.view:off_nadir", "interval": 5}
186+
},
187+
"centroid_geohash_grid_frequency": {
188+
"geohash_grid": {
189+
"field": "properties.proj:centroid",
190+
"precision": 1,
191+
}
192+
},
193+
"centroid_geohex_grid_frequency": {
194+
"geohex_grid": {
195+
"field": "properties.proj:centroid",
196+
"precision": 0,
197+
}
198+
},
199+
"centroid_geotile_grid_frequency": {
200+
"geotile_grid": {
201+
"field": "properties.proj:centroid",
202+
"precision": 0,
203+
}
204+
},
205+
"geometry_geohash_grid_frequency": {
206+
"geohash_grid": {
207+
"field": "geometry",
208+
"precision": 1,
209+
}
210+
},
211+
"geometry_geotile_grid_frequency": {
212+
"geotile_grid": {
213+
"field": "geometry",
214+
"precision": 0,
215+
}
216+
},
217+
}
147218

148219
ES_MAPPING_TYPE_TO_JSON: Dict[
149220
str, Literal["string", "number", "boolean", "object", "array", "null"]

0 commit comments

Comments
 (0)