ElasticSearch学习之路-day10

转载自:https://blog.csdn.net/chengyuqiang/column/info/18392,ES版本号6.3.0

核心概念解读
索引:
索引(index)是ElasticSearch存放具体数据的地方,是一类具有相似特征的文档的集合。ElasticSearch中索引的概念具有不同意思,这里的索引相当于关系数据库中的一个数据库实例。在ElasticSearch中索引还可以作为动词,表示对数据进行索引操作。
类型:
在6.0之前的版本,一个ElasticSearch索引中,可以有多个类型;从6.0版本开始,,一个ElasticSearch索引中,只有1个类型。一个类型是索引的一个逻辑上的分类,通常具有一组相同字段的文档组成。ElasticSearch的类型概念相当于关系数据库的数据表。
文档:
文档是ElasticSearch可被索引的基础逻辑单元,相当于关系数据库中数据表的一行数据。ElasticSearch的文档具有JSON格式,由多个字段组成,字段相当于关系数据库中列的概念。
分片:
当数据量较大时,索引的存储空间需求超出单个节点磁盘容量的限制,或者出现单个节点处理速度较慢。为了解决这些问题,ElasticSearch将索引中的数据进行切分成多个分片(shard),每个分片存储这个索引的一部分数据,分布在不同节点上。当需要查询索引时,ElasticSearch将查询发送到每个相关分片,之后将查询结果合并,这个过程对ElasticSearch应用来说是透明的,用户感知不到分片的存在。 一个索引的分片一定指定,不再修改。
副本:
其实,分片全称是主分片,简称为分片。主分片是相对于副本来说的,副本是对主分片的一个或多个复制版本(或称拷贝),这些复制版本(拷贝)可以称为复制分片,可以直接称之为副本。当主分片丢失时,集群可以将一个副本升级为新的主分片。

创建索引:
(1)简单方式

PUT test

返回

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "test"
}

(2)索引名不能包含大写字母

PUT Test

返回

{
  "error": {
    "root_cause": [
      {
        "type": "invalid_index_name_exception",
        "reason": "Invalid index name [Test], must be lowercase",
        "index_uuid": "_na_",
        "index": "Test"
      }
    ],
    "type": "invalid_index_name_exception",
    "reason": "Invalid index name [Test], must be lowercase",
    "index_uuid": "_na_",
    "index": "Test"
  },
  "status": 400
}

(3)重复创建

PUT test

返回

{
  "error": {
    "root_cause": [
      {
        "type": "resource_already_exists_exception",
        "reason": "index [test/WC6GvUh1RTm1lKWfSURzTA] already exists",
        "index_uuid": "WC6GvUh1RTm1lKWfSURzTA",
        "index": "test"
      }
    ],
    "type": "resource_already_exists_exception",
    "reason": "index [test/WC6GvUh1RTm1lKWfSURzTA] already exists",
    "index_uuid": "WC6GvUh1RTm1lKWfSURzTA",
    "index": "test"
  },
  "status": 400
}

(4)指定参数

PUT blog
{ 
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  } 
}

返回

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "blog"
}

查看索引:
(1)查看指定索引的配置信息

GET blog/_settings

返回

{
  "blog": {
    "settings": {
      "index": {
        "creation_date": "1547090371599",
        "number_of_shards": "3",
        "number_of_replicas": "1",
        "uuid": "xwD2Y5k3TXOyNTJQ2lBitw",
        "version": {
          "created": "6030099"
        },
        "provided_name": "blog"
      }
    }
  }
}

(2)查看多个索引


GET blog,test/_settings

返回
{

  "blog": {
    "settings": {
      "index": {
        "creation_date": "1547090371599",
        "number_of_shards": "3",
        "number_of_replicas": "1",
        "uuid": "xwD2Y5k3TXOyNTJQ2lBitw",
        "version": {
          "created": "6030099"
        },
        "provided_name": "blog"
      }
    }
  },
  "test": {
    "settings": {
      "index": {
        "creation_date": "1547090207687",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "WC6GvUh1RTm1lKWfSURzTA",
        "version": {
          "created": "6030099"
        },
        "provided_name": "test"
      }
    }
  }
}

(3)删除索引

DELETE test

返回

{
  "acknowledged": true
}

索引的打开与关闭
(1)关闭索引

POST blog/_close

返回

{
  "acknowledged": true
}

猜你喜欢

转载自blog.csdn.net/qq_23536449/article/details/91047732