前言

Elasticsearch作为一个强大的搜索引擎,提供了多种方式来查看和管理数据。本文将详细介绍各种ES数据查看和管理工具,包括Kibana、Elasticsearch Head、curl命令、Postman等,帮助您高效地操作和管理ES数据。

1. 工具概览

1.1 常用工具对比

工具 类型 优点 缺点 推荐度
Kibana 官方可视化平台 功能强大、官方支持 资源占用大 ⭐⭐⭐⭐⭐
Elasticsearch Head 浏览器插件/独立应用 轻量、直观 功能相对简单 ⭐⭐⭐⭐
curl/HTTPie 命令行工具 灵活、脚本化 不够直观 ⭐⭐⭐⭐
Postman API测试工具 易用、可保存请求 需要手动配置 ⭐⭐⭐⭐
Cerebro Web管理工具 轻量、功能全 需要额外部署 ⭐⭐⭐
ElasticHQ Web管理工具 界面美观 更新较慢 ⭐⭐⭐
Dejavu 数据浏览器 类似数据库客户端 功能单一 ⭐⭐⭐

1.2 选择建议

生产环境推荐:

  • Kibana(官方、功能最全)
  • Cerebro(轻量级管理)

开发环境推荐:

  • Kibana Dev Tools
  • Elasticsearch Head
  • Postman

快速查看:

  • curl命令
  • 浏览器插件

2. Kibana(官方推荐)

2.1 安装Kibana

Docker安装(推荐):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 拉取Kibana镜像
docker pull kibana:8.11.0

# 启动Kibana
docker run -d \
--name kibana \
--net elastic \
-p 5601:5601 \
-e "ELASTICSEARCH_HOSTS=http://elasticsearch:9200" \
-e "I18N_LOCALE=zh-CN" \
kibana:8.11.0

# 访问Kibana
# 浏览器打开:http://localhost:5601

传统安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 下载
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.11.0-linux-x86_64.tar.gz

# 解压
tar -xzf kibana-8.11.0-linux-x86_64.tar.gz

# 配置(kibana.yml)
cd kibana-8.11.0
vim config/kibana.yml

# 修改配置
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
i18n.locale: "zh-CN"

# 启动
./bin/kibana

2.2 Kibana Dev Tools(开发者工具)

访问路径:

1
2
Kibana首页 → Management → Dev Tools
或直接访问:http://localhost:5601/app/dev_tools#/console

基本操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 1. 查看集群健康状态
GET /_cluster/health

# 2. 查看所有索引
GET /_cat/indices?v

# 3. 查看索引映射
GET /user_index/_mapping

# 4. 查询所有文档
GET /user_index/_search
{
"query": {
"match_all": {}
}
}

# 5. 条件查询
GET /user_index/_search
{
"query": {
"match": {
"name": "张三"
}
}
}

# 6. 创建文档
POST /user_index/_doc/1
{
"name": "张三",
"age": 25,
"email": "zhangsan@example.com"
}

# 7. 更新文档
POST /user_index/_update/1
{
"doc": {
"age": 26
}
}

# 8. 删除文档
DELETE /user_index/_doc/1

# 9. 批量操作
POST /_bulk
{"index":{"_index":"user_index","_id":"1"}}
{"name":"张三","age":25}
{"index":{"_index":"user_index","_id":"2"}}
{"name":"李四","age":30}

快捷键:

1
2
3
4
Ctrl + Enter:执行当前请求
Ctrl + /:注释/取消注释
Ctrl + I:自动格式化
Ctrl + Space:自动补全

2.3 Kibana Discover(数据探索)

访问路径:

1
Kibana首页 → Analytics → Discover

功能介绍:

  1. 创建索引模式(Index Pattern)

    1
    2
    3
    Management → Stack Management → Index Patterns → Create index pattern
    输入:user_index
    选择时间字段:@timestamp(如果有)
  2. 查看数据

  • 时间范围选择:右上角选择时间范围
  • 搜索栏:使用KQL(Kibana Query Language)或Lucene语法
  • 字段过滤:左侧选择要显示的字段
  • 保存查询:保存常用查询

