1. Preparatory work
Download Elasticsearch version number 2.3.4 https://www.elastic.co/downloads/past-releases/elasticsearch-2-3-4, download the package required to synchronize the database https:// codeload.github.com/jprante/elasticsearch-jdbc/tar.gz/2.3.4.0, download ik chinese word https://github.com/medcl/ Elasticsearch-analysis-ik/releases/download/v1.9.4/elasticsearch-analysis-ik-1.9.4.zip
2. Running Elasticsearch
Extract
tar vxf elasticsearch-2.3. 4. Tar
The Elasticsearch is ready to start in the foreground by executing the following commands:
./bin/Elasticsearch
If you want to run in daemon mode in the background, add the-D parameter
./bin/elasticsearch-d
Open another terminal for testing:
" Http://127.0.0.1:9200/?pretty "
You can see the following return information:
{ "name": "Nico Minoru", "cluster_name": "Elasticsearch", "version":{ "number": "2.3.4", "Build_hash": "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f", " Build_timestamp ":" 2016-06-30t11:24:31z ", false, " lucene_version ":" 5.5.0 " }, " tagline ":" You Know, for Search "}
This means that your elasticsearch cluster is up and running properly.
3. Add IK Chinese participleCreate the folder IK under elasticsearch/plugins/, and extract the Elasticsearch-analysis-ik.zip to the following
4. Creating an index mapping synchronizing the database
write a script. Sh
#删除索引curl-xdelete'Http://127.0.0.1:9200/gsdata'#创建Mappingcurl-xput"Http://127.0.0.1:9200/gsdata"-D'{ "Mappings":{ "egov_basc_jbxx":{ "_all": { "Analyzer":"Ik_max_word", "Search_analyzer":"Ik_max_word", "Term_vector":"No", "Store":"false" }, "Dynamic":false, "Properties": { "ID":{ "type":"string" }, "Entname":{ "type":"string", "Analyzer":"Ik_smart" }, "Lerep":{ "type":"string", "Analyzer":"Ik_max_word" }, "Poscope":{ "type":"string", "Analyzer":"Ik_smart" }, "Econat":{ "type":"string", "Analyzer":"Ik_smart" }, "esdate":{ "type":"Date" }, "Regcap":{ "type":"integer" }, " State":{ "type":"string" } } } } }'#同步数据 DIR=/home/search/elasticsearch-jdbc-2.3.4.0bin=${dir}/Binlib=${dir}/Libjava_home=/home/search/jdk1.8. 0_111Echo '{ "type":"JDBC", "JDBC" : { "URL":"JDBC:ORACLE:THIN:@//127.0.0.1:1521/ORCL", "User":"Intgdata", "Password":"Intgdata", "SQL":"Select ID as \ "Id\", entname as \ "Entname\", lerep as \ "Lerep\", opscope as \ "Poscope\", Econat as \ "Econat\", estd ATE as \ "Esdate\", regcap as \ "Regcap\", state as \ "State\" from Egov_basc_jbxx", "treat_binary_as_string":true, "Index":"Gsdata", "type":"egov_basc_jbxx", "Elasticsearch" : { "Cluster":"Elasticsearch", "Host":"127.0.0.1", "Port":9300 } }}'| ${java_home}/bin/java \-CP "${lib}/*" -dlog4j.configurationfile=${bin}/log4j2.xml Org.xbib.tools.Runner Org.xbib.tools.JDBCImporter
Note: Since this version elasticsearch-jdbc must be more than 1.8, you can specify the JDK to run
5. Run the script. Sh
6. See if the data is entered
' Http://localhost:9200/_search '
Build Elasticsearch servers and synchronize databases on Linux