除了对单个文档执行创建、更新和删除之外,Elasticsearch还提供了使用_bulk API批量执行上述操作的能力。

下面的调用,在一个批量操作中,创建两个文档(ID 1 - John Doe和ID 2 - Jane Doe):

API

POST /customer/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }

CURL

curl -X POST "localhost:9200/customer/_bulk?pretty" -H 'Content-Type: application/json' -d'
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
'

下面的例子,在一个批量操作中,先更新第一个文档(ID为1),再删除第二个文档(ID为2):

API

POST /customer/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}

CURL

curl -X POST "localhost:9200/customer/_bulk?pretty" -H 'Content-Type: application/json' -d'
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
'

注意,对于delete操作,只需提供被删除文档的ID即可。

某个操作失败不会导致批量API执行中断,剩下的操作将继续执行。当_bulk API返回时,它将为每个操作提供一个状态(与发送操作的顺序相同),以便检查某个特定操作是否失败。

Elasticsearch 批处理的更多相关文章

  1. Elasticsearch批处理操作——bulk API

    Elasticsearch提供的批量处理功能,是通过使用_bulk API实现的.这个功能之所以重要,在于它提供了非常高效的机制来尽可能快的完成多个操作,与此同时使用尽可能少的网络往返. 1.批量索引 ...

  2. Elasticsearch 过滤

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  3. Elasticsearch Query DSL(查询语言)

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  4. Elasticsearch 搜索API

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  5. Elasticsearch 搜索数据

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  6. Elasticsearch 删除文档

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  7. Elasticsearch 更新文档

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  8. Elasticsearch 修改数据

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  9. Elasticsearch 使用集群 - 删除索引

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

随机推荐

  1. Python字符串(二)

    四.类型转换 1. 基本语法: 类型名(数据) --- 将指定数据转换成指定类型 说明:类型名 -任何python支持的,或者自定的类型都可以数据 -需要转换的对象,类型不同要求可能不一样 2. 转换 ...

  2. day10-Python运维开发基础(函数嵌套、nonlocal声明局部变量、闭包、locals/globals、lambda表达式)

    1. 函数的嵌套与nonlocal 声明局部变量 # ### 函数的嵌套 """ 函数和函数之间可以互相嵌套: 嵌套在内层的叫做内函数 乔涛在外层的叫做外函数 " ...

  3. 二、Navicat、IDEA、nopad、eclipse、excle工具使用、问题、快捷键

    1.Navicat工具: 目的:本地数据库与远程数据库之间数据导入导出 步骤1:文件--新建oracle链接/mysql的连接 步骤2:工具-选项:将本地oracle的bin\oci.dll 的路径复 ...

  4. C# 自定义控件容器,设计时可添加控件

    本分步指南介绍在将 UserControl 放在 Windows 窗体上之后,如何将 UserControl 对象用作设计时控件容器.可能会有这样的情况:您想将一个控件拖到 UserControl 中 ...

  5. POJ 3267:The Cow Lexicon 字符串匹配dp

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8905   Accepted: 4228 D ...

  6. redheat7 sd 0:0:0:0: [sda] Assuming drive cache: write through(未解决)

    以下是我上网查找的解决办法 1. sd 0:0:0:0: [sda] Assuming drive cache: write through 解决方法:/etc/default/grub 文件里去掉  ...

  7. C中的文件操作函数[笔记]

    头件 : #include<stdio.h> 两个必须函数: FILE * fopen(const char * path,const char * mode); //path:文件路径 ...

  8. python爬虫破解带有RSA.js的RSA加密数据的反爬机制

    前言 同上一篇的aes加密一样,也是偶然发现这个rsa加密的,目标网站我就不说了,保密. 当我发现这个网站是ajax加载时: 我已经习以为常,正在进行爬取时,发现返回为空,我开始用findler抓包, ...

  9. 项目启动报错:Communications link failure

    2017-12-29 10:43:19,776 ERROR [com.alibaba.druid.pool.DruidDataSource] - <init datasource error, ...

  10. JAVA实现--基础算法FOR选择排序

    首先 实现简单的选择排序. 简单排序的思路很简单,就是通过遍历(数组的length次)的数组,每次遍历找出最小的放到数组的第一个位置,下次遍历时就不用考虑第0位置的数从第1的位置开始找1到length ...