KQL查询示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 精确匹配
name: "张三"

# 模糊匹配
name: 张*

# 范围查询
age >= 20 and age <= 30

# 组合查询
name: "张三" and age > 25

# 存在性查询
email: *

# 排除查询
not status: "deleted"
  1. 查看文档详情
  • 点击文档左侧的箭头展开
  • 查看JSON格式或表格格式
  • 查看周围文档(上下文)

2.4 Kibana Visualize(数据可视化)

创建可视化图表:

  1. 饼图(Pie Chart)

    1
    2
    3
    4
    5
    用途:展示分类占比
    示例:用户年龄分布
    配置:
    - Metrics: Count
    - Buckets: Terms aggregation on age field
  2. 柱状图(Bar Chart)

    1
    2
    3
    4
    5
    用途:对比不同类别的数据
    示例:每月订单数量
    配置:
    - Y-axis: Count
    - X-axis: Date Histogram on createTime
  3. 折线图(Line Chart)

    1
    2
    3
    4
    5
    用途:展示趋势变化
    示例:用户增长趋势
    配置:
    - Y-axis: Count
    - X-axis: Date Histogram
  4. 数据表(Data Table)

    1
    2
    3
    4
    5
    用途:展示详细数据
    示例:商品销售排行
    配置:
    - Metrics: Sum of sales
    - Buckets: Terms on product_name

2.5 Kibana Dashboard(仪表板)

创建仪表板:

1
2
3
4
5
1. 创建多个可视化图表
2. Dashboard → Create dashboard
3. 添加已创建的可视化图表
4. 调整布局和大小
5. 保存仪表板

仪表板功能:

  • 实时刷新:自动刷新数据
  • 时间过滤:统一的时间范围选择
  • 交互过滤:点击图表进行过滤
  • 导出:导出为PDF或PNG

2.6 Kibana Stack Monitoring(监控)

查看集群状态:

1
2
3
4
5
6
7
8
Management → Stack Monitoring

监控内容:
- 集群健康状态
- 节点状态
- 索引状态
- 查询性能
- 索引性能

3. Elasticsearch Head

3.1 安装方式

方式1:Chrome插件(最简单)

1
2
3
4
1. 打开Chrome应用商店
2. 搜索"Elasticsearch Head"
3. 安装插件
4. 点击插件图标,输入ES地址:http://localhost:9200

方式2:Docker安装

1
2
3
4
5
6
docker run -d \
--name es-head \
-p 9100:9100 \
mobz/elasticsearch-head:5

# 访问:http://localhost:9100

方式3:源码安装

1
2
3
4
5
6
7
8
9
10
11
# 克隆仓库
git clone https://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head

# 安装依赖
npm install

# 启动
npm run start

# 访问:http://localhost:9100

配置ES允许跨域:

1
2
3
# elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"

3.2 主要功能

1. 概览(Overview)

1
2
3
4
- 集群健康状态(绿/黄/红)
- 节点列表
- 索引列表
- 分片分布

2. 索引(Indices)

1
2
3
4
- 查看所有索引
- 索引的文档数量
- 索引大小
- 分片信息

3. 浏览器(Browser)

1
2
3
- 浏览索引数据
- 查看文档详情
- 简单的搜索功能

4. 结构化查询(Structured Query)

1
2
3
- 可视化查询构建器
- 支持基本的查询条件
- 查看查询结果

5. 基本查询(Basic Query)

1
2
3
- 输入JSON格式的查询
- 执行查询
- 查看结果

3.3 使用示例

查看索引数据:

1
2
3
4
1. 点击"数据浏览"标签
2. 选择索引
3. 点击"浏览"按钮
4. 查看文档列表

执行查询:

1
2
3
4
5
6
7
8
9
10
1. 点击"复合查询"标签
2. 输入查询条件
{
"query": {
"match": {
"name": "张三"
}
}
}
3. 点击"搜索"按钮

4. curl命令行工具

