Elasticsearch schemas for Woeplanet indices to stop Elasticsearch being clever with data mappings.
$ curl -s http://localhost:9200/_aliases | python -mjson.tool
{
"placetypes_20200621": {
"aliases": {
"placetypes": {}
}
},
"woeplanet_20200619": {
"aliases": {
"woeplanet": {}
}
}
}
Each index is date-stamped in YYYYMMDD format with a date-less alias pointing to it.
$ cat ./schema/7.x/mappings.woeplanet.json | curl -s -XPUT http://localhost:9200/woeplanet_20200601 -H "Content-Type: application/json" -d @- | python -mjson.tool
{
"acknowledged": true,
"index": "woeplanet_20200601",
"shards_acknowledged": true
}
$ curl -s -XPOST http://localhost:9200/_aliases -H "Content-Type: application/json" -d '{"actions":[{"add":{"alias": "woeplanet", "index": "woeplanet_20200601"}}]}' | python -mjson.tool
{
"acknowledged": true
}
The ./bin/reload-schema.sh
script will do the following:
- Delete a current index and automagically delete its aliases
- Re-create the index from its schema mapping file with the current date-stamp
- Create a new alias to point to the just created index
The script takes two optional arguments; the index name without date-stamp and the old date-stamp for the previous index version.
$ ./bin/reload-schema.sh placetypes 20200621
Deleting index 'placetypes_20200621'
{
"acknowledged": true
}
Creating index 'placetypes_20200621'
{
"acknowledged": true,
"index": "placetypes_20200621",
"shards_acknowledged": true
}
Aliasing 'placetypes_20200621' as 'placetypes'
{
"acknowledged": true
}
$ cat schema/7.x/mappings.woeplanet.json | curl -X PUT http://localhost:9200/woeplanet_20200619 -H 'Content-Type: application/json' -d @-
$ curl -X POST http://localhost:9200/_aliases -H 'Content-Type: application/json' -d '{"actions":[{"add":{"alias": "woeplanet", "index": "woeplanet_20200619"}}]}'