PUT t_papers?pretty
返回
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "t_papers"
}
创建索引的时候可以通过修改number_of_shards 和number_of_replicas 来修改分片数和副本数,默认的分片数是5,副本数是1
PUT t_score
{
"settings": {
"index":{
"number_of_shards":3,
"number_of_replicas":2
}
}
}
返回
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "t_score"
}
后面可以通过setting修改副本数
PUT t_score/_settings/
{
"number_of_replicas": 3
}
返回
{
"acknowledged" : true
}
对于任何Elasticsearch文档而言,一个文档会包括一个或者多个字段,任何字段都要有自己的数据类型,例如string、integer、date等。Elasticsearch中是通过映射来进行字段和数据类型对应的。在默认的情况下Elasticsearch会自动识别字段的数据类型。同时Elasticsearch提供了mappings参数可以显式地进行映射。
GET _cat/indices?v
返回:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
oring-es-6-2020.06.02 3WLrlHh4TaGFo5weHcOWZQ 1 1 329575 158
green open t_papers Z0uR9NVKTySPBuASGX5-IA 5 1 0 0 2.2kb 1.1kb
表示新建啦一个索引t_papers
主分片是5个,文档数是0 ,健康状态为green
PUT t_papers/kaoyan/1/
{
"title":"first_season",
"info":"for math"
}
返回
{
"_index" : "t_papers",
"_type" : "kaoyan",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
POST t_papers/kaoyan/1/_update
{
"doc":{
"title":"first_season_again",
"info":"for math",
"location":"Pking"
}
}```
返回
```bash
{
"_index" : "t_papers",
"_type" : "kaoyan",
"_id" : "1",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 7,
"_primary_term" : 1
}
GET t_papers/kaoyan/1
返回
{
"_index" : "t_papers",
"_type" : "kaoyan",
"_id" : "1",
"_version" : 8,
"_seq_no" : 7,
"_primary_term" : 1,
"found" : true,
"_source" : {
"title" : "first_season_again",
"info" : "for math",
"location" : "Pking"
}
}
DELETE t_papers/kaoyan/1
{
"_index" : "t_papers",
"_type" : "kaoyan",
"_id" : "1",
"_version" : 9,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 8,
"_primary_term" : 1
}
DELETE t_papers/