Skip to content

Commit

Permalink
firest commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jiashiwen committed Aug 10, 2016
1 parent 14fcb32 commit 4e8c924
Show file tree
Hide file tree
Showing 20 changed files with 1,453 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/bin
/.gradle
/.settings
/build
settings.gradle
.project
.classpath
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM java:8u92-jre-alpine
RUN mkdir -p /elastictransfor
COPY ./build/libs/elastictransfor-1.0.jar /elastictransfor/
WORKDIR /elastictransfor
ENTRYPOINT ["java","-jar", "/elastictransfor/elastictransfor-1.0.jar"]
225 changes: 224 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,225 @@
# elastictransfor
elasticsearch index transfor,reindex tool


## Purpose

This programe is a command line tools for copy elasticsearch index.

# License

Apache License 2.0


## How Install


```
git clone https://github.com/jiashiwen/elastictransfor
```
```
cd elastictransfor
```
```
gradle clean build
```

you should see 'build/libs/elastictransfor-1.0.jar‘




## Usage

### command:
```
java -jar build/libs/elastictransfor-1.0.jar --help
```
### out put:
```
Usage: java -jar elastictransfor.jar [options]
Options:
--dsl
elasticsearch query dsl for Preform a partial transfor based on search
results.you must make content of this variable between '',just like
'{"query":{"term":{"word.primitive":{"value":"keywork"}}}}'
--help
Default: false
--script_file
execute script file write by json
--source_cluster
Source elasticsearch cluster name,default is 'elasticsearch
Default: elasticsearch
--source_host
Source elasticsearch cluster one of master ip address,default is
'127.0.0.1'.
Default: 127.0.0.1
--source_index
Source index name
--source_port
Source port
Default: 9300
--target_cluster
Target elasticsearch cluster name,default is 'elasticsearch
Default: elasticsearch
--target_host
Target elasticsearch cluster one of master ip address,default is
'127.0.0.1'.
Default: 127.0.0.1
--target_index
Target index name
--target_port
Target port
Default: 9300
--type
Transfor type value is [data,meta,force] and default value is 'meta'.If
value is 'metadata' try to create a new empty target index as
source;'data' copy source index documents to target index; 'force'
delete target index if exists and copy source index to target index.
Default: meta
```

## Example
### command
```
java -jar build/libs/elastictransfor-1.0.jar --source_cluster sourceclustername \
--source_host 10.0.0.1 \
--source_index sourceindex \
--target_cluster targetclustername \
--target_host 10.1.0.1 \
--target_index targetindex \
--type force
```

### out put:
```
2016-08-02 15:31:59 [INFO] - {
"help" : false,
"source_cluster" : "sourceclustername",
"source_host" : "10.0.0.1",
"source_port" : 9300,
"source_index" : "sourceindex",
"target_cluster" : "targetclustername",
"target_host" : "10.1.0.1",
"target_port" : 9300,
"target_index" : "targetindex",
"type" : "force"
}
2016-08-02 15:31:59 [INFO] - [Calvin Rankin] modules [], plugins [], sites []
2016-08-02 15:31:59 [INFO] - [Scarlet Spider] modules [], plugins [], sites []
FORCE OK!
2016-08-02 15:31:59 [INFO] - targetindex deleted!
2016-08-02 15:32:00 [INFO] - Target index targetindex create complete!
2016-08-02 15:32:00 [INFO] - 129 documents putted!!
2016-08-02 15:32:00 [INFO] - copy index sourceindex targetindex complete
```

