Elasticsearch 使用集群 - 创建索引

章节


现在让我们创建一个名为“customer”的索引,然后再次列出所有索引:

API格式:

PUT /customer?pretty
GET /_cat/indices?v

第一个命令使用PUT创建名为“customer”的索引。末尾追加pretty,可以漂亮地打印JSON响应(如果有的话)。

curl命令访问API:

curl -X PUT "localhost:9200/customer?pretty"
curl -X GET "localhost:9200/_cat/indices?v"

响应:

[root@qikegu elasticsearch]# curl -X PUT "localhost:9200/customer?pretty"
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "customer"
}
[root@qikegu elasticsearch]# curl -X GET "localhost:9200/_cat/indices?v"
health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   customer hGMH4nPSQjWhZ-uScEKk5w   1   1          0            0       230b           230b

第二个命令的结果告诉我们,现在有一个名为customer的索引,它有一个主分片和一个副本(默认值),没有包含任何文档。

customer索引上标记了一个黄色健康状态,回想一下前面的讨论,黄色表示还没有分配一些副本。发生这种情况的原因是,默认情况下,Elasticsearch为该索引创建了一个副本,但是目前只有一个节点,要等另一个节点加入集群后,才可以分配该副本(用于高可用性)。一旦将该副本分配到第二个节点,该索引的健康状态将变为绿色。

posted @ 2019-09-05 16:00  吴吃辣  阅读(571)  评论(0编辑  收藏  举报