1. kibana 概述
- kibana: 针对 ES 的开源分析可视化工具,与存储在 ES 的数据进行交互
- 索引 index:一条相似文档的集合,集合中存有很多条数据(只可以用小写字母,索引没有修改操作)
- 映射 mapping: 决定索引里文档所存储字段以及字段的类型
- 文档 document: 索引中的一条条数据,一条文档是可被索引的最小单元,ES 中文档采用轻量级 Json 格式来表示
ES 是RESTful 风格的系统,所以我们需要先掌握RESTful 的四个关键词:PUT(修改),POST(添加),DELETE(删除),GET(查询)。其中在ES里面PUT和POST的界限并不是很分明,有时候PUT也作为添加。
不设置文档类型时,默认文档类型为_doc
2. kibana 基础操作
2.1 索引的创建查看和删除
查看索引
查看es中的索引:
GET /_cat/indices?v
创建索引
创建索引:
PUT /索引名
PUT /products
// 创建索引并指定索引的分片信息
PUT /products1
{
"settings": {
"number_of_shards": 1 #指定主分片数量
, "number_of_replicas": 1 #指定副本分片数量
}
}
ES中索引健康状态,red(索引不可用), yellow(索引可用,存在风险), green(健康)
删除索引
DELETE /products1
2.2 映射
创建索引的时候,一并创建映射
// 常见类型:
字符串类型:keyword(关键词关键字)、text(一段文本)
数字类型:long、integer、short、byte、double、float、half float、scaled float
小数类型:float double
布尔类型:boolean
日期类型:date
二进制类型:binary
PUT /products
{
"settings": {
"number_of_replicas": 1,
"number_of_shards": 1
},
"mappings": {
"properties": {
"id":{
"type":"integer"
},
"title":{
"type":"keyword"
},
"price":{
"type":"double"
},
"create_at":{
"type":"date"
},
"description":{
"type":"text"
}
}
}
}
查询索引的映射信息
GET /索引名/_mapping
GET /products/_mapping
2.3 文档操作:Json 格式
添加文档
POST /products/_doc/1
{
"id":1,
"title":"薯条",
"price":"10.5",
"create_at":"2022-3-12",
"description":"薯条真好吃啊"
}
POST /products/_doc/
{
"title":"辣条",
"price":"9.5",
"create_at":"2022-3-12",
"description":"辣条真好吃啊"
}
查询文档
手动指定文档id查询:
GET /products/_doc/1
GET /products/_doc/JxDXeX8BOmAdT3sErqxz
删除文档
DELETE /products/_doc/
DELETE /products/_doc/JxDXeX8BOmAdT3sErqxz
更新文档
// 原文档删除,重新创建
PUT /products/_doc/1
{
"title":"薯条子"
}
// 指定文档字段更新,不重新创建新的文档
POST /products/_doc/1/_update
{
"doc":{
"price":"5.8",
"title":"薯条"
}
}