Stories

Detail Return Return

ES實戰第二版筆記-2 - Stories Detail

第三章 架構

  • ISO8601日期: yyyy-MM-dd

    3.1 索引(index)/別名(alias)

    3.1 數據流(時間序列數據)

  • 1.多個索引保存數據
  • 2.作為單個資源訪問
  • 3.索引es自動生成,且是隱藏的
  • 4.數據流=滾動隱藏索引的一個別名
  • 5.使用索引模版創建

    3.2 分片和副本

    _cat/health

  • 1.分片和副本分佈在不同節點
  • 2.索引創建後分片數無法修改

    路由算法: 分片編號=hash(文檔ID)%主分片數

3.3 節點和集羣

  • 節點角色: node.roles: [master,data,ingest,ml]

3.4 倒排索引

3.5 相關性

3.5.1 相關性算法

  • BM25

    (Best Match 25)最佳匹配25相關性算法
  • TF-IDF

    (term frequency/inverse document frequency)(詞頻/逆文檔頻率)相關性算法

    3.6 路由算法

    路由算法: 分片編號=hash(文檔ID)%主分片數
    所以, 一旦創建, 主分片數不允許修改

3.7 date的形式:

識別多個格式的date字符串為date類型:
"create_at": {
    "type": "date",
    "format": "yyyy-MM-dd||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd HH:mm:ss"
}

舉例:


PUT test_01
{
  "settings": {
    "number_of_replicas": 0,
    "number_of_shards": 1,
    "refresh_interval": "1s"
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "create_at": {
        "type": "date",
        "format": "yyyy-MM-dd||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd HH:mm:ss"
      },
      "count": {
        "type": "integer"
      }
    }
  }
}

PUT test_01/_doc/1
{
  "name": "name1",
  "create_at": "2025-10-10",
  "count": 1
}

POST _bulk
{"index":{"_index":"test_01","_id":2}}
{"name":"name2","create_at":"2025-10-20T20:20:49","count":2}
{"index":{"_index":"test_01","_id":3}}
{"name":"name3","create_at":"2025-10-08 10:22:11","count":3}
{"index":{"_index":"test_01","_id":4}}
{"name":"name4","create_at":"2025-08-10 10:10:20","count":4}
{"index":{"_index":"test_01","_id":5}}
{"name":"name5","create_at":"2025-10-01","count":1}

GET test_01/_search
{
  "query": {
    "range": {
      "create_at": {
        "lte": "2025-10-08 10:22:11"
      }
    }
  }
}
user avatar sysin Avatar
Favorites 1 users favorite the story!
Favorites

Add a new Comments

Some HTML is okay.