分类: 大数据
2015-03-08 23:28:50
1. 安装 openjdk(本人用的ubuntu)
sudo apt-get install openjdk-7-jre
2.下载安装 elasticsearch
wget sudo dpkg -i elasticsearch-1.4.4.deb /etc/init.d/elasticsearch start
3.安装JDBC 插件
./bin/plugin --install jdbc --url
4.安装Mysql JDBC 驱动
curl -o mysql-connector-java-5.1.33.zip -L 'http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.33.zip/from/http://cdn.mysql.com/' unzip mysql-connector-java-5.1.33.zip cp mysql-connector-java-5.1.33-bin.jar $ES_HOME/plugins/jdbc/ chmod 644 $ES_HOME/plugins/jdbc/* /etc/init.d/elasticsearch restart
配置信息(安装路径、插件...)
更多参数见:
5.测试mysql (用户root 密码passwd 库jdbctest 表名posts)
curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{ "type" : "jdbc", "jdbc" : { "url" : "jdbc:mysql://localhost:3306/jdbctest", "user" : "root", "password" : "passwd", "sql" : "select * from posts" } }' curl 'localhost:9200/jdbc/_search'
1. elasticsearch 默认的分词功能:(简单的把每个汉字分开)
root@blog-mreald-com:/usr/share/elasticsearch# curl -XGET '致力于全栈工程师'
结果如下:
{ "tokens" : [ { "token" : "mreald", "start_offset" : 1, "end_offset" : 7, "type" : "", "position" : 1 }, { "token" : "致", "start_offset" : 8, "end_offset" : 9, "type" : " ", "position" : 2 }, { "token" : "力", "start_offset" : 9, "end_offset" : 10, "type" : " ", "position" : 3 }, { "token" : "于", "start_offset" : 10, "end_offset" : 11, "type" : " ", "position" : 4 }, { ...............................
2.安装IK插件:(1.2.9没有jar包,要自己打)
要与ES版本配套:
Version
-—————
master | 1.4.0 → master
1.2.9 | 1.4.0
1.2.8 | 1.3.2
1.2.7 | 1.2.1
下载elasticsearch-analysis-ik 源代码
cd elasticsearch-analysis-ik mvn package cd target/releases/
就会看到 elasticsearch-analysis-ik-1.2.9.zip
把elasticsearch-analysis-ik-1.2.9.zip 解压到 ES/plugins/analysis-ik/
root@blog-mreald-com:/usr/share/elasticsearch/plugins/analysis-ik# ls commons-codec-1.6.jar elasticsearch-analysis-ik-1.2.9.jar httpclient-4.3.5.jar commons-logging-1.1.3.jar elasticsearch-analysis-ik-1.2.9.zip httpcore-4.3.2.jar
将ik的配置和字典都复制到ES_HOME/config下
sudo cp -R ik /etc/elasticsearch
elasticsearch.yml 增加下面一行,然后重启下ES
index.analysis.analyzer.ik.type : 'ik'
3.查看结果:
root@blog-mreald-com:/usr/share/elasticsearch# curl -XGET '致力于全栈工程师'
查看结果:
{ "tokens" : [ { "token" : "mreald", "start_offset" : 1, "end_offset" : 7, "type" : "ENGLISH", "position" : 1 }, { "token" : "致力于", "start_offset" : 8, "end_offset" : 11, "type" : "CN_WORD", "position" : 2 }, { "token" : "致力", "start_offset" : 8, "end_offset" : 10, "type" : "CN_WORD", "position" : 3 }, { "token" : "致", "start_offset" : 8, "end_offset" : 9, "type" : "CN_WORD", "position" : 4 }, { ...................
注意事件:
mvn 需要额外安装,centos 方法
ubuntu 使用 sudo aptitude install maven
1.
[ERROR] Unable to locate the Javac Compiler in: /usr/lib/java/jre1.7.0_55/../lib/tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project elasticsearch-analysis-ik: Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] /usr/lib/java/jre1.7.0_55/../lib/tools.jar
原因:ubuntu 自带的JAVA openjdk包不全,没有tools.jar包。解决方法(find 下你刚才安装的openjdk在哪儿):
sudo apt-get install openjdk-7-jre; export export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
2.错误:
{ "error" : "NoShardAvailableActionException[[_na][_na] No shard available for [org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest@7c9c15]]", "status" : 503 }
cp 过去的是: target/releases/elasticsearch-analysis-ik-1.2.9.zip
不是: target/elasticsearch-analysis-ik-1.2.9.jar
博客原文:http://blog.mreald.com/160 转载请保留出处,谢谢!