zoukankan      html  css  js  c++  java
  • ELK学习总结(2-4)bulk 批量操作-实现多个文档的创建、索引、更新和删除

    bulk 批量操作-实现多个文档的创建、索引、更新和删除

    ------------------------------------------------------------------------------ 

    1、命令格式

    {action:{metadata}}

    {request body}

    {action:{metadata}}

    {request body}

    其中,action的值有 createindexupdatedelete

    create:当文档不存在时创建之

    index:创建或替换已有文档

    update:局部更新文档

    delete:删除一个文档

     

    例如:{“delete”:{“_index”:"library","_type":"books","_id":"1"}} 

    ------------------------------------------------------------------------------ 

    2、举例如下

    请求命令:

    POST /library/books/_bulk

    {"index":{"_id":1}}

    {"title":"The Elasticsearch cook book","price":5}

    {"index":{"_id":2}}

    {"title":"Thinking in python","price":25}

    {"index":{"_id":3}}

    {"title":"Thinking in java","price":15}

    执行结果:

    {

        “took”:528,

        “errors”:false,

        "items":

        {

             "index":{

                  "_index":"library",

                  "_type":"book",

                  "_id":"1",

                  "_version":1,

                  "status":201

                  }

              },

             "index":{

                  "_index":"library",

                  "_type":"book",

                  "_id":"2",

                  "_version":1,

                  "status":201

                  }

              },

             "index":{

                  "_index":"library",

                  "_type":"book",

                  "_id":"3",

                  "_version":1,

                  "status":201

                  }

              },

             "index":{

                  "_index":"library",

                  "_type":"book",

                  "_id":"4",

                  "_version":1,

                  "status":201

                  }

              }  

    }

    检查命令:

    GET /library

    GET /library/books/_mget

    {

        "ids":["1","2","3","4","5"]

    ------------------------------------------------------------------------------

    3、还可以delete、update,但delete没有request body

    ------------------------------------------------------------------------------

    4、批量处理文档的大小最佳值

         需要验证得知

         可以借助插件监控的仪表数据判断

  • 相关阅读:
    Git 从入门到入坑
    单件模式(单例模式)
    装饰者模式
    观察者模式
    设计模式入门
    SpringBoot + Mybatis + Redis 整合入门项目
    Spring Boot 前后端交互及参数传递
    Spring Securtiy 认证流程(源码分析)
    Spring Boot 静态页面跳转
    第一条手机验证码
  • 原文地址:https://www.cnblogs.com/lexiaofei/p/6650002.html
Copyright © 2011-2022 走看看