環境配置java
操做系統:Cent OS 6.5 ElasticSearch:2.4.3 JDK:1.7 maven:3.3.9 elasticsearch-analysis-ik:1.4.1
一、首先要把jdk安裝好,而後下載elasticsearch-2.3.4.tar.gzgit
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.4/elasticsearch-2.3.4.tar.gz
二、解壓下載好的elasticsearch-2.3.4.tar.gzapache
[root@localhost opt]# cd /opt/ [root@localhost opt]# ls elasticsearch-2.3.4.tar.gz git-1.8.3.2.tar.gz [root@localhost opt]# tar zxvf elasticsearch-2.3.4.tar.gz
三、建立用戶和用戶組(elasticsearch 2.0.0版本後不能以root用戶啓動。)vim
[root@localhost opt]# groupadd elsearch [root@localhost opt]# useradd elsearch -g elsearch -p elasticsearch
四、把解壓好的目錄移動到/usr/local/elasticsearch瀏覽器
[root@localhost opt]# mv elasticsearch-2.3.4 /usr/local/elasticsearch
五、設置權限app
chown -R elsearch:elsearch /usr/local/elasticsearch
六、安裝es-head插件curl
[root@localhost plugins]# cd /usr/local/elasticsearch/bin/ [root@localhost plugins]# ./plugin –install mobz/elasticsearch-head
七、在瀏覽器中輸入http://localhost:9200,http://localhost:9200/_plugin/head/以下圖所示則ES啓動成功。elasticsearch
八、若要中止服務,則輸入sh elasticsearch stopmaven
[root@localhost opt]# cd /usr/local/elasticsearch/bin [root@localhost opt]# sh elasticsearch stop
九、安裝ik中文分詞,首先要安裝java 和 elasticsearchide
(1)安裝maven
[root@localhost opt]# tar zxvf apache-maven-3.3.9-bin.tar.gz [root@localhost opt]# mv apache-maven-3.3.9 /usr/local/maven [root@localhost opt]# vim /etc/profile
export PATH=$PATH:$JAVA_HOME/bin export M2_HOME=/usr/local/maven PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
[root@localhost opt]# source /etc/profile
(2)安裝elasticsearch-analysis-ik
[root@localhost opt]# wget -c [root@localhost opt]# unzip master.zip [root@localhost opt]# cd elasticsearch-analysis-ik-master/ [root@localhost elasticsearch-analysis-ik-master]# cp -Rf config/* ik /usr/local/elasticsearch/config/ [root@localhost elasticsearch-analysis-ik-master]# mvn package [root@localhost elasticsearch-analysis-ik-master]# /usr/local/elasticsearch/bin/plugin --install analysis-ik --url file:///alidata/download/elasticsearch-analysis-ik-master/target/releases/elasticsearch-analysis-ik-1.4.1.zip
(3)修改elasticsearch.yml,在該文件後面添加下面的內容:
[root@localhost ~]# cd /usr/local/elasticsearch/config [root@localhost config]# vim elasticsearch.yml index: analysis: analyzer: ik: alias: [ik_analyzer] type: org.elasticsearch.index.analysis.IkAnalyzerProvider ik_max_word: type: ik use_smart: false ik_smart: type: ik use_smart: true index.analysis.analyzer.default.type: ik
(4)從新啓動elasticsearch
[root@localhost config]# /usr/local/elasticsearch/bin/elasticsearch -d
(5) ik分詞測試,建立一個索引,名爲index
[root@localhost config]# curl -XPUT http://localhost:9200/index
爲索引index建立mapping
[root@localhost config]# curl -XPOST http://localhost:9200/index/fulltext/_mapping -d' { "fulltext": { "_all": { "analyzer": "ik" }, "properties": { "content": { "type" : "string", "boost" : 8.0, "term_vector" : "with_positions_offsets", "analyzer" : "ik", "include_in_all" : true } } } }'
測試
[root@localhost config]# curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d ' { "text":"www.acp.com" }'
顯示結果以下:
{ "tokens" : [ { "token" : "text", "start_offset" : 4, "end_offset" : 8, "type" : "ENGLISH", "position" : 1 }, { "token" : "www.acp.com", "start_offset" : 11, "end_offset" : 24, "type" : "LETTER", "position" : 2 }, { "token" : "www", "start_offset" : 11, "end_offset" : 14, "type" : "acp", "position" : 3 }, { "token" : "acp", "start_offset" : 15, "end_offset" : 20, "type" : "ENGLISH", "position" : 4 }, { "token" : "com", "start_offset" : 21, "end_offset" : 24, "type" : "ENGLISH", "position" : 5 }, {