Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone give a snapshot example of elastic-search by using python?

I'm using python to access elasticsearch cluster. Now I want to backup my index by using snapshot. The most difficult thing is that: the python-elasticsearch's doc just give me a API description. there is no example to show me how to create snapshot. I tried some parameters, but failed. Can anyone give a snapshot example of elastic-search by using python? The following is my code:

from elasticsearch import Elasticsearch
es = Elasticsearch()
snapshot_body = {
"type": "url",
"settings": {
        "url":  "http://download.elasticsearch.org/definitiveguide/sigterms_demo/"
    }
}
body = {"snapshot": snapshot_body}
es.snapshot.create_repository(repository='test', body=body)
like image 874
Howardyan Avatar asked Dec 19 '16 03:12

Howardyan


1 Answers

Your repository creation is almost correct, you don't need the line body = {"snapshot": snapshot_body}, simply create your repository like this:

es.snapshot.create_repository(repository='test', body=snapshot_body)

Now in order to create a snapshot, all you have to do is this:

es.snapshot.create(repository='test', snapshot='my_snapshot')

If you want to store only a few indices and not all you can also provide a body like this:

index_body = {
  "indices": "index_1,index_2"
}
es.snapshot.create(repository='test', snapshot='my_snapshot', body=index_body)
like image 188
Val Avatar answered Oct 24 '22 07:10

Val