4.1 基本语法

1
curl -X<METHOD> "http://localhost:9200/<PATH>" -H 'Content-Type: application/json' -d'<BODY>'

4.2 常用操作

1. 集群和索引管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 查看集群健康
curl -X GET "http://localhost:9200/_cluster/health?pretty"

# 查看所有索引
curl -X GET "http://localhost:9200/_cat/indices?v"

# 查看索引映射
curl -X GET "http://localhost:9200/user_index/_mapping?pretty"

# 查看索引设置
curl -X GET "http://localhost:9200/user_index/_settings?pretty"

# 创建索引
curl -X PUT "http://localhost:9200/user_index" -H 'Content-Type: application/json' -d'
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name": { "type": "text" },
"age": { "type": "integer" }
}
}
}
'

# 删除索引
curl -X DELETE "http://localhost:9200/user_index"

2. 文档操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 创建文档(指定ID)
curl -X PUT "http://localhost:9200/user_index/_doc/1" -H 'Content-Type: application/json' -d'
{
"name": "张三",
"age": 25,
"email": "zhangsan@example.com"
}
'

# 创建文档(自动生成ID)
curl -X POST "http://localhost:9200/user_index/_doc" -H 'Content-Type: application/json' -d'
{
"name": "李四",
"age": 30
}
'

# 查询文档
curl -X GET "http://localhost:9200/user_index/_doc/1?pretty"

# 更新文档
curl -X POST "http://localhost:9200/user_index/_update/1" -H 'Content-Type: application/json' -d'
{
"doc": {
"age": 26
}
}
'

# 删除文档
curl -X DELETE "http://localhost:9200/user_index/_doc/1"

3. 搜索操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 查询所有
curl -X GET "http://localhost:9200/user_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
'

# 条件查询
curl -X GET "http://localhost:9200/user_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match": {
"name": "张三"
}
}
}
'

# 复合查询
curl -X GET "http://localhost:9200/user_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"bool": {
"must": [
{ "match": { "name": "张三" } }
],
"filter": [
{ "range": { "age": { "gte": 20, "lte": 30 } } }
]
}
}
}
'

# 分页查询
curl -X GET "http://localhost:9200/user_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"from": 0,
"size": 10
}
'

# 排序查询
curl -X GET "http://localhost:9200/user_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"sort": [
{ "age": "desc" }
]
}
'

4. 批量操作

1
2
3
4
5
6
7
8
9
10
# 批量索引
curl -X POST "http://localhost:9200/_bulk" -H 'Content-Type: application/json' -d'
{"index":{"_index":"user_index","_id":"1"}}
{"name":"张三","age":25}
{"index":{"_index":"user_index","_id":"2"}}
{"name":"李四","age":30}
{"update":{"_index":"user_index","_id":"1"}}
{"doc":{"age":26}}
{"delete":{"_index":"user_index","_id":"3"}}
'

5. 聚合查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 统计聚合
curl -X GET "http://localhost:9200/user_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"avg_age": {
"avg": { "field": "age" }
},
"max_age": {
"max": { "field": "age" }
}
}
}
'

# 分组聚合
curl -X GET "http://localhost:9200/user_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"group_by_age": {
"terms": {
"field": "age"
}
}
}
}
'

4.3 curl技巧

保存查询到文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 保存查询JSON
cat > query.json << EOF
{
"query": {
"match": {
"name": "张三"
}
}
}
EOF

# 使用文件执行查询
curl -X GET "http://localhost:9200/user_index/_search?pretty" \
-H 'Content-Type: application/json' \
-d @query.json

格式化输出:

1
2
3
4
5
# 使用jq格式化JSON
curl -X GET "http://localhost:9200/user_index/_search" | jq '.'

# 只显示命中的文档
curl -X GET "http://localhost:9200/user_index/_search" | jq '.hits.hits[]._source'

添加认证:

1
2
3
4
5
6
# 基本认证
curl -u elastic:password -X GET "http://localhost:9200/_cluster/health?pretty"

