User Tools

Site Tools


wiki:elasticsearch_commands

Elasticsearch commands

Get elastic search indexes

curl -XGET 'localhost:9200/_cat/indices?v&pretty'

Delete index

curl -XDELETE 'localhost:9200/twitter?pretty'

Replace “twitter” with your index name.

Delete all indices

curl -X DELETE 'http://localhost:9200/_all'

Create snapshot

Register repo first:

curl -X PUT -u undefined:$ESPASS "localhost:9200/_snapshot/es_backup?pretty" -H 'Content-Type: application/json' -d'
{
  "type": "fs",
  "settings": {
    "location": "es_backup"
  }
}
'

Instead of creating new repo, you can use the default_backup repo if you want.

Create first backup

curl -X PUT "localhost:9200/_snapshot/es_backup/ztest?wait_for_completion=true&pretty"

To create single index snapshot use

curl -X PUT "localhost:9200/_snapshot/default_backup/myindex_backup?wait_for_completion=true&pretty" -H 'Content-Type: application/json' -d'
{
  "indices": "coolindex"
}'

The backup folder is created in /opt/backup/elasticsearch/.

You can now zip this and transfer to another server.

List snapshots

curl -s -X GET "localhost:9200/_snapshot"
curl -s -X GET "localhost:9200/_snapshot/es_backup/*?pretty=true"

Restore snapshot

If you have an archive, unarchive it to /opt/backup/elasticsearch/, e.g.

tar xvf /tmp/es_backup.tar.gz -C /opt/backup/elasticsearch/es_backup

When you transfer it to another server unzip it, make sure that the owner is elasticsearch on the folder and then create the snapshot repository with command above, otherwise you won't see it when trying to list the snaphots.

List the snapshots with above command.

After this do the restore with snapshot name you want:

curl -s -X POST "localhost:9200/_snapshot/es_backup/snapshot-12/_restore" 

To restore single index use

curl -s -X POST "localhost:9200/_snapshot/myes_bak/snapshot-2023-01-11/_restore" -H 'Content-Type: application/json' -d'
{
  "indices": "niceindex"
}'

If you get an error that an index exist, like with the system index .geoip_databases, you can restore the system indices from the snapshot as well with

curl -s -X POST "localhost:9200/_snapshot/es_backup/snapshot-12/_restore" -H 'Content-Type: application/json' -d \
'{
"include_global_state": true
}'

Tested on

  • ES 7.17.5

See also

References

wiki/elasticsearch_commands.txt · Last modified: 2023/01/11 17:03 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki