分布式搜索引擎Elasticsearch的简单使用
官方网址:https://www.elastic.co/products/elasticsearch/
一、特性
1、支持中文分词
2、支持多种数据源的全文检索引擎
3、分布式
4、基于lucene的开源搜索引擎
5、Restful api
二、资源
smartcn, 默认的中文分词 :https://github.com/elasticsearch/elasticsearch-analysis-smartcn
mmseg :https://github.com/medcl/elasticsearch-analysis-mmseg
ik:https://github.com/medcl/elasticsearch-analysis-ik
pinyin, 拼音分词可用于输入拼音提示中文 :https://github.com/medcl/elasticsearch-analysis-pinyin
stconvert, 中文简繁体互换 :https://github.com/medcl/elasticsearch-analysis-stconvert
elasticsearch-servicewrapper:https://github.com/elasticsearch/elasticsearch-servicewrapper
Elastic HQ,elasticsearch的监控工具:http://www.elastichq.org
elasticsearch-rtf :https://github.com/medcl/elasticsearch-rtf
三、安装
服务器:Linux(centos 6.x)
java环境:JDK 1.8.0
elasticsearch:2.3.1
elasticsearch-jdbc(数据源插件):2.3.1
IK Analysis(中文分词插件):1.9.1
1、安装Java
yum install java-1.8.0
2、安装Elasticsearch
#创建.repo文件(elasticsearch.repo) cat >> /etc/yum.repos.d/elasticsearch.repo << EOF [elasticsearch-2.x] name=Elasticsearch repository for 2.x packages baseurl=https://packages.elastic.co/elasticsearch/2.x/centos gpgcheck=1 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch enabled=1 EOF#导入key: rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch yum install elasticsearch
3、创建用户
如果是用root账号启动,会报以下错误
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root. at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93) at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144) at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35) Refer to the log for complete error details.
这是出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑, 建议创建一个单独的用户用来运行ElasticSearch
groupadd elsearch useradd elsearch -g elsearch -p elasticsearch
4、创建目录
mkdir -p /data/elasticsearch/data mkdir -p /data/elasticsearch/logs chown -R elsearch:elsearch /data/elasticsearch/data chown -R elsearch:elsearch /data/elasticsearch/logs
5、生成配置文件(/etc/elasticsearch/elasticsearch.yml)
#集群名(同一个集群,名称必须相同) cluster.name: my-application #服务节点名(每个服务节点不一样) node.name: node-1 #数据存储路径 path.data: /data/elasticsearch/data #服务日志路径 path.logs: /data/elasticsearch/logs #服务ip地址 network.host: 0.0.0.0 #服务端口 http.port: 9200
四、IK的安装
1.安装maven工具
wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo yum install apache-maven
2.下载ik源码包
git clone https://github.com/medcl/elasticsearch-analysis-ik
3.生成jar插件包
mvn clean mvn compile mvn packageunzip target/releases/elasticsearch-analysis-ik-*.zip cp -r target/releases/ /usr/share/elasticsearch/plugins/ik
4.配置词库(ik自带搜狗词库)
配置:/usr/share/elasticsearch/plugins/ik/config/ik/IKAnalyzer.cfg.xml
<entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic;custom/sougou.dic</entry>
将jar包复制到Elasticsearch的plugins/analysis-ik
目录下,再把解压出的ik目录(配置和词典等),复制到Elasticsearch的config
目录下。然后编辑配置文件elasticsearch.yml
,在后面加一行:
index.analysis.analyzer.ik.type : "ik"
重启service elasticsearch restart
然后录入数据,创建索引
五、elasticsearch-jdbc
1、使用feeder方式
wget http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/2.3.1.0/elasticsearch-jdbc-2.3.1.0-dist.zip unzip elasticsearch-jdbc-2.3.1.0-dist.zip
编辑数据导入脚本import.sh
export JDBC_IMPORTER_HOME=/elasticsearch-jdbc-2.3.1.0bin=$JDBC_IMPORTER_HOME/bin lib=$JDBC_IMPORTER_HOME/lib echo '{ "type" : "jdbc", "jdbc": { "url":"jdbc:mysql://127.0.0.1:3306/dbtest", "user":"root", "password":"123456", "sql":"select * from test_tb", "index" : "customer", "type" : "external" }}' | java \-cp "${lib}/*" \-Dlog4j.configurationFile=${bin}/log4j2.xml \org.xbib.tools.Runner \org.xbib.tools.JDBCImporter
测试
curl -XGET 'localhost:9200/customer/external/_search?pretty&q=a'
删除索引
curl -XDELETE 'http://localhost:9200/customer'
2、使用river方式
#安装elasticsearch curl -OL https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.2.zipcd $ES_HOME unzip path/to/elasticsearch-1.4.2.zip#安装JDBC插件 ./bin/plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.4.0.6/elasticsearch-river-jdbc-1.4.0.6-plugin.zip#下载mysql driver 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/' cp mysql-connector-java-5.1.33-bin.jar $ES_HOME/plugins/jdbc/ chmod 644 $ES_HOME/plugins/jdbc/*#启动elasticsearch ./bin/elasticsearch#停止river curl -XDELETE 'localhost:9200/_river/my_jdbc_river/'
JDBC插件参数
curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{"type" : "jdbc","jdbc" : {"url" : "jdbc:mysql://localhost:3306/test","user" : "","password" : "","sql" : "select * from orders","index" : "myindex","type" : "mytype",...} }'如果一个数组传递给jdbc字段,多个river源也是可以的curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{<river parameters>"type" : "jdbc","jdbc" : [ {<river definition 1>}, {<river definition 2>} ] }'curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{"type" : "jdbc","jdbc" : {"driver" : "com.mysql.jdbc.Driver","url" : "jdbc:mysql://localhost:3306/test","user" : "root","password" : "123456","sql" : "select * from test.student;","interval" : "30","index" : "test","type" : "student"}}’
查看ES是否已经同步了这些数据
curl -XGET 'localhost:9200/test/student/_search?pretty&q=*'
官网地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
参考
https://www.elastic.co/guide/en/elasticsearch/guide/current/empty-search.html
https://github.com/medcl/elasticsearch-analysis-ik
http://blog.csdn.net/clementad/article/details/46898013
https://endymecy.gitbooks.io/elasticsearch-guide-chinese/content/elasticsearch-river-jdbc.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
https://github.com/jprante/elasticsearch-jdbc
http://www.voidcn.com/blog/wojiushiwo987/article/p-6058574.html
http://leotse90.com/2015/11/11/ElasticSearch%E4%B8%8EMySQL%E6%95%B0%E6%8D%AE%E5%90%8C%E6%AD%A5%E4%BB%A5%E5%8F%8A%E4%BF%AE%E6%94%B9%E8%A1%A8%E7%BB%93%E6%9E%84/
http://www.jianshu.com/p/638ff7b848cc
http://www.cnblogs.com/buzzlight/p/logstash_elasticsearch_kibana_log.html
分布式搜索引擎Elasticsearch的简单使用相关推荐
- 分布式搜索引擎-ElasticSearch(上集)
个人简介 作者是一个来自河源的大三在校生,以下笔记都是作者自学之路的一些浅薄经验,如有错误请指正,将来会不断的完善笔记,帮助更多的Java爱好者入门. 文章目录 个人简介 分布式搜索引擎-Elasti ...
- 分布式搜索引擎ElasticSearch(四) -- 插件使用
2019独角兽企业重金招聘Python工程师标准>>> 分布式搜索引擎ElasticSearch(四) -- 插件使用 博客分类: 搜索引擎,爬虫 首先 非常感谢国内大神 - Med ...
- 微服务03 分布式搜索引擎 elasticsearch ELK kibana RestAPI 索引库 DSL查询 RestClient 黑马旅游
分布式搜索引擎01 -- elasticsearch基础 0.学习目标 1.初识elasticsearch 1.1.了解ES 1.1.1.elasticsearch的作用 elasticsearch是 ...
- SpringBoot2.x集成分布式搜索引擎Elasticsearch
参考资料: https://my.oschina.net/uwith/blog/3226665 https://www.freesion.com/article/8399663484/ https:/ ...
- 分布式搜索引擎ElasticSearch+Kibana (Marvel插件安装详解)
在安装插件的过程中,尤其是安装Marvel插件遇到了很多问题,要下载license.Marvel-agent,又要下载安装Kibana 版本需求 Java 7 or later Elasticsear ...
- 分布式搜索引擎ElasticSearch
总结前言: 因为最近项目开发有用到ElasticSearch,之前在去年年底也在技术交流研讨会上听过这个技术,其实听过很多次,但是每次都没有关注,直到现在用到了,就在这做一个总结,也是写一下学习成果, ...
- ElasticSearch logo 分布式搜索引擎 ElasticSearch
原文来自:http://www.oschina.net/p/elasticsearch Elastic Search 是一个基于Lucene构建的开源,分布式,RESTful搜索引擎.设计用于云计算中 ...
- 分布式搜索引擎ElasticSearch之高级运用(三)
一.倒排索引原理 ES采用的是倒排索引(Inverted Index), 也称为反向索引. 有反向索引,也会有正向索引. 正向索引 正排索引是以文档的ID作为关键字,并且记录文档中每个字段的值信息,通 ...
- 分布式搜索引擎ElasticSearch(二)---ElasticSearch进阶使用教程
ElasticSearch ElasticSearch进阶教程 文档批量操作 批量获取文档数据 批量操作文档数据 DSL语言高级查询 无条件查询 有查询条件 叶子条件查询(单字段查询条件) 组合条件查 ...
- 分布式搜索引擎Elasticsearch(一):Elasticsearch命令
前言:本文为原创 若有错误欢迎评论! linux安装elasticsearch6.5.4与windows下的kibana 请参考我的博客https://blog.csdn.net/weixin_439 ...
最新文章
- LiTAMIN2:一种超轻型LiDAR-SLAM(ICRA2021)
- JZOJ 5907. 【NOIP2018模拟10.16】轻功(qinggong)
- Swift之旅--数据类型
- Deep Learning(深度学习) 学习笔记(四)
- 理解 python 装饰器
- 机器学习领域综述大列表:真的很大, 你忍一忍
- python笔记:datetime模块中的函数
- VM centos网络配置
- SpringCloud与Ribbon整合的时候是如何提供RestTemplate负载均衡功能?
- 聚合直播源码原生播放器php分享,原生聚合直播搭建源码
- 深入游戏变速底层原理以及内核变速的实现
- win10安装mysql初始化失败怎么办_Win10系统安装SQL2000失败 初始化错误该怎么解决?...
- VScommunity2019 0x00007FFCCA14B7EC (ucrtbased.dll) (Project1.exe 中)处有未经处理的异常: 将一个无效参数传递给了将无效参数视为严重错误
- 笔记本电源指示灯维修及散热硅脂替换
- HHUOJ 1395 彩票
- 3.Open3D教程——点云数据操作
- mysql中哪种方式可以开启一个事务_网易技术类笔试题-2016
- 乐高式微服务化改造(上)
- ODOO15委外加工(外协)业财一体凭证生成方案
- Oriented Object Proposals
热门文章
- Atitit.研发团队与公司绩效管理的原理概论的attilax总结
- Atitit.wrmi web rmi框架新特性
- atitit.ajax上传文件的实现原理 与设计
- paip.自定义java 泛型类与泛型方法的实现总结
- PAIP.DW 各个版本的差别大比较。
- 日志记录总结要整理的地方
- Julia:last() 和first()
- OpenStack基金会任命马振强为中国区大使
- Apache基金会获得Pineapple基金88.34比特币捐赠
- 和包支付的钱哪里来_老瓦发问国际乒联:道理我都懂!问题钱从哪里来?