Skip to content

Commit 053f130

Browse files
author
Phil Varner
authored
Pv/update es mappings (#47)
* Add better elasticsearch mappings
1 parent e385f14 commit 053f130

File tree

4 files changed

+92
-8
lines changed

4 files changed

+92
-8
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
- [ ] Code is formatted and linted (run `pre-commit run --all-files`)
1111
- [ ] Tests pass (run `make test`)
1212
- [ ] Documentation has been updated to reflect changes, if applicable, and docs build successfully (run `make docs`)
13-
- [ ] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac/blob/master/CHANGES.md), if applicable
13+
- [ ] Changes are added to the changelog

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Deprecated
11+
12+
### Added
13+
14+
### Fixed
15+
16+
### Changed
17+
18+
- Elasticsearch index mappings updated to be more thorough.
19+
20+
### Removed
21+
22+
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/main>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Elasticsearch backend for stac-fastapi.
44

55
**WIP** This backend is not yet stable (notice no releases yet), so use the pgstac backend instead.
66

7+
For changes, see the [Changelog](CHANGELOG.md).
8+
79
## Development Environment Setup
810

911
Install [pre-commit](https://pre-commit.com/#install).

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,82 @@ class TransactionsClient(BaseTransactionsClient):
3232
settings = ElasticsearchSettings()
3333
client = settings.create_client
3434

35-
mappings = {
35+
ES_MAPPINGS_DYNAMIC_TEMPLATES = [
36+
# Common https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
37+
{
38+
"descriptions": {
39+
"match_mapping_type": "string",
40+
"match": "description",
41+
"mapping": {"type": "text"},
42+
}
43+
},
44+
{
45+
"titles": {
46+
"match_mapping_type": "string",
47+
"match": "title",
48+
"mapping": {"type": "text"},
49+
}
50+
},
51+
# Projection Extension https://github.com/stac-extensions/projection
52+
{"proj_epsg": {"match": "proj:epsg", "mapping": {"type": "integer"}}},
53+
{
54+
"proj_projjson": {
55+
"match": "proj:projjson",
56+
"mapping": {"type": "object", "enabled": False},
57+
}
58+
},
59+
{
60+
"proj_centroid": {
61+
"match": "proj:centroid",
62+
"mapping": {"type": "geo_point"},
63+
}
64+
},
65+
{
66+
"proj_geometry": {
67+
"match": "proj:geometry",
68+
"mapping": {"type": "geo_shape"},
69+
}
70+
},
71+
{
72+
"no_index_href": {
73+
"match": "href",
74+
"mapping": {"type": "text", "index": False},
75+
}
76+
},
77+
# Default all other strings not otherwise specified to keyword
78+
{"strings": {"match_mapping_type": "string", "mapping": {"type": "keyword"}}},
79+
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "float"}}},
80+
]
81+
82+
ES_MAPPINGS = {
83+
"numeric_detection": False,
84+
"dynamic_templates": ES_MAPPINGS_DYNAMIC_TEMPLATES,
3685
"properties": {
3786
"geometry": {"type": "geo_shape"},
38-
"id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
39-
"properties__datetime": {
40-
"type": "text",
41-
"fields": {"keyword": {"type": "keyword"}},
87+
"assets": {"type": "object", "enabled": False},
88+
"links": {"type": "object", "enabled": False},
89+
"properties": {
90+
"type": "object",
91+
"properties": {
92+
# Common https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
93+
"datetime": {"type": "date"},
94+
"start_datetime": {"type": "date"},
95+
"end_datetime": {"type": "date"},
96+
"created": {"type": "date"},
97+
"updated": {"type": "date"},
98+
# Satellite Extension https://github.com/stac-extensions/sat
99+
"sat:absolute_orbit": {"type": "integer"},
100+
"sat:relative_orbit": {"type": "integer"},
101+
},
42102
},
43-
}
103+
},
44104
}
45105

46106
def create_item_index(self):
47107
"""Create the index for Items."""
48108
self.client.indices.create(
49109
index="stac_items",
50-
body={"mappings": self.mappings},
110+
body={"mappings": self.ES_MAPPINGS},
51111
ignore=400, # ignore 400 already exists code
52112
)
53113

0 commit comments

Comments
 (0)