1.文档的CRUD
- Type名,约定都用_doc
- Create 如果ID已经存在,会失败
- Index 如果ID不存在,创建新的文档,否则,先删除现有的文档,再创建新的文档,版本会增加
- Update 文档必须已经存在,更新只会对相应字段做增量修改
1.1 CREATE 一个文档
支持自动生成文档ID 和 指定文档ID 两种方式
自动生成文档ID
通过调用”post /users/_doc 系统会自动生成document ID
POST users/_doc
{
"user":"Mike",
"post_date":"2019-07-10",
"message":"trying out kibana"
}
运行成功结果
{
"_index" : "users",
"_type" : "_doc",
"_id" : "vJXKIWwBd9mJYCU0J9hg", // 自动生成的文档ID
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 7,
"_primary_term" : 2
}
指定文档ID
使用HTTP PUT user/_create/1创建时,URI中显示指定 _create ,此时如果该id的文档已经存在,操作失败
PUT users/_create/1
{
"firstName":"jack",
"lastName":"Johnson",
"tags":["guiar","skateboard"]
}
第一次运行 运行成功
{
"_index" : "users",
"_type" : "_doc",
"_id" : "3",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 2
}
第二次运行相同的命令 出现错误
{
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[3]: version conflict, document already exists (current version [1])",
"index_uuid": "90f6Tjm4RbiErbHWuSDKEw",
"shard": "0",
"index": "users"
}
],