ElasticSearch在Windows单节点部署及使用_windows部署es
文章目录
- 初始化ES服务
-
- 下载启动
- 验证
- Kibana可视化使用ES
-
- 下载启动
- 验证使用
- 创建第一个索引
- 添加文档
- 查询文档
- ES优点
初始化ES服务
下载启动
访问官网https://www.elastic.co/downloads/elasticsearch
点击Windows,开始下载elasticsearch-8.17.4-windows-x86_64.zip文件,文件大小456MB
下载完成后解压到D盘Config目录
编辑 config/elasticsearch.yml
cluster.name: my-windows-clusternode.name: windows-node-1network.host: 0.0.0.0http.port: 9200discovery.type: single-node # 关键!单节点模式xpack.security.enabled: false # 开发环境可关闭安全认证
启动 Elasticsearch,进入到解压目录直接执行elasticsearch
# 进入解压目录cd C:\\elasticsearch-8.12.0# 启动(前台运行,查看日志).\\bin\\elasticsearch.bat# 或作为服务安装(管理员权限).\\bin\\elasticsearch-service.bat install.\\bin\\elasticsearch-service.bat start
我这里启动有个报错
解决方法:删除CLASSPATH环境变量,值为D:\\Program Files\\PostgreSQL\\postgresql-9.3-1103.jdbc4.jar即可
重新启动,starting代表启动成功了
验证
打开浏览器访问:http://localhost:9200
应看到类似响应:
{ \"name\" : \"windows-node-1\", \"cluster_name\" : \"my-windows-cluster\", \"version\" : { \"number\" : \"8.12.0\", \"build_flavor\" : \"default\", \"build_type\" : \"zip\", \"lucene_version\" : \"9.8.0\" }}
健康状态检查:浏览器访问http://localhost:9200/_cluster/health?pretty
看到 “status” : “green” 表示节点健康
作为系统服务运行
# 安装服务(管理员权限).\\bin\\elasticsearch-service.bat install# 启动服务.\\bin\\elasticsearch-service.bat start# 其他命令.\\bin\\elasticsearch-service.bat stop # 停止.\\bin\\elasticsearch-service.bat remove # 卸载
Windows下ES服务仅供开发学习使用,实际生产中还是使用Linux下部署启动ES
Kibana可视化使用ES
下载启动
下载可视化工具 https://www.elastic.co/downloads/kibana
kibana-8.17.4-windows-x86_64.zip 文件大小518MB,解压到目录
修改 config/kibana.yml
server.port: 5601server.host: \"localhost\"elasticsearch.hosts: [\"http://localhost:9200\"]
进入bin目录执行kibana.bat启动
验证使用
启动成功后,浏览器访问 http://localhost:5601
我这里选择了Explore on my own,随便选哪个都行
在 Kibana 左侧菜单 → Management → Dev Tools
打开新的 Dev Tools窗口
说明:索引(Index) ≈ 数据库,文档(Document) ≈ 表中的行,映射(Mapping) ≈ 表结构定义
创建第一个索引
PUT /my_first_index{ \"settings\": { \"number_of_shards\": 1, \"number_of_replicas\": 0 }, \"mappings\": { \"properties\": { \"title\": { \"type\": \"text\" }, \"description\": { \"type\": \"text\" }, \"price\": { \"type\": \"float\" }, \"created_at\": { \"type\": \"date\" } } }}
添加文档
POST /my_first_index/_doc/1{ \"title\": \"Elasticsearch入门指南\", \"description\": \"一本关于ES的入门教程\", \"price\": 39.9, \"created_at\": \"2023-05-01\"}
查询文档
GET /my_first_index/_search{ \"query\": { \"match\": { \"title\": \"入门\" } }}
ES优点
● 分布式水平扩展可处理PB级数据
● 快速响应搜索结果
● RESTful API的Http接口
● 多语言支持:java,python等
● 基于Lucene提供的全文检索能力
● 通过插件连接Postgresql等关系型数据库
● Logstash日志分析解决方案、Kibana数据可视化