文档的操作
一、添加文档
DSL 语法如下:
POST /索引库名/_doc/文档id
{
"字段1":"值1",
"字段2":"值2",
"字段3": {
"子属性1": "值3",
"子属性2": "值4"
}
}
Kibana 测试:
POST /test/_doc/1
{
"info":"我是一名GO和PHP程序猿",
"email":"test123@qq.com",
"name": {
"firstName": "三",
"lastName": "张"
}
}
响应:
{
"_index": "test",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
二、查询文档
DSL 语法如下:
GET /索引库名/_doc/文档id
Kibana 测试:
GET /test/_doc/1
响应:
{
"_index": "test",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"info": "我是一名GO和PHP程序猿",
"email": "test123@qq.com",
"name": {
"firstName": "三",
"lastName": "张"
}
}
}
三、删除文档
DSL 语法如下:
DELETE /索引库名/_doc/文档id
Kibana 测试:
DELETE /test/_doc/1
响应:
{
"_index": "test",
"_id": "1",
"_version": 2,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
四、修改文档
方式1:全量修改,会删除旧文档,添加新文档;文档ID不存在时,则会自动新增文档;
DSL 语法如下:
PUT /索引库名/_doc/文档id
{
"字段1": "值1",
"字段2": "值2"
}
Kibana 测试:
PUT /test/_doc/1
{
"info":"我是GO和PHP程序猿",
"email":"test888@qq.com",
"name": {
"firstName": "四",
"lastName": "张"
}
}
响应:
{
"_index": "test",
"_id": "1",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 1
}
方式2:增量修改,修改指定字段值;
DSL 语法如下:
POST /索引库名/_update/文档id
{
"doc": {
"字段名": "字段值"
}
}
Kibana 测试:
POST /test/_update/1
{
"doc": {
"email": "test999@qq.com"
}
}
响应:
{
"_index": "test",
"_id": "1",
"_version": 3,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 4,
"_primary_term": 1
}
原文地址:https://blog.csdn.net/qq_29627497/article/details/143891461
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!