## Example by query
### command
```
java -jar elastictransfor-1.0.jar \
--source_cluster sourceclustername \
--source_host 10.0.0.1 \
--source_index sourceindex \
--target_cluster targetclustername \
--target_host 10.1.0.1 \
--target_index targetindex \
--type data \
--dsl '{"query":{"term":{"word.primitive":{"value":"keyword"}}}}'
```
### out put:
```
2016-08-03 12:35:26 [INFO] - Your setting is:
{
"help" : false,
"source_cluster" : "sourceclustername",
"source_host" : "10.0.0.1",
"source_port" : 9300,
"source_index" : "sourceindex",
"target_cluster" : "targetclustername",
"target_host" : "10.1.0.1",
"target_port" : 9300,
"target_index" : "targetindex",
"type" : "data",
"dsl" : "{\"query\":{\"term\":{\"word.primitive\":{\"value\":\"keyword\"}}}}"
}
2016-08-03 12:35:26 [INFO] - [Jean Grey] modules [], plugins [], sites []
2016-08-03 12:35:27 [INFO] - [Man-Spider] modules [], plugins [], sites []
{"query":{"term":{"word.primitive":{"value":"keyword"}}}}
TYPE IS DATA OK!
2016-08-03 12:35:27 [INFO] - 128 documents putted!!
2016-08-03 12:35:27 [INFO] - copy index sourceindex 1 documents to targetindex complete
```

## Example by use json execute script
### command
```
java -jar elastictransfor-1.0.jar --script_file script.json
```
### script.json
```
{
"source_cluster": "es-source",
"source_host": "10.0.0.22",
"source_port": 9300,
"target_cluster": "es-target",
"target_host": "10.10.10.32",
"target_port": 9300,
"indexes": [
{
"source_index": "index1",
"target_index": "index1",
"type": "force"
},
{
"source_index": "index2",
"target_index": "index2-copy",
"type": "meta"
}
]
}
```


## Use Docker

### command

```
sudo docker run --rm jiashiwen/elastictransfor --source_cluster sourceclustername \
--source_host 10.0.0.1 \
--source_index sourceindex \
--target_cluster targetclustername \
--target_host 10.1.0.1 \
--target_index targetindex \
--type force
```
### out put:
```
2016-08-02 15:31:59 [INFO] - {
"help" : false,
"source_cluster" : "sourceclustername",
"source_host" : "10.0.0.1",
"source_port" : 9300,
"source_index" : "sourceindex",
"target_cluster" : "targetclustername",
"target_host" : "10.1.0.1",
"target_port" : 9300,
"target_index" : "targetindex",
"type" : "force"
}
2016-08-02 15:31:59 [INFO] - [Calvin Rankin] modules [], plugins [], sites []
2016-08-02 15:31:59 [INFO] - [Scarlet Spider] modules [], plugins [], sites []
FORCE OK!
2016-08-02 15:31:59 [INFO] - targetindex deleted!
2016-08-02 15:32:00 [INFO] - Target index targetindex create complete!
2016-08-02 15:32:00 [INFO] - 129 documents putted!!
2016-08-02 15:32:00 [INFO] - copy index sourceindex targetindex complete
```
## Use Docker with script
```
sudo docker run -v ${PWD}:/script --rm jiashiwen/elastictransfor --script_file /script/script.json
```
70 changes: 70 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'develop' at '16-7-27 上午11:05' with Gradle 2.14
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/2.14/userguide/tutorial_java_projects.html
*/

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'eclipse'


sourceCompatibility = 1.8
targetCompatibility = 1.8

//create a single Jar with all dependencies
version=1.0
//task releaseJar(type: Jar) {
// manifest {
// attributes 'Implementation-Title': 'Gradle Jar File Example',
// 'Implementation-Version': version,
// 'Main-Class': 'elastictransfor.ElasticTransforMain'
// }
// baseName = project.name + '-all'
// from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
// with jar
//}

jar {
manifest {
attributes("Implementation-Title": "Gradle",
"Implementation-Version": version,
'Main-Class': 'elastictransfor.ElasticTransforMain')
}
baseName = project.name
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
maven { url "http://10.204.12.34:8081/repository/maven-public" }
jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'
// compile 'org.slf4j:slf4j-log4j12:1.7.21'
// compile 'org.slf4j:slf4j-simple:1.7.21'
compile 'com.beust:jcommander:1.55'
compile 'ch.qos.logback:logback-classic:1.1.7'
compile 'ch.qos.logback:logback-core:1.1.7'
compile 'commons-cli:commons-cli:1.3.1'
compile "com.beust:jcommander:1.48"


compile group: 'org.elasticsearch', name: 'elasticsearch', version: '2.3.3'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.6.6'

// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Jul 27 11:05:09 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
Loading

0 comments on commit 4e8c924

Please sign in to comment.