|
1 | 1 | # elastictransfor
|
2 |
| -elasticsearch index transfor,reindex tool |
| 2 | + |
| 3 | + |
| 4 | +## Purpose |
| 5 | + |
| 6 | +This programe is a command line tools for copy elasticsearch index. |
| 7 | + |
| 8 | +# License |
| 9 | + |
| 10 | +Apache License 2.0 |
| 11 | + |
| 12 | + |
| 13 | +## How Install |
| 14 | + |
| 15 | + |
| 16 | +``` |
| 17 | +git clone https://github.com/jiashiwen/elastictransfor |
| 18 | +``` |
| 19 | +``` |
| 20 | +cd elastictransfor |
| 21 | +``` |
| 22 | +``` |
| 23 | +gradle clean build |
| 24 | +``` |
| 25 | + |
| 26 | +you should see 'build/libs/elastictransfor-1.0.jar‘ |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### command: |
| 34 | +``` |
| 35 | +java -jar build/libs/elastictransfor-1.0.jar --help |
| 36 | +``` |
| 37 | +### out put: |
| 38 | +``` |
| 39 | +Usage: java -jar elastictransfor.jar [options] |
| 40 | + Options: |
| 41 | + --dsl |
| 42 | + elasticsearch query dsl for Preform a partial transfor based on search |
| 43 | + results.you must make content of this variable between '',just like |
| 44 | + '{"query":{"term":{"word.primitive":{"value":"keywork"}}}}' |
| 45 | + --help |
| 46 | +
|
| 47 | + Default: false |
| 48 | + --script_file |
| 49 | + execute script file write by json |
| 50 | + --source_cluster |
| 51 | + Source elasticsearch cluster name,default is 'elasticsearch |
| 52 | + Default: elasticsearch |
| 53 | + --source_host |
| 54 | + Source elasticsearch cluster one of master ip address,default is |
| 55 | + '127.0.0.1'. |
| 56 | + Default: 127.0.0.1 |
| 57 | + --source_index |
| 58 | + Source index name |
| 59 | + --source_port |
| 60 | + Source port |
| 61 | + Default: 9300 |
| 62 | + --target_cluster |
| 63 | + Target elasticsearch cluster name,default is 'elasticsearch |
| 64 | + Default: elasticsearch |
| 65 | + --target_host |
| 66 | + Target elasticsearch cluster one of master ip address,default is |
| 67 | + '127.0.0.1'. |
| 68 | + Default: 127.0.0.1 |
| 69 | + --target_index |
| 70 | + Target index name |
| 71 | + --target_port |
| 72 | + Target port |
| 73 | + Default: 9300 |
| 74 | + --type |
| 75 | + Transfor type value is [data,meta,force] and default value is 'meta'.If |
| 76 | + value is 'metadata' try to create a new empty target index as |
| 77 | + source;'data' copy source index documents to target index; 'force' |
| 78 | + delete target index if exists and copy source index to target index. |
| 79 | + Default: meta |
| 80 | +
|
| 81 | +``` |
| 82 | + |
| 83 | +## Example |
| 84 | +### command |
| 85 | +``` |
| 86 | +java -jar build/libs/elastictransfor-1.0.jar --source_cluster sourceclustername \ |
| 87 | + --source_host 10.0.0.1 \ |
| 88 | + --source_index sourceindex \ |
| 89 | + --target_cluster targetclustername \ |
| 90 | + --target_host 10.1.0.1 \ |
| 91 | + --target_index targetindex \ |
| 92 | + --type force |
| 93 | + |
| 94 | +``` |
| 95 | + |
| 96 | +### out put: |
| 97 | +``` |
| 98 | +2016-08-02 15:31:59 [INFO] - { |
| 99 | + "help" : false, |
| 100 | + "source_cluster" : "sourceclustername", |
| 101 | + "source_host" : "10.0.0.1", |
| 102 | + "source_port" : 9300, |
| 103 | + "source_index" : "sourceindex", |
| 104 | + "target_cluster" : "targetclustername", |
| 105 | + "target_host" : "10.1.0.1", |
| 106 | + "target_port" : 9300, |
| 107 | + "target_index" : "targetindex", |
| 108 | + "type" : "force" |
| 109 | +} |
| 110 | +2016-08-02 15:31:59 [INFO] - [Calvin Rankin] modules [], plugins [], sites [] |
| 111 | +2016-08-02 15:31:59 [INFO] - [Scarlet Spider] modules [], plugins [], sites [] |
| 112 | +FORCE OK! |
| 113 | +2016-08-02 15:31:59 [INFO] - targetindex deleted! |
| 114 | +2016-08-02 15:32:00 [INFO] - Target index targetindex create complete! |
| 115 | +2016-08-02 15:32:00 [INFO] - 129 documents putted!! |
| 116 | +2016-08-02 15:32:00 [INFO] - copy index sourceindex targetindex complete |
| 117 | +``` |
| 118 | + |
| 119 | +## Example by query |
| 120 | +### command |
| 121 | +``` |
| 122 | +java -jar elastictransfor-1.0.jar \ |
| 123 | + --source_cluster sourceclustername \ |
| 124 | + --source_host 10.0.0.1 \ |
| 125 | + --source_index sourceindex \ |
| 126 | + --target_cluster targetclustername \ |
| 127 | + --target_host 10.1.0.1 \ |
| 128 | + --target_index targetindex \ |
| 129 | + --type data \ |
| 130 | + --dsl '{"query":{"term":{"word.primitive":{"value":"keyword"}}}}' |
| 131 | +``` |
| 132 | +### out put: |
| 133 | +``` |
| 134 | +2016-08-03 12:35:26 [INFO] - Your setting is: |
| 135 | + { |
| 136 | + "help" : false, |
| 137 | + "source_cluster" : "sourceclustername", |
| 138 | + "source_host" : "10.0.0.1", |
| 139 | + "source_port" : 9300, |
| 140 | + "source_index" : "sourceindex", |
| 141 | + "target_cluster" : "targetclustername", |
| 142 | + "target_host" : "10.1.0.1", |
| 143 | + "target_port" : 9300, |
| 144 | + "target_index" : "targetindex", |
| 145 | + "type" : "data", |
| 146 | + "dsl" : "{\"query\":{\"term\":{\"word.primitive\":{\"value\":\"keyword\"}}}}" |
| 147 | +} |
| 148 | +2016-08-03 12:35:26 [INFO] - [Jean Grey] modules [], plugins [], sites [] |
| 149 | +2016-08-03 12:35:27 [INFO] - [Man-Spider] modules [], plugins [], sites [] |
| 150 | +{"query":{"term":{"word.primitive":{"value":"keyword"}}}} |
| 151 | +TYPE IS DATA OK! |
| 152 | +2016-08-03 12:35:27 [INFO] - 128 documents putted!! |
| 153 | +2016-08-03 12:35:27 [INFO] - copy index sourceindex 1 documents to targetindex complete |
| 154 | +``` |
| 155 | + |
| 156 | +## Example by use json execute script |
| 157 | +### command |
| 158 | +``` |
| 159 | +java -jar elastictransfor-1.0.jar --script_file script.json |
| 160 | +``` |
| 161 | +### script.json |
| 162 | +``` |
| 163 | +{ |
| 164 | + "source_cluster": "es-source", |
| 165 | + "source_host": "10.0.0.22", |
| 166 | + "source_port": 9300, |
| 167 | + "target_cluster": "es-target", |
| 168 | + "target_host": "10.10.10.32", |
| 169 | + "target_port": 9300, |
| 170 | + "indexes": [ |
| 171 | + { |
| 172 | + "source_index": "index1", |
| 173 | + "target_index": "index1", |
| 174 | + "type": "force" |
| 175 | + }, |
| 176 | + { |
| 177 | + "source_index": "index2", |
| 178 | + "target_index": "index2-copy", |
| 179 | + "type": "meta" |
| 180 | + } |
| 181 | + ] |
| 182 | +} |
| 183 | +
|
| 184 | +``` |
| 185 | + |
| 186 | + |
| 187 | +## Use Docker |
| 188 | + |
| 189 | +### command |
| 190 | + |
| 191 | +``` |
| 192 | +sudo docker run --rm jiashiwen/elastictransfor --source_cluster sourceclustername \ |
| 193 | + --source_host 10.0.0.1 \ |
| 194 | + --source_index sourceindex \ |
| 195 | + --target_cluster targetclustername \ |
| 196 | + --target_host 10.1.0.1 \ |
| 197 | + --target_index targetindex \ |
| 198 | + --type force |
| 199 | +``` |
| 200 | +### out put: |
| 201 | +``` |
| 202 | +2016-08-02 15:31:59 [INFO] - { |
| 203 | + "help" : false, |
| 204 | + "source_cluster" : "sourceclustername", |
| 205 | + "source_host" : "10.0.0.1", |
| 206 | + "source_port" : 9300, |
| 207 | + "source_index" : "sourceindex", |
| 208 | + "target_cluster" : "targetclustername", |
| 209 | + "target_host" : "10.1.0.1", |
| 210 | + "target_port" : 9300, |
| 211 | + "target_index" : "targetindex", |
| 212 | + "type" : "force" |
| 213 | +} |
| 214 | +2016-08-02 15:31:59 [INFO] - [Calvin Rankin] modules [], plugins [], sites [] |
| 215 | +2016-08-02 15:31:59 [INFO] - [Scarlet Spider] modules [], plugins [], sites [] |
| 216 | +FORCE OK! |
| 217 | +2016-08-02 15:31:59 [INFO] - targetindex deleted! |
| 218 | +2016-08-02 15:32:00 [INFO] - Target index targetindex create complete! |
| 219 | +2016-08-02 15:32:00 [INFO] - 129 documents putted!! |
| 220 | +2016-08-02 15:32:00 [INFO] - copy index sourceindex targetindex complete |
| 221 | +``` |
| 222 | +## Use Docker with script |
| 223 | +``` |
| 224 | +sudo docker run -v ${PWD}:/script --rm jiashiwen/elastictransfor --script_file /script/script.json |
| 225 | +``` |
0 commit comments