kibana展示mysql数据_使用Kibana实现基本的增删改查操作

本文介绍了如何使用Kibana创建、查询、更新和删除MySQL数据对应的Elasticsearch索引及文档。通过Dev Tools,演示了创建索引、添加文档、查询、修改和删除文档的操作过程。
摘要由CSDN通过智能技术生成

es中的索引对应 mysql 的 数据库 、类型对应mysql的表、文档对应mysql的记录、映射对应mysql的索引

索引:index

类型:type

映射:mappings

1、创建索引

在kibana的Dev Tools中输入如下

PUT /lib/

{

"settings":{

"index":{

"number_of_shards":3,

"number_of_replicas":0

}

}

}

索引的名称为lib

number_of_shards:分片的数量为3,分片的数量一旦确定了就不能修改

number_of_replicas: 备份的数量为1,由于就1台 服务器 因此备份数量为0

创建成果后在右边显示如下

{

"acknowledged": true,

"shards_acknowledged": true,

"index": "lib"

}

直接创建一个索引,会使用默认配置

PUT lib2

查看已经创建好的索引的配置

GET /lib/_settings

GET /lib2/_settings

查看所有索引的配置

GET _all/_settings

2、在索引下添加文档

# user 是类型

# 1 是文档的id

PUT /lib/user/1

{

"first_name": "Jane",

"last_name": "Smith",

"age": 32,

"about": "I like to collect rock albums",

"interests": ["music"]

}

右边显示结果如下

{

"_index": "lib",

"_type": "user",

"_id": "1",

"_version": 1,

"result": "created",

"_shards": {

"total": 1,

"successful": 1,

"failed": 0

},

"_seq_no": 0,

"_primary_term": 1

}

如果添加文档时没有指定id,那么这个id会由es自动生成,那么我们要使用POST方式添加文档

POST /lib/user/

{

"first_name": "Douglas",

"last_name": "Fir",

"age": 23,

"about": "I like to build cabinets",

"interests": ["forestry"]

}

结果如下

{

"_index": "lib",

"_type": "user",

"_id": "3z0vM2kBpR5Gle8qjwsu",

"_version": 1,

"result": "created",

"_shards": {

"total": 1,

"successful": 1,

"failed": 0

},

"_seq_no": 0,

"_primary_term": 1

}

3、查询文档

# 根据文档id进行查询

GET /lib/user/1

结果如下

{

"_index": "lib",

"_type": "user",

"_id": "1",

"_version": 1,

"found": true,

"_source": {

"first_name": "Jane",

"last_name": "Smith",

"age": 32,

"about": "I like to collect rock albums",

"interests": [

"music"

]

}

}

GET /lib/user/3z0vM2kBpR5Gle8qjwsu

# 查看文档的部分信息

GET /lib/user/1?_source=age,about

结果如下

{

"_index": "lib",

"_type": "user",

"_id": "1",

"_version": 1,

"found": true,

"_source": {

"about": "I like to collect rock albums",

"age": 32

}

}

4、修改文档

# 使用一个新的文档覆盖之前的文档,会覆盖文档所有字段的值

PUT /lib/user/1

{

"first_name": "Jane",

"last_name": "Smith",

"age": 36,

"about": "I like to collect rock albums",

"interests": ["music"]

}

结果如下,会提示结果为updated

{

"_index": "lib",

"_type": "user",

"_id": "1",

"_version": 2,

"result": "updated",

"_shards": {

"total": 1,

"successful": 1,

"failed": 0

},

"_seq_no": 1,

"_primary_term": 1

}

# 修改文档中的指定字段的值

POST /lib/user/1/_update

{

"doc":{

"age":33

}

}

结果如下

{

"_index": "lib",

"_type": "user",

"_id": "1",

"_version": 3,

"result": "updated",

"_shards": {

"total": 1,

"successful": 1,

"failed": 0

},

"_seq_no": 2,

"_primary_term": 1

}

5、删除文档

DELETE /lib/user/1

结果如下

{

"_index": "lib",

"_type": "user",

"_id": "1",

"_version": 4,

"result": "deleted",

"_shards": {

"total": 1,

"successful": 1,

"failed": 0

},

"_seq_no": 3,

"_primary_term": 1

}

6、删除一个索引

DELETE lib2

结果如下

{

“acknowledged”: true

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值