Skip to content

Commit a2aa879

Browse files
author
Phil Varner
authored
Merge pull request #103 from stac-utils/pv/improve-queryables
improve queryables, add documentation for copying indicies
2 parents 9aabbe0 + c3669c1 commit a2aa879

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,105 @@ make ingest
7272
## Elasticsearch Mappings
7373

7474
Mappings apply to search index, not source.
75+
76+
## Managing Elasticsearch Indices
77+
78+
This section covers how to create a snapshot repository and then create and restore snapshots with this.
79+
80+
Create a snapshot repository. This puts the files in the `elasticsearch/snapshots` in this git repo clone, as
81+
the elasticsearch.yml and docker-compose files create a mapping from that directory to
82+
`/usr/share/elasticsearch/snapshots` within the Elasticsearch container and grant permissions on using it.
83+
84+
```
85+
curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup" \
86+
-H 'Content-Type: application/json; charset=utf-8' \
87+
-d $'{
88+
"type": "fs",
89+
"settings": {
90+
"location": "/usr/share/elasticsearch/snapshots/my_fs_backup"
91+
}
92+
}'
93+
```
94+
95+
The next step is to create a snapshot of one or more indices into this snapshot repository. This command creates
96+
a snapshot named `my_snapshot_2` and waits for the action to be completed before returning. This can also be done
97+
asynchronously, and queried for status. The `indices` parameter determines which indices are snapshotted, and
98+
can include wildcards.
99+
100+
```
101+
curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2?wait_for_completion=true" \
102+
-H 'Content-Type: application/json; charset=utf-8' \
103+
-d $'{
104+
"metadata": {
105+
"taken_because": "dump of all items",
106+
"taken_by": "pvarner"
107+
},
108+
"include_global_state": false,
109+
"ignore_unavailable": false,
110+
"indices": "items_my-collection"
111+
}'
112+
```
113+
114+
To see the status of this snapshot:
115+
116+
```
117+
curl http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2
118+
```
119+
120+
To see all the snapshots:
121+
122+
```
123+
curl http://localhost:9200/_snapshot/my_fs_backup/_all
124+
```
125+
126+
To restore a snapshot, run something similar to the following. This specific command will restore any indices that
127+
match `items_*` and rename them so that the new index name will be suffixed with `-copy`.
128+
129+
```
130+
curl -X "POST" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2/_restore?wait_for_completion=true" \
131+
-H 'Content-Type: application/json; charset=utf-8' \
132+
-d $'{
133+
"include_aliases": false,
134+
"include_global_state": false,
135+
"ignore_unavailable": true,
136+
"rename_replacement": "items_$1-copy",
137+
"indices": "items_*",
138+
"rename_pattern": "items_(.+)"
139+
}'
140+
141+
```
142+
143+
Now the item documents have been restored in to the new index (e.g., `my-collection-copy`), but the value of the
144+
`collection` field in those documents is still the original value of `my-collection`. To update these to match the
145+
new collection name, run the following Elasticsearch Update By Query command, substituting the old collection name
146+
into the term filter and the new collection name into the script parameter:
147+
148+
```
149+
curl -X "POST" "http://localhost:9200/items_my-collection-copy/_update_by_query" \
150+
-H 'Content-Type: application/json; charset=utf-8' \
151+
-d $'{
152+
"query": {
153+
"match_all": {}
154+
},
155+
"script": {
156+
"lang": "painless",
157+
"params": {
158+
"collection": "my-collection-copy"
159+
},
160+
"source": "ctx._source.collection = params.collection"
161+
}
162+
}'
163+
```
164+
165+
Then, create a new collection through the api with the new name for each of the restored indices:
166+
167+
```
168+
curl -X "POST" "http://localhost:8080/collections" \
169+
-H 'Content-Type: application/json' \
170+
-d $'{
171+
"id": "my-collection-copy"
172+
}'
173+
```
174+
175+
Voila! You have a copy of the collection now that has a resource URI (`/collections/my-collection-copy`) and can be
176+
correctly queried by collection name.

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,15 @@ async def get_queryables(
509509
"properties": {
510510
"id": {
511511
"description": "ID",
512-
"$ref": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json#/id",
512+
"$ref": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json#/definitions/core/allOf/2/properties/id",
513513
},
514514
"collection": {
515515
"description": "Collection",
516-
"$ref": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json#/collection",
516+
"$ref": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json#/definitions/core/allOf/2/then/properties/collection",
517517
},
518518
"geometry": {
519519
"description": "Geometry",
520-
"$ref": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json#/geometry",
520+
"$ref": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json#/definitions/core/allOf/1/oneOf/0/properties/geometry",
521521
},
522522
"datetime": {
523523
"description": "Acquisition Timestamp",
@@ -542,6 +542,13 @@ async def get_queryables(
542542
"minimum": 0,
543543
"maximum": 100,
544544
},
545+
"nodata_pixel_percentage": {
546+
"description": "No Data Pixel Percentage",
547+
"title": "No Data Pixel Percentage",
548+
"type": "number",
549+
"minimum": 0,
550+
"maximum": 100,
551+
},
545552
},
546553
"additionalProperties": True,
547554
}

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/extensions/filter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"updated": "properties.updated",
3434
"cloud_cover": "properties.eo:cloud_cover",
3535
"cloud_shadow_percentage": "properties.s2:cloud_shadow_percentage",
36+
"nodata_pixel_percentage": "properties.s2:nodata_pixel_percentage",
3637
}
3738

3839

0 commit comments

Comments
 (0)