创建指定名称的index
。
命令样例如下:
curl -X PUT "https://localhost:9200/testindex_002?pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 2
}
}
}
' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
或者
curl -X PUT "https://localhost:9200/testindex_002?pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2
}
}
' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "testindex_002"
}
index
的名称
有如下规范:
- 只允许使用小写字母。
- 不允许使用特殊字符,如下:
\
/
*
?
"
<
>
|
- 空格
,
#
- 仅在7.0之前的版本,允许使用
:
。
- 不允许使用如下字符作为开头:
-
_
+
- 不允许使用
.
和..
。 - 名称的长度小于255个字节,注意不是字符。
- 使用
.
作为开头的index
,仅供ElasticSearch
内部使用。
方法参数
wait_for_active_shards
,默认值为1
,即主分片。
可能取值为all
或者大于0
小于number_of_replicas+1
的正整数,表示等待收到响应的分片的数量。
命令样例如下:
curl -X PUT "https://localhost:9200/testindex_003?pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"index.number_of_shards": 3,
"index.number_of_replicas": 2,
"index.write.wait_for_active_shards": "2"
}
}
' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
或者
curl -X PUT "https://localhost:9200/testindex_003?wait_for_active_shards=2&pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"index.number_of_shards": 3,
"index.number_of_replicas": 2
}
}
' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{
"acknowledged" : true,
"shards_acknowledged" : false,
"index" : "testindex_003"
}
方法的请求消息体
在创建index
时,允许指定:
index
的工作参数。index
的字段的映射及参数。index
的别名。
方法的响应消息体
acknowledged
在超时前,创建请求的结果。
true
,创建成功。false
,在超时前,未能完成创建,但创建操作并未停止。
shards_acknowledged
在超时前,创建请求的结果。
true
,各分片均返回创建成功。false
,在超时前,未能完成创建,但创建操作并未停止。
相关资料
- ElasticSearch Create index APIelasticsearch create index api elasticsearch index api get elasticsearch index open api elasticsearch settings index api elasticsearch index stats api elasticsearch clone index api elasticsearch close index api elasticsearch delete index api elasticsearch modules index 索引postgis create index