elasticsearch 配置 JDBC数据源 与IK 中文分词插件
来源:互联网 发布:java web项目打war包 编辑:程序博客网 时间:2024/05/22 07:42
配置 JDBC 数据源
1. 安装 openjdk(本人用的ubuntu)
sudo
apt-get
install
openjdk-7-jre
2.下载安装 elasticsearch
wget https:
//download
.elasticsearch.org
/elasticsearch/elasticsearch/elasticsearch-1
.4.4.deb
sudo
dpkg -i elasticsearch-1.4.4.deb
/etc/init
.d
/elasticsearch
start
3.安装JDBC 插件
.
/bin/plugin
--
install
jdbc --url http:
//xbib
.org
/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1
.4.0.10
/elasticsearch-river-jdbc-1
.4.0.10.zip
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
http://localhost:9200/_nodes?settings=true&pretty=true 配置信息(安装路径、插件...)
更多参数见:https://github.com/jprante/elasticsearch-river-jdbc
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'
IK 中文分词插件
1. elasticsearch 默认的分词功能:(简单的把每个汉字分开)
root@blog-mreald-com:
/usr/share/elasticsearch
# curl -XGET 'http://localhost:9200/posts/_analyze?analyzer=standard&pretty=true&text=Mreald致力于全栈工程师'
结果如下:
{
"tokens"
: [ {
"token"
:
"mreald"
,
"start_offset"
: 1,
"end_offset"
: 7,
"type"
:
"<ALPHANUM>"
,
"position"
: 1
}, {
"token"
:
"致"
,
"start_offset"
: 8,
"end_offset"
: 9,
"type"
:
"<IDEOGRAPHIC>"
,
"position"
: 2
}, {
"token"
:
"力"
,
"start_offset"
: 9,
"end_offset"
: 10,
"type"
:
"<IDEOGRAPHIC>"
,
"position"
: 3
}, {
"token"
:
"于"
,
"start_offset"
: 10,
"end_offset"
: 11,
"type"
:
"<IDEOGRAPHIC>"
,
"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 源代码 https://github.com/medcl/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.IK 安装之后:
root@blog-mreald-com:
/usr/share/elasticsearch
# curl -XGET 'http://localhost:9200/posts/_analyze?analyzer=ik&pretty=true&text=Mreald致力于全栈工程师'
查看结果:
{
"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
Errors:
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
- elasticsearch 配置 JDBC数据源与IK中文分词插件
- elasticsearch 配置 JDBC数据源 与IK 中文分词插件
- elasticsearch 配置 ik 分词与 jdbc 数据源
- Elasticsearch安装中文分词插件ik
- Elasticsearch安装中文分词插件ik
- Elasticsearch安装中文分词插件ik
- ElasticSearch增加ik中文分词插件
- Elasticsearch中文分词插件ik的安装
- Elasticsearch如何安装中文分词插件ik
- Elasticsearch如何安装中文分词插件ik
- Elasticsearch的中文分词插件ik
- Elasticsearch中文分词ik插件安装
- 安装Elasticsearch analysis ik中文分词插件
- Elasticsearch安装中文分词插件ik
- ElasticSearch配置ik中文分词器
- elasticsearch 2.3.4中文分词插件ik 1.9.4安装
- Elasticsearch中文分词插件IK Analyer安装操作指导
- ELK第三篇:Elasticsearch安装IK中文分词插件
- c++primer第一章
- android开源项目和框架
- Eclipse里面使用Maven搭建Web工程
- NEUQ 1398: 求和号
- Git与SVN的简单比较
- elasticsearch 配置 JDBC数据源 与IK 中文分词插件
- 抽象类
- nodejs中exports与module.exports的区别详细介绍
- Linux下搭建Memcached缓存系统
- Git命令图解
- TF-IDF与余弦相似性的应用(一):自动提取关键词
- Qt连接MySQL
- http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
- TF-IDF与余弦相似性的应用(二):找出相似文章