1. Kibana 的版本
- 服務器安裝的ElasticSearch 和Kibana 的版本均爲 6.5.4
2. Kibana 操作命令
2.1 索引的查詢語句(簡單的查詢)
- 查詢 所有索引的所有數據,執行命令:
GET _search
{
"query": {
"match_all": {}
}
}
2.查詢指定索引goods的所有數據,執行命令:
GET /goods/_search
{
"query": {
"match_all": {}
}
}
3.查詢指定索引指定類型指定ID的某些字段的數據,執行命令:
GET /goods/goods/2?_source=name
這個語句相當於 SELECT name FROM goods WHERE ID = 2
GET /goods/goods/2?_source=name,detail
這個語句相當於SELECT NAME,detail FROM goods WHERE ID = 2
4.查詢 某個索引的某個類型的某個id的數據 (以下兩種方式均可)
GET /goods/goods/2
或
GET /goods/goods/2?_source
5.設置查詢返回的索引數據數量
GET /goods/_search
{
"query": {
"match_all": {
}
},
"from": 1,
"size": 2
}
6.按照指定字段name的值模糊查詢相關數據
GET /goods/_search
{
"query": {
"match": {
"name": "Max"
}
}
}
7.查詢內容排序(按照時間倒序排列)
GET /goods/_search
{
"query": {
"match": {
"name": "蘋果Max"
}
},
"sort": [
{
"created_time": {
"order": "asc"
}
}
]
}
8. 獲取所有的設置
GET _settings
9. 查詢索引中的內容
GET goods/_analyze
{
"field": "text",
"text": "蘋果"
}
10. 指定條件過濾查詢
GET /goods/goods/_search
{
"query" : {
"bool": {
"must": {
"match" : {
"name" : "iphone"
}
},
"filter": {
"range" : {
"price" : { "gt" : 5000 }
}
}
}
}
}
2.2 新增數據
- 指定ID插入數據(相當於插入一條記錄到一個數據庫表中)
PUT /goods/goods/5
{
"detail" : "官方授權蘋果 7Plus",
"@version" : "1",
"updated_time" : "2020-02-14T10:40:40.000Z",
"name" : "蘋果 max",
"sub_images" : """{"imgages":[{"http://img.iblimg.com/photo-42/3020/1135120490_200x200.jpg"},{"http://img.iblimg.com/photo-42/3020/1135120490_200x200.jpg"}]}""",
"price" : null,
"stock" : null,
"category_id" : 11,
"main_image" : "http://img.iblimg.com/photo-42/3020/1135120490_200x200.jpg",
"created_time" : "2020-02-14T22:40:40.000Z",
"revision" : 1,
"status" : 0,
"subtitle" : "iPhone 7 Plus",
"created_by" : null,
"attribute_list" : "1,2,3",
"updated_by" : null,
"@timestamp" : "2020-02-14T22:51:00.270Z"
}
- 系統默認ID的插入方式
POST /goods/goods/
{
"detail" : "官方授權iPhone XS",
"@version" : "1",
"updated_time" : "2020-02-14T21:40:40.000Z",
"name" : "蘋果 X",
"sub_images" : """{"imgages":[{"http://img.iblimg.com/0x200.jpg"},{"http://img.iblimg.com/0x200.jpg"}]}""",
"price" : 5288,
"stock" : null,
"category_id" : 11,
"main_image" : "http://img.iblimg.com/00.jpg",
"created_time" : "2020-02-14T21:40:40.000Z",
"revision" : 1,
"status" : 0,
"subtitle" : "iPhone XS",
"created_by" : null,
"attribute_list" : "1,2,3",
"updated_by" : null,
"@timestamp" : "2020-02-14T22:51:00.270Z"
}
2.3 索引的更新操作(相當於SQL的修改操作)
- 覆蓋式修改索引文檔
PUT /goods/goods/5
{
"detail" : "官方授權蘋果 XR",
"@version" : "1",
"updated_time" : "2020-02-14T21:23:40.000Z",
"name" : "蘋果 iPhone XR",
"sub_images" : """{"imgages":[{"http://img.iblimg.com/photo-42/3020/1135120490_200x200.jpg"},{"http://img.iblimg.com/photo-42/3020/1135120490_200x200.jpg"}]}""",
"price" : 5288,
"stock" : null,
"category_id" : 11,
"main_image" : "http://img.iblimg.com/photo-42/3020/1135120490_200x200.jpg",
"created_time" : "2020-02-14T21:40:40.000Z",
"revision" : 1,
"status" : 0,
"subtitle" : "iPhone XR",
"created_by" : null,
"attribute_list" : "1,2,3",
"updated_by" : null,
"@timestamp" : "2020-02-14T22:51:00.270Z"
}
該句相當於SQL的UPDATE goods SET NAME = ?,price= ?,subtitle= ?,detail= ? WHERE ID = 5
- 修改索引文檔的某些字段的值
POST /goods/goods/2/_update
{
"doc":{
"price":6888
}
}
該句相當於SQL的 UPDATE goods SET price= 6888 WHERE ID =2
2.4 索引的刪除操作
刪除操作分爲3種:
- 刪除整個index(庫)
DELETE goods
- 刪除一個type(表)
DELETE goods/goods
- 刪除一條記錄
DELETE /goods/goods/5/
參考: Kibana 用戶手冊
Elasticsearch:權威指南
以及博客:Kibana+ElasticSearch實現索引數據的增刪改查
後續更新…