Elasticsearch 创建索引

简单方式创建index

curl -XPUT ‘http://localhost:9200/twitter/'

在创建索引的时候指定分片和副本数量参数,参数格式采用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
  }
}'

另外的一种create index方式

curl -XPUT 'http://localhost:9200/twitter/tweet/1/_create' -d '{
  "user":"kimchy",
  "post_date":"2009-11-11T14:12:12",
  "message":"hello,world"
}'

以上代码如果不指定id(即1),系统会自动生成id。

curl -XPUT http://localhost:9200/twitter/'
posted @ 2021-01-21 16:02  你的小可爱吖  阅读(384)  评论(0编辑  收藏  举报