windows 安装 Elasticsearch
一.官网下载安装包Elasticsearch高版本内置jdk,无需使用系统安装的java,无需修改配置文件
1. 下载安装包
https://www.elastic.co/cn/downloads/elasticsearch
https://i-blog.csdnimg.cn/direct/8cf7165cd00046399737b0c77b617403.png
2.下载后解压
双击 elasticsearch.bat 启动 elasticsearch 服务
注:第一次启动时, 要注意此时的 ip 地点(注意下本身的虚拟机或者vpn, 它们的ip可能会产生干扰), 该 ip 地点会被绑定到 enrollment token 中, 在安装 Kibana 时有用
https://i-blog.csdnimg.cn/direct/83d95f1a39d54e75ae4a22a714cb110d.png
启动后第一次会显示一些配置信息,包罗默认的用户暗码
https://i-blog.csdnimg.cn/direct/d0c8f68421604c379c7e042fa2edbbbf.png
第一次启动会打印一下内容, 要好好纪录下来
Elasticsearch security features have been automatically configured!
Authentication is enabled and cluster connections are encrypted.
Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
51U=XE=htaUnwvw7pCi_
HTTP CA certificate SHA-256 fingerprint:
1f43e6cdbe51241f0722124ce48490933ecdef34d6fd0b658003fc2d2b635385
Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC41MC4xNTc6OTIwMCJdLCJmZ3IiOiIxZjQzZTZjZGJlNTEyNDFmMDcyMjEyNGNlNDg0OTA5MzNlY2RlZjM0ZDZmZDBiNjU4MDAzZmMyZDJiNjM1Mzg1Iiwia2V5IjoieEY3UHJKVUJNUXRiSWswTzdRMXU6QWRsb1FPeFVSRldQcWs0S3BtX1IzUSJ9
Configure other nodes to join this cluster:
• On this node:
⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
⁃ Restart Elasticsearch.
• On other nodes:
⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.
3.验证安装效果
在浏览器中输入如下链接和用户名暗码
https://localhost:9200/
https://i-blog.csdnimg.cn/direct/9b83692cf2254fe7802513b49c8d9ae8.png
4.将 elasticsearch 以服务的方式安装
4.1 添加系统情况变量 Elasticsearch_Server
https://i-blog.csdnimg.cn/direct/b7cf6861d582478ebf15fc9a487502c6.png
4.2 在系统情况变量 Path 中添加如下路径
%Elasticsearch_Server%\bin
https://i-blog.csdnimg.cn/direct/ed3335625f5b4ceab7547f88ec507899.png
4.3 安装 Elasticsearch 服务
cmd中执行
elasticsearch-service.bat install
https://i-blog.csdnimg.cn/direct/f7223db1c63b47ada28a139fec6ef0a2.png
4.4 服务操作命令
启动Elasticsearch服务:
elasticsearch-service.bat start
停止Elasticsearch服务:
elasticsearch-service.bat stop
安装Elasticsearch服务:
elasticsearch-service.bat install
卸载Elasticsearch服务:
elasticsearch-service.bat remove
启动 Elasticsearch 属性gui:
elasticsearch-service.bat manager
4.5 可能碰到的题目
4.5.1 假如报 org.elasticsearch.ElasticsearchException: not all primary shards of [.geoip_databases] index are active
是因为 es 启动时会去更新舆图的一些数据库, 则在 elasticsearch-8.3.3/config/elasticsearch.yml 总添加配置禁止下载:
ingest.geoip.downloader.enabled: false
4.5.2 在将服务启动或者注册为windows服务启动后, 莫名其妙的报了如下错误:
org.elasticsearch.bootstrap.StartupException: org.elasticsearch.bootstrap.BootstrapException: java.nio.file.NoSuchFileException: D:\Procedure\apache-jmeter-5.5\lib\ext\ApacheJMeter_core.jar
出现这种题目, 可能是因为情况变量中设置过 JMeter 的东西, 假如辩论了, 重新修改下 CLASSPATH 中的配置
安装 kibana
1.下载与Elasticsearch 雷同版本的 kibana
https://www.elastic.co/cn/downloads/past-releases#kibana
2.启动 Kibana服务
bin目录下双击执行 kibana.bat 文件, 启动 kibana
https://i-blog.csdnimg.cn/direct/c7ad534a8d3744e39901ca586272ddc4.png
浏览器访问该地点, 出现如下界面
https://i-blog.csdnimg.cn/direct/81a1c7b5b1474e91acbae84125531625.png
将上文所说, 生存下来的 enrollment token 输入到方框中
https://i-blog.csdnimg.cn/direct/e12b421559ba4aebb5e339110a873380.png
点击 Configure Elastic
3.输入用户暗码
https://i-blog.csdnimg.cn/direct/6e2990bcc5ca43a9bbf165f4fc5e7902.png
https://i-blog.csdnimg.cn/direct/50326241e22343f99c8d8f41b8573fc4.png
4.中文版界面
修改 config\kibana.yml 文件
将 i18n.locale: “en”, 改为 i18n.locale: “zh-CN”
https://i-blog.csdnimg.cn/direct/76b8a15d49294f2d847aa1bddbdf7874.png
Elasticsearch使用Kibana举行基础操作
一、Restful接口
Elasticsearch通过RESTful接口提供与其举行交互的方式。在ES中,提供了功能丰富的RESTful API的操作,包罗CRUD、创建索引、删除索引等操作。你可以用你最喜爱的 web 客户端访问 Elasticsearch 。究竟上,你甚至可以使用 curl 命令来和 Elasticsearch 交互。
Elasticserch为大部门编程语言(诸如java/javascript/go/ruby等等)提供了官方客户端。全部这些可以在Elasticsearch Clients找到。
二、使用Kibana可视化操作
Kibana是一个用于数据可视化和分析的开源工具。它是Elasticsearch的一个组件,用于在Elasticsearch索引中搜索、分析和互动式地可视化数据。Kibana提供了丰富的图表和图形,可以资助用户更好地理解和分析数据,从而支持数据驱动的决议和洞察力的发现。
启动之后,浏览器输入: http://localhost:5601/ ,进入开发者工具控制台
https://i-blog.csdnimg.cn/direct/0a34b5b2130743a38094ddac48320cb0.png
官方学习教程传送门–> elasticsearch入门教程
三、索引操作
3.1创建索引
PUT /employee?pretty
3.2查询全部索引
https://i-blog.csdnimg.cn/direct/dd348d6d208e44ba93bdf81c0d1965d0.png
其中,employee是我们本身创建的索引,插入了0条数据。
3.3删除索引
https://i-blog.csdnimg.cn/direct/7404d18ea3454f3aa486c4056259a2b0.png
四、文档操作
4.1插入新文档
PUT /index_name/_doc/document_id
{
"field1": "value1",
"field2": "value2",
...
}
其中:index_name代表索引名字,document_id代表文档的id。假如不指定,ES则主动创建一个。假如id已存在,则旧的数据被覆盖。
https://i-blog.csdnimg.cn/direct/37a17413f5e84688875a74652dda9c09.png
4.2更新文档
POST /employee/doc/1
{
"name": "Lily"
}
以上命令将索引为employee,id为1的文档,name属性举行更新。
https://i-blog.csdnimg.cn/direct/6f533a0e5d6a4b3e8fbe4ce9ce236193.png
4.3删除文档
https://i-blog.csdnimg.cn/direct/5a97a160cfac40b895f378c3aad34d0e.png
4.4查询全部文档
GET /索引名/_search
{"query": {
"match_all": {}
}
}
https://i-blog.csdnimg.cn/direct/f84428acd141484da709a7723888dcf6.png
4.5查询指定字段
https://i-blog.csdnimg.cn/direct/b2a69c96ba2e4b52a81204634ad8a395.png
五、query语法
5.1查询语句的根本语法结构
GET /索引名/_search
{
"query": {
"查询类型": {
"字段名": "查询条件"
}
}
}
GET:请求的范例,表现发送一个GET请求。
/索引名/_search:指定要查询的索引和范例。
“query”:查询的关键字,表现要举行查询操作。
“查询范例”:查询的范例,如match、term、range等。
“字段名”:要查询的字段名。
“查询条件”:详细的查询条件。
5.2match和term的区别
[*]Match查询:Match是一种全文搜索查询,它会将查询字符串分词,并将分词后的项与文档中的词项举行匹配。它会根据查询字符串的分词效果来搜索包罗恣意匹配项的文档。Match查询使用的是全文搜索的相关性算法,会给每个匹配的文档一个相关性得分。适合用text
范例的字段。
[*]Term查询:Term是一种精确匹配查询,它会将查询字符串作为一个整体与文档中的词项举行精确匹配。Term查询不举行分词,而是将查询字符串作为一个单独的术语举行搜索,不适合用于text范例的字段(官网原话Avoid
using the term query for text fields)
// 指定字段类型创建索引
PUT my-index-001
{
"mappings": {
"properties": {
"full_text": { "type": "text" }
}
}
}
//存值
PUT my-index-001/_doc/1
{
"full_text": "Hello Elastic!"
}
新建一个索引,包罗一个名为“full_text”的text字段。ES会将text字段拆分为[“Hello”,“Elastic”]。使用term搜索,效果为空。(term为精确匹配,而text字段已被拆分,所以匹配不到)
https://i-blog.csdnimg.cn/direct/b748716eda8e4f9b88c30eab1813abd6.png
使用match匹配,则可以查询得到(因为match属于模糊查询,查询前也会举行拆词)
https://i-blog.csdnimg.cn/direct/cb00e678849e47158d1cd1c01e642166.png
新建一个索引,包罗一个名为“full_text”的keyword字段。使用term查询,得到效果。ES不会对keyword范例的字段举行拆词。https://i-blog.csdnimg.cn/direct/1f9d82bb15c7490eaf883b6cce3a9ce9.png
5.3范围查询
GET /<index_name>/_search
{
"query": {
"range": {
"<field_name>": {
"gte": "<lower_limit>",
"lte": "<upper_limit>"
}
}
}
}
其中范围量词有:
gte:大于等于 ;
gt:大于 ;
lte:小于等于;
lt:小于
示例代码:
https://i-blog.csdnimg.cn/direct/3a40d86ed11c4bbab9149ae00cb835e0.png
WEB可视化工具
找可视化工具,发现支持8.x 的很难找到,这里推荐一个简单好用的ElasticSearch可视化客户端,支持毗连6,7,8版本的ES
ElasticView 是一款用来监控ElasticSearch状态和操作ElasticSearch索引的web可视化工具。它由golang开发而成,具有摆设方便,占用内存小等优点,官网地点:http://www.elastic-view.cn
[*] ElasticSearch毗连树管理(更方便的切换测试/生产情况)
[*] 支持权限管理
[*] 支持sql转换成dsl语法
[*] 更方便的重建索引
[*] 任务管理
[*] 备份管理
[*] 可将查询内容下载为excel文件
[*] 可举行索引创建,映射创建,别名创建,索引删除等操作
[*] 支持版本 6.x,7.x,8.x
[*] 支持雷同Navicat功能
[*] docker摆设
[*] 支持sqlite3(免安装gcc版)
[*] 数据抽取功能
安装步骤
https://i-blog.csdnimg.cn/direct/2973a430903b45dcab054739685a3d54.png
https://i-blog.csdnimg.cn/direct/4e4fe2184e1e45b5a260dcac06970738.png
添加es的配置链接详细
https://i-blog.csdnimg.cn/direct/b48cf3f9a9ed4f42bc20c196b923f436.png
选择对应版本和鉴权信息
https://i-blog.csdnimg.cn/direct/51c25964a4a94ed1ab6d9d982c45807f.png
安装插件
https://i-blog.csdnimg.cn/direct/898119a33b1540b0be4d3a8e88a4ca59.png
选择对应的数据源举行操作
https://i-blog.csdnimg.cn/direct/c27c7b528790475aa2c2387ea5f27bc5.png
分词器安装
点击下载对应的es版本
https://i-blog.csdnimg.cn/direct/96f1e92ff5f54f308c20470a3c187b15.png
下载完后,解压安装包到 ElasticSearch 所在文件夹中的plugins目录中:
https://i-blog.csdnimg.cn/direct/5caf9227589847d8bc7a494869489130.png
再启动ElasticSearch,检察IK分词器插件是否安装成功
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]