栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

ES之文档修改及删除(入门)

ES之文档修改及删除(入门)

ES之文档修改及删除(入门)

一、全量覆盖
原id为1001的数据内容为:

{
    "_index": "test-index-3",
    "_type": "_doc",
    "_id": "1001",
    "_version": 3,
    "_seq_no": 5,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "title": "test",
        "num": 1,
        "date": "20211213"
    }
}

发送【POST】或【PUT】请求:http://127.0.0.1:9200/test-index-3/_doc/1001,参数如下

{
    "test":"abc"
}

执行后返回结果为

{
    "_index": "test-index-3",
    "_type": "_doc",
    "_id": "1001",
    "_version": 4,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 13,
    "_primary_term": 1
}

修改后查询结果为

{
    "_index": "test-index-3",
    "_type": "_doc",
    "_id": "1001",
    "_version": 4,
    "_seq_no": 13,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "test": "abc"
    }
}

二、修改某个字段
原id为1002的数据内容为:

{
    "_index": "test-index-3",
    "_type": "_doc",
    "_id": "1002",
    "_version": 2,
    "_seq_no": 7,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "title": "test",
        "num": 1,
        "date": "20211213"
    }
}

发送【POST】请求:http://127.0.0.1:9200/test-index-3/_update/1002,参数如下(不能用PUT协议,如果参数中有新字段,则会新增字段)

{
    "doc" : {
        "title" : "测试",
        "file": 666
    }
}

执行后返回结果为

{
    "_index": "test-index-3",
    "_type": "_doc",
    "_id": "1002",
    "_version": 3,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 15,
    "_primary_term": 1
}

修改后查询结果为

{
    "_index": "test-index-3",
    "_type": "_doc",
    "_id": "1002",
    "_version": 3,
    "_seq_no": 15,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "title": "测试",
        "num": 1,
        "date": "20211213",
        "file": 666
    }
}

三、删除数据
发送【DELETE】请求:http://127.0.0.1:9200/test-index-3/_doc/1001
结果返回如下

{
    "_index": "test-index-3",
    "_type": "_doc",
    "_id": "1001",
    "_version": 6,
    "result": "deleted",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 18,
    "_primary_term": 1
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/663506.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号