前言:
1、elasticsearch是一个基于Lucene的高扩展的分布式搜索服务器,支持开箱即用。
2、elasticsearch隐藏了Lucene的复杂性,对外提供Restful 接口来操作索引、搜索。
突出优点:
1.扩展性好,可部署上百台服务器集群,处理PB级数据。
2.近实时的去索引数据、搜索数据。
es和solr选择哪个?
1.如果你公司现在用的solr可以满足需求就不要换了。
2.如果你公司准备进行全文检索项目的开发,建议优先考虑elasticsearch,因为像Github这样大规模的搜索都在用 它。
下图是es在项目中的应用方式:
1)用户在前端搜索关键字
2)项目前端通过http方式请求项目服务端
3)项目服务端通过Http RESTful方式请求ES集群进行搜索
4)ES集群从索引库检索数据。
一:ElasticaSearch安装
安装配置:
1、新版本要求至少jdk1.8以上。
2、支持tar、zip、rpm等多种安装方式。 在windows下开发建议使用ZIP安装方式。
3、支持docker方式安装
详细参见:https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
下载ES: Elasticsearch 6.2.1 https://www.elastic.co/downloads/past-releases
解压 elasticsearch-6.2.1.zip
bin:脚本目录,包括:启动、停止等可执行脚本
config:配置文件目录
data:索引目录,存放索引文件的地方
logs:日志目录
modules:模块目录,包括了es的功能模块
plugins :插件目录,es支持插件机制
二:启动Es
进入bin目录,双击elasticsearch便可启动,出现端口号9200时,说明启动成功
显示结果如下(配置不同内容则不同)说明ES启动成功:
{ "name" : "lAFXwlR", "cluster_name" : "elasticsearch", "cluster_uuid" : "-5i3q9tpSNW7mCGgCdhC5g", "version" : { "number" : "6.2.1", "build_hash" : "7299dc3", "build_date" : "2018-02-07T19:34:26.990113Z", "build_snapshot" : false, "lucene_version" : "7.2.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } |
三:安装head插件
下载地址https://github.com/mobz/elasticsearch-head
然后安装 node.js
启动:启动cmd 进入 head根目录 输入npm run start 命令
启动出现画面
Last login: Wed Jul 31 12:19:43 on ttys001 ➜ elasticsearch-head-master npm run start > elasticsearch-head@0.0.0 start /Applications/MrWang/elasticsearch/chajian/elasticsearch-head-master > grunt server Running "connect:server" (connect) task Waiting forever... Started connect web server on http://localhost:9100 |
浏览器输入 http://localhost:9100
这时我们发现head启动是成功的,但是我们集群健康值显示未连接(我们上面明明启动了Es啊)
原因是:head插件作为客户端要连接ES服务(localhost:9200),此时存在跨域问题,elasticsearch默认不允许跨 域访问。
解决方案: 设置elasticsearch允许跨域访问。 在config/elasticsearch.yml 后面增加以下参数: #开启cors跨域访问支持,默认为false http.cors.enabled: true #跨域访问允许的域名地址,(允许所有域名)以上使 用正则 http.cors.allow-origin: /.*/ 注意:将config/elasticsearch.yml另存为utf-8编码格式。
http.cors.enabled: true
http.cors.allow-origin: /.*/
成功连接ES