zoukankan      html  css  js  c++  java
  • 【ElasticSearch】批量操作 bulk

    【ElasticSearch】批量操作 bulk

    ======================================================

    1、索引 index

    2、创建 create

    3、index 和 create 区别

    4、更新  update

    5、删除 delete

    ======================================================

    1、索引 index

    创建新文档或替换已用文档

    vim customer_index.json
    { "index" : { "_index" : "customer", "_id" : "1" } }
    { "name" : "Tom" }
    { "index" : { "_index" : "customer", "_id" : "2" } }
    { "name" : "Bob" }
    
    curl -H "Content-Type: application/json" -XPOST "localhost:9200/customer/_bulk?pretty&refresh" --data-binary "@customer_index.json"
    curl "localhost:9200/_cat/indices?v"

    2、创建 create

    文档不存在时创建

    vim customer_create.json
    { "create" : { "_index" : "customer", "_id" : "3" } }
    { "name" : "Alice" }
    { "create" : { "_index" : "customer", "_id" : "4" } }
    { "name" : "Smith" }
    
    curl -H "Content-Type: application/json" -XPOST "localhost:9200/customer/_bulk?pretty&refresh" --data-binary "@customer_create.json"
    curl "localhost:9200/_cat/indices?v"

    3、index 和 create 区别

    如果数据存在,使用create操作失败,会提示文档已存在,使用index则可以成功执行

    {
      "took" : 44,
      "errors" : true,
      "items" : [
        {
          "create" : {
            "_index" : "customer",
            "_type" : "_doc",
            "_id" : "1",
            "status" : 409,
            "error" : {
              "type" : "version_conflict_engine_exception",
              "reason" : "[1]: version conflict, document already exists (current version [1])",
              "index_uuid" : "SaYbL9kjSIKcXY1B73U9Rw",
              "shard" : "0",
              "index" : "customer"
            }
          }
        }
      ]
    }

    4、更新  update

    vim customer_update.json
    { "update" : {"_id" : "1", "_index" : "customer"} }
    { "doc" : {"name" : "Tom Green"} }
    { "update" : {"_id" : "2", "_index" : "customer"} }
    { "doc" : {"name" : "Bob Smith"} }
    
    curl -H "Content-Type: application/json" -XPOST "localhost:9200/customer/_bulk?pretty&refresh" --data-binary "@customer_update.json"
    curl "localhost:9200/_cat/indices?v"

    doc 是关键字保持

    5、删除 delete

    vim customer_delete.json
    { "delete" : { "_index" : "customer", "_id" : "1" } }
    { "delete" : { "_index" : "customer", "_id" : "2" } }
    
    curl -H "Content-Type: application/json" -XPOST "localhost:9200/customer/_bulk?pretty&refresh" --data-binary "@customer_delete.json"
    curl "localhost:9200/_cat/indices?v"
  • 相关阅读:
    SpringMVC与uploadify结合进行上传
    SpringMVC使用MultipartFile文件上传,多文件上传,带参数上传
    file.delete()与file.deleteOnExit(); 的区别
    快速遍历目录下所有文件名
    使用SpringMVC框架解决中文乱码的问题
    SpringCloud微服务基础
    Linux常用命令
    Linux安装软件
    MySQL 树节点递归遍历所以子节点
    微软Office Online服务安装部署(三)
  • 原文地址:https://www.cnblogs.com/yangchongxing/p/13215104.html
Copyright © 2011-2022 走看看