# 或使用-H参数
curl -H "Authorization: Basic ZWxhc3RpYzpwYXNzd29yZA==" \
-X GET "http://localhost:9200/_cluster/health?pretty"

5. HTTPie(更友好的curl)

5.1 安装HTTPie

1
2
3
4
5
6
7
8
# macOS
brew install httpie

# Ubuntu/Debian
sudo apt install httpie

# Python pip
pip install httpie

5.2 基本使用

语法更简洁:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# GET请求
http GET localhost:9200/_cluster/health

# POST请求
http POST localhost:9200/user_index/_doc/1 \
name="张三" \
age:=25 \
email="zhangsan@example.com"

# PUT请求
http PUT localhost:9200/user_index

# DELETE请求
http DELETE localhost:9200/user_index/_doc/1

查询示例:

1
2
3
4
5
6
7
8
9
10
# 查询所有
http POST localhost:9200/user_index/_search \
query:='{"match_all":{}}'

# 条件查询
http POST localhost:9200/user_index/_search \
query:='{"match":{"name":"张三"}}'

# 复合查询
http POST localhost:9200/user_index/_search < query.json

6. Postman

6.1 配置Postman

创建ES环境:

1
2
3
4
5
6
1. 点击右上角的"Environment"
2. 创建新环境"Elasticsearch"
3. 添加变量:
- es_host: http://localhost:9200
- username: elastic
- password: password

配置认证:

1
2
3
1. 在请求的Authorization标签
2. 选择"Basic Auth"
3. 输入用户名和密码

6.2 创建请求集合

集群管理:

1
2
3
GET {{es_host}}/_cluster/health
GET {{es_host}}/_cat/indices?v
GET {{es_host}}/_cat/nodes?v

索引操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 创建索引
PUT {{es_host}}/user_index
Content-Type: application/json

{
"settings": {
"number_of_shards": 3
},
"mappings": {
"properties": {
"name": { "type": "text" },
"age": { "type": "integer" }
}
}
}

# 查看索引
GET {{es_host}}/user_index

# 删除索引
DELETE {{es_host}}/user_index

文档操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 创建文档
PUT {{es_host}}/user_index/_doc/1
Content-Type: application/json

{
"name": "张三",
"age": 25,
"email": "zhangsan@example.com"
}

# 查询文档
GET {{es_host}}/user_index/_doc/1

# 搜索文档
POST {{es_host}}/user_index/_search
Content-Type: application/json

{
"query": {
"match": {
"name": "张三"
}
}
}

6.3 Postman技巧

使用变量:

1
2
3
4
5
6
7
// Pre-request Script
pm.environment.set("timestamp", new Date().toISOString());

// 在请求中使用
{
"createTime": "{{timestamp}}"
}

测试脚本:

1
2
3
4
5
6
7
8
9
// Tests标签
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.test("Response has data", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.hits.total.value).to.be.above(0);
});

导出/导入集合:

1
2
3
4
1. 右键集合 → Export
2. 保存为JSON文件
3. 分享给团队成员
4. Import导入集合

7. Cerebro(轻量级管理工具)

7.1 安装Cerebro

Docker安装:

1
2
3
4
5
6
docker run -d \
--name cerebro \
-p 9000:9000 \
lmenezes/cerebro:latest

# 访问:http://localhost:9000

传统安装:

1
2
3
4
5
6
7
8
9
10
11
# 下载
wget https://github.com/lmenezes/cerebro/releases/download/v0.9.4/cerebro-0.9.4.tgz

# 解压
tar -xzf cerebro-0.9.4.tgz

# 启动
cd cerebro-0.9.4
./bin/cerebro

# 访问:http://localhost:9000

7.2 主要功能

1. 集群概览

1
2
3
4
- 集群健康状态
- 节点信息
- 索引列表
- 分片分布可视化

2. 索引管理

1
2
3
4
5
- 创建/删除索引
- 打开/关闭索引
- 刷新索引
- 清空缓存
- 优化索引

3. 节点管理

1
2
3
- 查看节点详情
- 节点统计信息
- 节点配置

