Created
August 11, 2017 12:39
-
-
Save jxerome/f8244f5eaa9725e0629f18b43ad5eaad to your computer and use it in GitHub Desktop.
Data resurrection when recreating formerly destroyed index (exemple)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -x | |
| docker_id=$(sudo docker run -d -P strapdata/elassandra) | |
| #host_ip=$(sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' "$docker_id") | |
| port=$(sudo docker inspect --format='{{(index (index .NetworkSettings.Ports "9200/tcp") 0).HostPort}}' "$docker_id") | |
| round=1 | |
| limit=5 | |
| while [[ $round -le $limit ]]; do | |
| echo "Wait elassandra initialization (round: $round/$limit)" | |
| (( round += 1 )) | |
| sleep 30 | |
| if curl -s -XGET localhost:${port}; then | |
| break | |
| fi | |
| done | |
| curl -s -XPUT localhost:${port}/data?pretty -d '{ | |
| "mapping": { | |
| "test": { | |
| "name": {"type": "text"} | |
| } | |
| } | |
| }' | |
| curl -s -XPUT localhost:${port}/data/type/1?pretty -d '{"name":"Lazarus of Bethany"}' | |
| curl -s -XGET localhost:${port}/data/type/_search?q=name:lazarus\&pretty | |
| curl -s -XDELETE localhost:${port}/data?pretty | |
| curl -s -XGET localhost:${port}/data/type/_search?q=name:lazarus\&pretty | |
| curl -s -XPUT localhost:${port}/data?pretty -d '{ | |
| "mapping": { | |
| "test": { | |
| "name": {"type": "text"} | |
| } | |
| } | |
| }' | |
| curl -s -XPUT localhost:${port}/data/type/2?pretty -d '{"name":"Phoenix Lazarus"}' | |
| curl -s -XPOST localhost:${port}/data/_refresh?pretty | |
| curl -s -XGET localhost:${port}/data/type/_search?q=name:lazarus\&pretty | |
| sudo docker rm -f $docker_id | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ++ sudo docker run -d -P strapdata/elassandra | |
| + docker_id=771ff200537ea54edf6c15c814439273c71a9a958f979472e4a167407542724f | |
| ++ sudo docker inspect '--format={{(index (index .NetworkSettings.Ports "9200/tcp") 0).HostPort}}' 771ff200537ea54edf6c15c814439273c71a9a958f979472e4a167407542724f | |
| + port=32930 | |
| + round=1 | |
| + limit=5 | |
| + [[ 1 -le 5 ]] | |
| + echo 'Wait elassandra initialization (round: 1/5)' | |
| Wait elassandra initialization (round: 1/5) | |
| + (( round += 1 )) | |
| + sleep 30 | |
| + curl -s -XGET localhost:32930 | |
| { | |
| "name" : "172.17.0.3", | |
| "cluster_name" : "Test Cluster", | |
| "cluster_uuid" : "c7845bad-74c8-4e4e-a5ab-fb8584250edf", | |
| "version" : { | |
| "number" : "2.4.2", | |
| "build_hash" : "6688b48175fd0249cbeecae6b00484435d07920b", | |
| "build_timestamp" : "2017-05-12T08:52:33Z", | |
| "build_snapshot" : false, | |
| "lucene_version" : "5.5.2" | |
| }, | |
| "tagline" : "You Know, for Search" | |
| } | |
| + break | |
| + curl -s -XPUT 'localhost:32930/data?pretty' -d '{ | |
| "mapping": { | |
| "test": { | |
| "name": {"type": "text"} | |
| } | |
| } | |
| }' | |
| { | |
| "acknowledged" : true | |
| } | |
| + curl -s -XPUT 'localhost:32930/data/type/1?pretty' -d '{"name":"Lazarus of Bethany"}' | |
| { | |
| "_index" : "data", | |
| "_type" : "type", | |
| "_id" : "1", | |
| "_version" : 1, | |
| "_shards" : { | |
| "total" : 1, | |
| "successful" : 1, | |
| "failed" : 0 | |
| }, | |
| "created" : true | |
| } | |
| + curl -s -XGET 'localhost:32930/data/type/_search?q=name:lazarus&pretty' | |
| { | |
| "took" : 31, | |
| "timed_out" : false, | |
| "_shards" : { | |
| "total" : 1, | |
| "successful" : 1, | |
| "failed" : 0 | |
| }, | |
| "hits" : { | |
| "total" : 0, | |
| "max_score" : null, | |
| "hits" : [ ] | |
| } | |
| } | |
| + curl -s -XDELETE 'localhost:32930/data?pretty' | |
| { | |
| "acknowledged" : true | |
| } | |
| + curl -s -XGET 'localhost:32930/data/type/_search?q=name:lazarus&pretty' | |
| { | |
| "error" : { | |
| "root_cause" : [ { | |
| "type" : "index_not_found_exception", | |
| "reason" : "no such index", | |
| "resource.type" : "index_or_alias", | |
| "resource.id" : "data", | |
| "index" : "data" | |
| } ], | |
| "type" : "index_not_found_exception", | |
| "reason" : "no such index", | |
| "resource.type" : "index_or_alias", | |
| "resource.id" : "data", | |
| "index" : "data" | |
| }, | |
| "status" : 404 | |
| } | |
| + curl -s -XPUT 'localhost:32930/data?pretty' -d '{ | |
| "mapping": { | |
| "test": { | |
| "name": {"type": "text"} | |
| } | |
| } | |
| }' | |
| { | |
| "acknowledged" : true | |
| } | |
| + curl -s -XPUT 'localhost:32930/data/type/2?pretty' -d '{"name":"Phoenix Lazarus"}' | |
| { | |
| "_index" : "data", | |
| "_type" : "type", | |
| "_id" : "2", | |
| "_version" : 1, | |
| "_shards" : { | |
| "total" : 1, | |
| "successful" : 1, | |
| "failed" : 0 | |
| }, | |
| "created" : true | |
| } | |
| + curl -s -XPOST 'localhost:32930/data/_refresh?pretty' | |
| { | |
| "_shards" : { | |
| "total" : 1, | |
| "successful" : 1, | |
| "failed" : 0 | |
| } | |
| } | |
| + curl -s -XGET 'localhost:32930/data/type/_search?q=name:lazarus&pretty' | |
| { | |
| "took" : 19, | |
| "timed_out" : false, | |
| "_shards" : { | |
| "total" : 1, | |
| "successful" : 1, | |
| "failed" : 0 | |
| }, | |
| "hits" : { | |
| "total" : 2, | |
| "max_score" : 0.37158427, | |
| "hits" : [ { | |
| "_index" : "data", | |
| "_type" : "type", | |
| "_id" : "2", | |
| "_score" : 0.37158427, | |
| "_source" : { | |
| "name" : "Phoenix Lazarus" | |
| } | |
| }, { | |
| "_index" : "data", | |
| "_type" : "type", | |
| "_id" : "1", | |
| "_score" : 0.2972674, | |
| "_source" : { | |
| "name" : "Lazarus of Bethany" | |
| } | |
| } ] | |
| } | |
| } | |
| + sudo docker rm -f 771ff200537ea54edf6c15c814439273c71a9a958f979472e4a167407542724f | |
| 771ff200537ea54edf6c15c814439273c71a9a958f979472e4a167407542724f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment