ElasticSearch學習筆記---01

阮老師視頻筆記

文檔(Documen)

  • Elasticsearch是面向文檔的,文檔時所有可搜索數據的最小單位
  • 文檔會被序列化成JSON格式,保存在Elasticsearch中
    • JSON 對象由字段組成
    • 每個字段都有對應的字段類型(字符串/數值/布爾/日期/二進制/範圍類型)
  • 每個文檔都有一個Unique ID
    • 可以自定義
    • 或者Elasticsearch自動生成

文檔的元數據

  • _index:文檔所屬的索引名
  • _type:文檔所屬的類型名
  • _id:文檔唯一id
  • _source:文檔的原始Json數據
  • _all:整合所有字段的內容到該字段(已被廢除)
  • _version:文檔的版本信息
  • _score:相關性打分

索引

  • index 索引是文檔的容器,是一類概念的結合
    • index 體現了邏輯空間的概念:每個索引都有自己的Mapping定義,用於包含的文檔字段名和字段類型
    • Shard 體現了物理空間的概念:索引中的數據分散在 Shard上
  • 索引的Mapping與Setting
    • Mapping 定義文檔字段的類型
    • Setting 定義不同的數據分佈

索引的不同語境

  • 名詞:一個Elasticsearch集羣中,可以創建很多不同的索引
  • 動詞:保存一個文檔到Elasticsearch的過程也叫索引(indexing)
    • ES中,創建一個倒排索引的過程
  • 名詞:一個B樹索引,一個倒排索引

抽象與類比

RDBMS Elasticsearch
Table index
Row Doucment
Column Filed
Schema Mapping
SQL DSL

基本API

// 查看索引相關信息
GET kibana_sample_data_ecommerce


// 查看索引的文檔總數
GET kibana_sample_data_ecommerce/_count


// 查看文檔前10條
POST kibana_sample_data_ecommerce/_search
{
  
}

// _cat indices API
// 查看indices
GET /_cat/indices/kibana*?v&s=index

// 查看狀態爲綠的索引
GET /_cat/indices?v&health=green

// 按照文檔個數排序
GET /_cat/indices?v&s=docs.count:desc

// 查看具體的字段
GET /_cat/indices/kibana*?pri&v&h=health,index,pri,rep,docs.count,mt

// 索引所佔用的內存
GET /_cat/indices?v&h=i,tm&s=tm:desc


文檔的CRUD

// ceate document,自動生成_id
POST users/_doc
{
  "user":"Mike",
  "post_date":"2019-04-15T14:12:12",
  "message":"trying out Kibana"
}
返回結果:
{
  "_index" : "users",
  "_type" : "_doc",
  "_id" : "C7tTL3IB7xUCe-bLXYph",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

// create document指定id,如果id已經存在,報錯
POST users/_doc/1?op_type=create
{
  "user":"Jack",
  "post_date":"2019-04-15T14:12:12"
  "message":"trying out Kibana"
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章