zoukankan      html  css  js  c++  java
  • 批量增删改"_bulk"

    除了delete以外,每个操作需要两个json字符串,语法如下:
    {"action":{"metadata"}}
    {"data"}
    bulk api对json字符串的语法有严格的要求,每个json串不能换行,只能放在一行,同时json串和json串之间必须有一个换行

    有哪些类型的操作可以执行?
    1、delete:删除一个文档
    2、create:PUT /index/type/id/_ceate,强制创建
    3、index:普通的put操作,可以是创建文档,也可以是全量替换文档
    4、update:partial update操作

    ----------------------------------------------------------------------------------------------------
    1、不同index的操作
    POST /_bulk
    {"delete":{"_index":"test_index1","_type":"test_type","_id":1}}
    {"create":{"_index":"test_index2","_type":"test_type","_id":1}}
    {"test_field":"test field create"}
    {"index":{"_index":"test_index3","_type":"test_type","_id":1}}
    {"test_field":"test field index"}
    {"update":{"_index":"test_index4","_type":"test_type","_id":1,"_retry_on_conflict":3}}
    {"doc":{"test_field":"test field update"}}

    bulk操作中,任意一个操作失败不会影响其他的操作,但是在返回的结果集中,会告诉你异常的日志

    2、相同index,不同type的操作
    {"delete":{"_type":"test_type1","_id":1}}
    {"create":{"_type":"test_type2","_id":1}}
    {"test_field":"test type ceate"}
    {"index":{"_type":"test_type3","_id":1}}
    {"test_field":"test type index"}
    {"update":{"_type":"test_type4","_id":1,"_retry_on_conflict":3}}
    {"doc":{"test_field":"test type update"}}

    3、相同index、type,不同id的操作
    {"delete":{"_id":1}}
    {"ceate":{"_id":2}}
    {"test_field":"test id create"}
    {"index":{"_id":3}}
    {"test_field":"test id index"}
    {"update":{"_id":4,"_retry_on_conflict":3}}
    {"doc":{"test_field":"test id update"}}

    4、bulk size最佳大小
    bulk request内容会加载到内存中,如果太大的话,性能反而会降低,因此需要反复尝试,得到一个最佳的bulk size
    一般从1000条数据开始,逐渐成倍的增加。
    如果看数据文件大小的话,最好是在5到15M之间。

  • 相关阅读:
    1055 The World's Richest (25 分)
    1048 Find Coins (25 分)散列
    经典多线程问题(三)-子线程与主线程的循环打印
    经典多线程问题(二)-生产者消费者问题
    源码分析 CurrentHashMap 1.8
    源码分析 CurrentHashMap 1.7
    源码分析 HashTable与CurrentHashMap1.7与currentHashMap1.8对比
    源码分析 HashMap 1.8
    源码分析 HashMap 1.7
    Linux复习(常用命令)
  • 原文地址:https://www.cnblogs.com/qinjf/p/8506358.html
Copyright © 2011-2022 走看看