4. REST请求

1
2
- 发送自定义REST请求
- 查看响应结果

5. 快照管理

1
2
3
- 创建快照仓库
- 创建快照
- 恢复快照

8. 其他工具

8.1 ElasticHQ

Docker安装:

1
2
3
4
5
6
docker run -d \
--name elastichq \
-p 5000:5000 \
elastichq/elasticsearch-hq

# 访问:http://localhost:5000

功能特点:

  • 美观的UI界面
  • 集群监控
  • 索引管理
  • 查询工具
  • 节点管理

8.2 Dejavu

Docker安装:

1
2
3
4
5
6
docker run -d \
--name dejavu \
-p 1358:1358 \
appbaseio/dejavu

# 访问:http://localhost:1358

功能特点:

  • 类似数据库客户端的界面
  • 可视化数据浏览
  • 数据编辑
  • 导入/导出数据
  • 实时搜索

8.3 Elasticvue

浏览器插件:

1
2
3
1. Chrome/Firefox应用商店搜索"Elasticvue"
2. 安装插件
3. 点击插件图标连接ES

功能特点:

  • 现代化UI
  • 索引管理
  • 文档浏览和编辑
  • 查询构建器
  • 快照管理

9. 实用脚本

9.1 批量导入数据

Shell脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

# bulk_import.sh
ES_HOST="http://localhost:9200"
INDEX_NAME="user_index"

# 生成测试数据
for i in {1..1000}
do
echo "{\"index\":{\"_index\":\"$INDEX_NAME\",\"_id\":\"$i\"}}"
echo "{\"name\":\"用户$i\",\"age\":$((20 + RANDOM % 40)),\"email\":\"user$i@example.com\"}"
done | curl -s -H "Content-Type: application/x-ndjson" -XPOST "$ES_HOST/_bulk" --data-binary @-

echo "导入完成"

Python脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk

# 连接ES
es = Elasticsearch(['http://localhost:9200'])

# 生成数据
def generate_data(count):
for i in range(1, count + 1):
yield {
"_index": "user_index",
"_id": i,
"_source": {
"name": f"用户{i}",
"age": 20 + (i % 40),
"email": f"user{i}@example.com"
}
}

# 批量导入
success, failed = bulk(es, generate_data(1000))
print(f"成功: {success}, 失败: {failed}")

9.2 数据导出

导出为JSON:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash

ES_HOST="http://localhost:9200"
INDEX_NAME="user_index"
OUTPUT_FILE="export.json"

# 使用scroll API导出所有数据
curl -X POST "$ES_HOST/$INDEX_NAME/_search?scroll=1m" \
-H 'Content-Type: application/json' \
-d '{"size":1000,"query":{"match_all":{}}}' \
| jq '.hits.hits[]._source' > $OUTPUT_FILE

echo "导出完成: $OUTPUT_FILE"

Python导出脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from elasticsearch import Elasticsearch
import json

es = Elasticsearch(['http://localhost:9200'])

# 使用scan helper导出大量数据
from elasticsearch.helpers import scan

query = {"query": {"match_all": {}}}
results = scan(es, index="user_index", query=query)

# 保存到文件
with open('export.json', 'w', encoding='utf-8') as f:
for hit in results:
json.dump(hit['_source'], f, ensure_ascii=False)
f.write('\n')

print("导出完成")

9.3 索引备份和恢复

创建快照:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

ES_HOST="http://localhost:9200"

# 1. 创建快照仓库
curl -X PUT "$ES_HOST/_snapshot/my_backup" -H 'Content-Type: application/json' -d'
{
"type": "fs",
"settings": {
"location": "/mount/backups/my_backup"
}
}
'

# 2. 创建快照
curl -X PUT "$ES_HOST/_snapshot/my_backup/snapshot_$(date +%Y%m%d)" -H 'Content-Type: application/json' -d'
{
"indices": "user_index,product_index",
"ignore_unavailable": true,
"include_global_state": false
}
'

echo "快照创建完成"

恢复快照:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash

