虚拟化容器,大数据,DBA,中间件,监控。

Elasticsearch 7 : 通过 _bulk 批量添加文档

07 04月
作者:admin|分类:大数据

Elasticsearch 7 : 通过 _bulk 批量添加文档


创建索引:

PUT student{
  "mappings" : {
    "properties" : {
      "name" : {
        "type" : "keyword"
      },
      "age" : {
        "type" : "integer"
      }
    }
  }}


2,添加文档时,不可使用工具如postman等美化,不然会无法正常执行。

使用 _bulk 创建文档

POST _bulk
{ "index" : { "_index" : "student", "_id" : "1" } }
{ "name" : "张三" }
{ "index" : { "_index" : "student", "_id" : "2" } }
{ "name" : "李四", "age": 10 }
{ "index" : { "_index" : "student", "_id" : "3" } }
{ "name" : "王五", "age": 11 }

响应:

{
  "took" : 21,
  "errors" : false,
  "items" : [
    {
      "index" : {
        "_index" : "student",
        "_type" : "_doc",
        "_id" : "1",
        "_version" : 1,
        "result" : "created",
        "_shards" : {
          "total" : 2,
          "successful" : 1,
          "failed" : 0
        },
        "_seq_no" : 0,
        "_primary_term" : 1,
        "status" : 201
      }
    },
    {
      "index" : {
        "_index" : "student",
        "_type" : "_doc",
        "_id" : "2",
        "_version" : 1,
        "result" : "created",
        "_shards" : {
          "total" : 2,
          "successful" : 1,
          "failed" : 0
        },
        "_seq_no" : 1,
        "_primary_term" : 1,
        "status" : 201
      }
    },
    {
      "index" : {
        "_index" : "student",
        "_type" : "_doc",
        "_id" : "3",
        "_version" : 1,
        "result" : "created",
        "_shards" : {
          "total" : 2,
          "successful" : 1,
          "failed" : 0
        },
        "_seq_no" : 2,
        "_primary_term" : 1,
        "status" : 201
      }
    }
  ]}

_bulk也支持 delete、update 等操作。具体可参考官方文档:Bulk API 。


浏览661 评论0
返回
目录
返回
首页
Oracle 关于 not in 的坑 ,not in 查询不出数据 ElasticSearch学习笔记 | PUT、POST增加文档和GET搜索文档