ES Docs-3:Modifying Data
Modifying Data
Indexing/Replacing Documents
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '
{
"name": "John Doe"
}'
If we then executed the above command again with a different (or same) document, Elasticsearch will replace (i.e. reindex) a new document on top of the existing one with the ID of 1
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '
{
"name": "Micheal"
}'
If, on the other hand, we use a different ID, a new document will be indexed and the existing document(s) already in the index remains untouched.
we are using the POST verb instead of PUT since we didn’t specify an ID.
curl -XPOST 'localhost:9200/customer/external?pretty' -d '
{
"name": "Jane Doe"
}'
Updating Documents
This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe":
改变name field
curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
"doc": { "name": "Jane Doe" }
}'
添加age field
curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
"doc": { "name": "Jane Doe", "age": 20 }
}'
脚本更新(失败)
curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
"script" : "ctx._source.age += 5"
}'
返回
{
"error" : {
"root_cause" : [ {
"type" : "remote_transport_exception",
"reason" : "[es_node_1][127.0.0.1:9300][indices:data/write/update[s]]"
} ],
"type" : "illegal_argument_exception",
"reason" : "failed to execute script",
"caused_by" : {
"type" : "script_exception",
"reason" : "scripts of type [inline], operation [update] and lang [groovy] are disabled"
}
},
"status" : 400
}
Deleting Documents
根据ID删除Doc
es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl -XDELETE 'localhost:9200/customer/external/2?pretty'
返回
{
"found" : true,
"_index" : "customer",
"_type" : "external",
"_id" : "2",
"_version" : 2,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
The delete-by-query plugin can delete all documents matching a specific query.
Batch Processing
_bulk API
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
'
返回
{
"took" : 17,
"errors" : false,
"items" : [ {
"index" : {
"_index" : "customer",
"_type" : "external",
"_id" : "1",
"_version" : 5,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"status" : 200
}
}, {
"index" : {
"_index" : "customer",
"_type" : "external",
"_id" : "2",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"status" : 201
}
} ]
}
当然,也可以进行索引的更新和删除操作,不过删除操作没有参数
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
This functionality is important in that it provides a very efficient mechanism to do multiple operations as fast as possible with as little network roundtrips as possible.
The bulk API executes all the actions sequentially and in order. If a single action fails for whatever reason, it will continue to process the remainder of the actions after it. When the bulk API returns, it will provide a status for each action (in the same order it was sent in) so that you can check if a specific action failed or not.
参考资料
来源: https://www.elastic.co/guide/en/elasticsearch/reference/current/_batch_processing.html
最新文章
- [转]LUA C 互调
- 多种方法实现H5网页图片动画效果;
- Piotr's Ants UVa 10881
- 转: Firefox 浏览器对 TABLE 中绝对定位元素包含块的判定有错误
- delphi 线程教学第六节:TList与泛型
- 异常 - Error / Checked Exception / Runtime Exception
- Shell 变量、脚本参数
- 《汇编语言 基于x86处理器》第七章整数运算部分的代码
- Node稳定性的研究心得
- mysql学习------错误日志和通用查询日志
- 【安全开发】IOS安全编码规范
- 团队作业4 Alpha冲刺
- [翻译]Review——24 tips for React Native you probably want to know
- 混沌数学之拉比诺维奇-法布里康特方程(Rabinovich-Fabrikant equations)
- 【BioCode】将多个蛋白质序列分成单个的txt文档
- mybatis 简单实现 left join
- Cannot assign requested address (connect failed)
- vi编辑器:命令模式、输入模式、末行模式
- ORACLE系统表大全
- J2EE之EJB
热门文章
- TMS scripter使用心得
- CDH- 集群时间同步ntp问题解决
- 给手机发验证码 综合使用 (忘记密码处理 php发验证码 重置用户密码)
- php导出内容到txt并自动弹出下载文件
- flex 和bison的安装和使用
- 解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
- BZOJ1150:[CTSC2007]数据备份
- Azure Public IP DNS域名
- Jetson TX2火力全开
- 在Golang中使用C语言代码实例