ES_HOST="http://localhost:9200"
SNAPSHOT_NAME="snapshot_20251210"

# 恢复快照
curl -X POST "$ES_HOST/_snapshot/my_backup/$SNAPSHOT_NAME/_restore" -H 'Content-Type: application/json' -d'
{
"indices": "user_index,product_index",
"ignore_unavailable": true,
"include_global_state": false
}
'

echo "快照恢复完成"

9.4 监控脚本

集群健康监控:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

ES_HOST="http://localhost:9200"

while true; do
# 获取集群健康状态
health=$(curl -s "$ES_HOST/_cluster/health" | jq -r '.status')

# 获取节点数量
nodes=$(curl -s "$ES_HOST/_cluster/health" | jq '.number_of_nodes')

# 获取索引数量
indices=$(curl -s "$ES_HOST/_cat/indices" | wc -l)

echo "$(date) - 状态: $health, 节点: $nodes, 索引: $indices"

# 如果状态不是green,发送告警
if [ "$health" != "green" ]; then
echo "警告: 集群状态异常!"
# 这里可以添加发送邮件或短信的代码
fi

sleep 60
done

10. 最佳实践

10.1 日常操作建议

1. 使用合适的工具

1
2
3
4
5
开发调试:Kibana Dev Tools
数据浏览:Kibana Discover
可视化:Kibana Dashboard
快速查看:Elasticsearch Head
脚本操作:curl/Python

2. 查询优化

1
2
3
4
- 使用filter代替query(不需要评分时)
- 限制返回字段(_source)
- 合理设置分页大小
- 使用scroll API处理大量数据

3. 安全建议

1
2
3
4
- 启用认证和授权
- 使用HTTPS
- 限制网络访问
- 定期备份数据

10.2 常见问题排查

1. 连接失败

1
2
3
4
5
6
7
8
# 检查ES是否运行
curl http://localhost:9200

# 检查端口是否开放
netstat -an | grep 9200

# 查看ES日志
docker logs elasticsearch

2. 查询慢

1
2
3
4
5
6
7
8
9
# 查看慢查询日志
GET /_cat/indices?v&s=search.query_time_in_millis:desc

# 分析查询
GET /user_index/_search
{
"profile": true,
"query": { "match": { "name": "张三" } }
}

3. 磁盘空间不足

1
2
3
4
5
6
7
8
# 查看磁盘使用
GET /_cat/allocation?v

# 删除旧索引
DELETE /old_index_*

# 清理缓存
POST /_cache/clear

10.3 监控指标

关键指标:

1
2
3
4
5
6
7
8
1. 集群健康状态(green/yellow/red)
2. 节点状态
3. 索引数量和大小
4. 查询响应时间
5. 索引速度
6. CPU和内存使用率
7. 磁盘使用率
8. JVM堆内存使用

监控命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 集群健康
GET /_cluster/health

# 节点统计
GET /_nodes/stats

# 索引统计
GET /_stats

# 线程池状态
GET /_cat/thread_pool?v

# 任务列表
GET /_tasks

11. 总结

11.1 工具选择指南

场景 推荐工具 原因
开发调试 Kibana Dev Tools 功能强大,语法高亮
数据浏览 Kibana Discover 强大的搜索和过滤
可视化分析 Kibana Dashboard 官方支持,功能全面
快速查看 Elasticsearch Head 轻量,直观
脚本操作 curl/Python 自动化,灵活
API测试 Postman 易用,可保存
集群管理 Cerebro 轻量,功能全

11.2 学习路径

  1. 入门阶段

    • 学习curl基本命令
    • 使用Elasticsearch Head浏览数据
    • 了解基本的CRUD操作
  2. 进阶阶段

    • 掌握Kibana Dev Tools
    • 学习复杂查询DSL
    • 使用Kibana Discover探索数据
  3. 高级阶段

    • 创建Kibana可视化和仪表板
    • 编写自动化脚本
    • 集群监控和优化

11.3 推荐资源

官方文档:

工具下载:

社区资源:

参考资源