索引创建API允许初始化一个索引。 ElasticSearch对多重索引提供了支持,包括跨多个索引执行操作。每个索引在创建时可以让一个特定的设置项与其关联。
$ curl -XPUT 'http://localhost:9200/twitter/'
$ curl -XPUT 'http://localhost:9200/twitter/' -d '
index :
number_of_shards : 3
number_of_replicas : 2
'
上面第二个curl例子展示了如何创建一个名字叫 twitter 的索引,并且使用 YAML 格式为其指定设置项。在这个例子中,我们为该索引配置了三个切片和两个副本。索引设置项也可以通过 JSON 格式指定:
$ curl -XPUT 'http://localhost:9200/twitter/' -d '{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
}'
或者简化为
$ curl -XPUT 'http://localhost:9200/twitter/' -d '{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}'
请注意,你不需要在 settings 项中显示的指定 index 。
映射
索引创建API可以接收一个或一组映射选项:
curl -XPOST localhost:9200/test -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false },
"properties" : {
"field1" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}'
索引设置
想要关注更多不同的,可以在索引创建时设置的索引级选项,请看 index modules 。