1. 程式人生 > 實用技巧 >kibana中簡單操作es

kibana中簡單操作es

一、查詢和檢視。

#1.查詢所有的資料
GET _search
{
  "query": {
    "match_all":{}
  }
}

#2. 檢視ES叢集的健康狀態
GET _cat/health

# 檢視詳細資訊
GET _cat/health?V

# 檢視ES叢集的節點資訊(master, slave)
GET _cat/nodes

# 檢視ES叢集的節點詳細資訊
GET _cat/nodes?v

# 檢視ES叢集中的index資訊(index相當於資料庫)
GET _cat/indices

# 檢視ES叢集中的index詳細資訊
GET _cat/indices?v


二、建立 index 和 type 操作。

# 建立index
PUT test_index4

#
1. 建立type(兩種形式建立(POST,PUT)) # 這兩種建立形式沒有區別,都會創建出type型別 #2. 使用PUT進行建立type的時候可以自定義格式 #3. 使用POST進行建立type的時候必須要按照ES所提供的格式進行建立 #4. 在ES中可以建立多個index,但是每一個index只能有一個type #5. 使用PUT方式進行建立 # 使用PUT的時候,index是不能存在的(建立形式是先建立index,然後再建立type型別) # 當只是用{的時候會報錯,這是kibana自帶的拼寫檢測(語法規則檢測),一旦檢測到錯誤,直接會丟擲異常,這個異常不影響kibana正常執行! # properties:中就是type所要新增的欄位名 # ES中是所有的資料都是以文件的形式存在(所有的字串型別全部都要使用text表示) # 在ES中有integer型別但是沒有int型別 # 在ES中是以文件的形式存在,這個mapping就可以直接理解為Java中的Map(key, value) # Document:就是xml文件 PUT
/test_index18 { "mappings": { "test_type3" : { "properties" : { "id" : {"type" : "long"}, "username" : {"type" : "text"}, "password" : {"type" : "text"}, "age" : {"type" : "integer"} } } } } # 使用POST形式建立 # 必須要按照ES所提供的規則進行建立,不能自定義規則 # 如果使用的POST的情況下就必須要使用mapping的形式進行建立 # 當使用POST進行建立的type的時候,根據ES的規定所有的type型別全部都是text POST
/test_index8/test_type4 { "properties" : { "id" : {"type" : "long"}, "username" : {"type" : "text"}, "password" : {"type" : "text"}, "age" : {"type" : "integer"} } } 三、查詢type型別 # 查詢所有的type型別(只能根據index進行查詢) # 也就是說type不能直接查詢,必須要指明某一個index下的type型別 GET /test_index18/_mapping/test_type3 四、在type中新增 資料 put 和 post # 向type中新增一條資料 也有兩種形式(PUT和POST) # ES中無論是index,type還是type中的資料ES會自動給這些上索引(唯一識別符號),目的就是為了方便查詢以及提升了查詢速度 #當使用PUT的時候,可以自定義這個索引(這個索引在ES中叫id),但是使用POST的時候只能由ES自動生成一個UUID # 相當於自增主鍵和非自增主鍵的區別 PUT /test_index18/test_type3/10 { "id" : 22, "username" :"zhangsan" , "password" : "666", "age" : 10 } POST /test_index8/test_type4/ { "id" : 220, "username" :"zhangsan02" , "password" : "6669999", "age" : 100 } 五。刪除資料 # 刪除資料(通過id進行刪除) DELETE /test_index18/test_type3/10 六、 檢視type中的資料 # 檢視某一個type中的資料(根據Id進行查詢) GET /test_index18/test_type3/10/_source GET /test_index18/test_type3/10/_source # 不寫id 查不出來 GET /test_index8/test_type4/mbf_SG0B749a8DIzkah3/_source 七、 修改資料 # 修改資料 # 修改資料的時候可以使用PUT和POST,但是規定只能用POST(PUT會造成資料的篡改) # UPDATE關鍵字 POST /test_index18/test_type3/10/_update { "doc" : { "username" : "盧本偉" } } POST /test_index8/test_type4/mbf_SG0B749a8DIzkah3/_update { "doc" : { "username" : "馬飛飛02" } }