ElasticSearch基本概念

ElasticSearch基本概念

Document(文檔)

ES是面向文檔的,文檔是所有可搜索數據的最小單位,一部電影、一首歌、一篇文章都是一個文檔,類比到關係型數據庫,相當於一行數據。

文檔會被序列化成JSON格式,每個JSON格式由字段組成,每個字段有對應的字段類型。

每個文檔都有一個UniqueID。可以自己指定,也可以由ES自己生成

文檔的元數據

文檔的元數據 標註文檔的相關信息。

{
    "_index" : "movies",
    "_type" : "_doc",
    "_id" : "1178",
    "_score" : 1.0,
    "_source" : {
        "id" : "1178",
        "genre" : [
        "Drama",
        "War"
        ],
        "title" : "Paths of Glory",
        "@version" : "1",
        "year" : 1957
    }
}
  • _index:文檔所屬的索引
  • _type:文檔所屬的類型
  • _id 文檔的唯一ID
  • _score 相關性打分
  • _source 原始數據

索引

如果文檔看成關係型數據庫裏的一行數據,那麼索引就相當於關係型數據庫的表,是一類文檔的集合。以下是一個索引結構,他涉及到兩個概念:mappings和settings。mappings對索引庫中索引的字段名稱及其數據類型進行定義,相當於關係型數據庫裏面的schema。settings對分片和副本數進行定義。

# 查看索引相關信息
GET movies
{
  "movies" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "@version" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "genre" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "title" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "year" : {
          "type" : "long"
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1572545279868",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "NY-SRj1TSDCO0CJ5J0I-IQ",
        "version" : {
          "created" : "7040099"
        },
        "provided_name" : "movies"
      }
    }
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章