前言
初学者,建议先观看参考链接中的视频教程 P3概述(非广告),对Elasticsearch 进行一个基本的了解. 然后按照基础配置安装完所有软件后和基础语法这个入门篇(一)之后,再去看视频可以从 P7开始看起,可以节省大量时间。
已经对ES有部分了解的开发者,建议直接观看我的文章,进行安装和基础语法练习即可,无需再去观看视频,有问题直接看官方文档。
文章虽然更加枯燥,却比看视频高效,唯一的阻碍只是英文
参考链接
-
ES官方网站 安装配置建议参看官方文档说明 Getting started
-
Bilibili 狂神说 ES教程 ES基础了解,基本工具使用和语法了解,配合官方文档使用
ES介绍
Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。
Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。Elasticsearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。
根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。
基础配置
安装 Elasticsearch 7.9
使用zip
进行安装,解压,即可,官方文档地址
-
Download the Elasticsearch 7.9.1 Windows zip file from the Elasticsearch download page.
-
Extract the contents of the zip file to a directory on your computer, for example,
C:\Program Files
. -
Open a command prompt as an Administrator and navigate to the directory that contains the extracted files, for example:
cd C:\devTools\elasticsearch-7.9.1
-
Open file
conf\elasticsearch.yml
, Add cors origin(跨域访问) settings tail of file:# Allow cors origin http.cors.enabled: true http.cors.allow-origin: "*"
-
using
elasticsearch-service.bat
install service for windowsbin\elasticsearch-service.bat install
-
Start Elasticsearch:
bin\elasticsearch.bat
or
bin\elasticsearch-service.bat start # 启动 bin\elasticsearch-service.bat stop # 停止
也可以使用
elasticsearch-service.bat manager
调用图形化界面修改配置参数 -
open http://localhost:9200/, then you can see below code:
{ "name" : "XXXXXXX", "cluster_name" : "elasticsearch", "cluster_uuid" : "va7ayoctSDi571dHHe4E_g", "version" : { "number" : "7.9.1", "build_flavor" : "default", "build_type" : "zip", "build_hash" : "083627f112ba94dffc1232e8b42b73492789ef91", "build_date" : "2020-09-01T21:22:21.964974Z", "build_snapshot" : false, "lucene_version" : "8.6.2", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
注意: 不可以安装路径中包含 空格和中文字符,包括不限于 Program file
文件夹
安装 kibana-7.9.1 可视化工具
kibana是官方提供的一款可视化工具,使用其中的开发者工具,我们可以更好的练习基础语法,更像一个MySql Command。
- Download the Kibana 7.9.1 Windows zip file from the Kibana download page.
- Extract the contents of the zip file to a directory on your computer, for example,
C:\Program Files
. - Open a command prompt as an Administrator and navigate to the directory that contains the extracted files, for example:
cd C:\devTools\kibana-7.9.1-windows
- 打开
conf\kibana.yml
,在末尾追加如下代码,实现国际化:i18n.locale: "zh-CN"
- Start Kibana:
bin\kibana.bat
- open http://localhost:5601/, then you can see website for Kibana.
安装 Elasticsearch-head 插件
Head 插件 并非必须安装,类似于 Navicat 对于 MySql 一样,但并不能执行太复杂操作,且没有语法提示,主要是用来进行可视化查看数据,执行命令还是Kibana更方便一点。
GItHub地址:elasticsearch-head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
- open http://localhost:9100/
This will start a local webserver running on port 9100 serving elasticsearch-head
安装 IK中文分词器
Elasticsearch 默认无法对中文进行分词,需要额外下载插件进行分词,支持两个分词模式ik_smart
, ik_max_word
, 详情可参见基础语法。
GItHub地址:IK Analysis for Elasticsearch
- download pre-build package from here: https://github.com/medcl/elasticsearch-analysis-ik/releases
- create plugin folder
cd your-es-root/plugins/ && mkdir ik
- unzip plugin to folder
your-es-root/plugins/ik
- restart your Elasticsearch
- if you start Kibana you also need restart Kibana.
基础语法
详细语法文档:请参考官方 REST API 文档
中文文档可以看我写的基础语法 :Elasticsearch 7.9 DSL (domain specific language) 语法 (待补充)
基础语法可以在 Kibana 的开发工具中进行练习
Kibana 提供了语法高亮功能和自动补全功能,适合新手开发 (命令行)
然后使用 Elasticsearch-head 插件 查看具体数据 (可视化界面)