Skip to content

Pv/update es mappings #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- [ ] Code is formatted and linted (run `pre-commit run --all-files`)
- [ ] Tests pass (run `make test`)
- [ ] Documentation has been updated to reflect changes, if applicable, and docs build successfully (run `make docs`)
- [ ] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac/blob/master/CHANGES.md), if applicable
- [ ] Changes are added to the changelog
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Deprecated

### Added

### Fixed

### Changed

- Elasticsearch index mappings updated to be more thorough.

### Removed

[Unreleased]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/main>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Elasticsearch backend for stac-fastapi.

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

For changes, see the [Changelog](CHANGELOG.md).

## Development Environment Setup

Install [pre-commit](https://pre-commit.com/#install).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,82 @@ class TransactionsClient(BaseTransactionsClient):
settings = ElasticsearchSettings()
client = settings.create_client

mappings = {
ES_MAPPINGS_DYNAMIC_TEMPLATES = [
# Common https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
{
"descriptions": {
"match_mapping_type": "string",
"match": "description",
"mapping": {"type": "text"},
}
},
{
"titles": {
"match_mapping_type": "string",
"match": "title",
"mapping": {"type": "text"},
}
},
# Projection Extension https://github.com/stac-extensions/projection
{"proj_epsg": {"match": "proj:epsg", "mapping": {"type": "integer"}}},
{
"proj_projjson": {
"match": "proj:projjson",
"mapping": {"type": "object", "enabled": False},
}
},
{
"proj_centroid": {
"match": "proj:centroid",
"mapping": {"type": "geo_point"},
}
},
{
"proj_geometry": {
"match": "proj:geometry",
"mapping": {"type": "geo_shape"},
}
},
{
"no_index_href": {
"match": "href",
"mapping": {"type": "text", "index": False},
}
},
# Default all other strings not otherwise specified to keyword
{"strings": {"match_mapping_type": "string", "mapping": {"type": "keyword"}}},
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "float"}}},
]

ES_MAPPINGS = {
"numeric_detection": False,
"dynamic_templates": ES_MAPPINGS_DYNAMIC_TEMPLATES,
"properties": {
"geometry": {"type": "geo_shape"},
"id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
"properties__datetime": {
"type": "text",
"fields": {"keyword": {"type": "keyword"}},
"assets": {"type": "object", "enabled": False},
"links": {"type": "object", "enabled": False},
"properties": {
"type": "object",
"properties": {
# Common https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
"datetime": {"type": "date"},
"start_datetime": {"type": "date"},
"end_datetime": {"type": "date"},
"created": {"type": "date"},
"updated": {"type": "date"},
# Satellite Extension https://github.com/stac-extensions/sat
"sat:absolute_orbit": {"type": "integer"},
"sat:relative_orbit": {"type": "integer"},
},
},
}
},
}

def create_item_index(self):
"""Create the index for Items."""
self.client.indices.create(
index="stac_items",
body={"mappings": self.mappings},
body={"mappings": self.ES_MAPPINGS},
ignore=400, # ignore 400 already exists code
)

Expand Down