ElasticSearch for Modify your Data
2016-06-16 10:12
441 查看
一、Updating Documents
This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe":
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"doc":{"name":"Jane Doe"}
}'
This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe" and at the same time add an age field to it:
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"doc":{"name":"Jane Doe","ages":20}
0}'
Elasticsearch支持通过脚本修改文档信息
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script" : "ctx._source.ages += 5"
}'
OR
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script": {
"inline":{ctx._source.ages+=age},
"params":{
"age":20
}
}
}'
除了_source字段,可以通过ctx来获得_index、_type、_id、_version、_parent、_timestamp、_ttl等字段信息
也可以利用srcipt添加字段信息
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script":"ctx._source.name_of_new_field=\"value_of_new_field\""
}'
也可以利用srcipt移除字段信息
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script":"ctx._source.remove(\"name_of_field\")"
}'
二、Delting Documents
Deleting a document is fairly straightforward. This example shows how to delete our previous customer with the ID of 2
curl -XDELETE '192.168.56.101:9200/customer/external/2?pretty'
三、Batch Processing
As a quick example, the following call indexes two documents (ID 1 - John Doe and ID 2 - Jane Doe) in one bulk operation:
This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe":
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"doc":{"name":"Jane Doe"}
}'
This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe" and at the same time add an age field to it:
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"doc":{"name":"Jane Doe","ages":20}
0}'
Elasticsearch支持通过脚本修改文档信息
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script" : "ctx._source.ages += 5"
}'
OR
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script": {
"inline":{ctx._source.ages+=age},
"params":{
"age":20
}
}
}'
除了_source字段,可以通过ctx来获得_index、_type、_id、_version、_parent、_timestamp、_ttl等字段信息
也可以利用srcipt添加字段信息
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script":"ctx._source.name_of_new_field=\"value_of_new_field\""
}'
也可以利用srcipt移除字段信息
curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '
{
"script":"ctx._source.remove(\"name_of_field\")"
}'
二、Delting Documents
Deleting a document is fairly straightforward. This example shows how to delete our previous customer with the ID of 2
curl -XDELETE '192.168.56.101:9200/customer/external/2?pretty'
三、Batch Processing
As a quick example, the following call indexes two documents (ID 1 - John Doe and ID 2 - Jane Doe) in one bulk operation:
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d ' {"index":{"_id":"1"}} {"name": "John Doe" } {"index":{"_id":"2"}} {"name": "Jane Doe" } 'This example updates the first document (ID of 1) and then deletes the second document (ID of 2) in one bulk operation:
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d ' {"update":{"_id":"1"}} {"doc": { "name": "John Doe becomes Jane Doe" } } {"delete":{"_id":"2"}}
相关文章推荐
- libCurl上传下载代码一个好用的
- Hibernate 左外连接查询
- Linux无法解析hosts里面绑定域名的排查方法
- android编码时的细节进行优化内存
- Linux中安装PHP的pdo_mysql扩展的详细解决方案
- HDU 1000 & HDU1001 & 字符串连接
- Java 循环中标签的作用
- iOS同一种页面布局加载不同的页面数据的数据刷新
- 程序出错时自动生成dump文件
- ubuntu(16.04)+java(eclipse)+android(android studio)
- strerror
- 看Cognos+SPSS如何无缝对接BI+Data Mining
- 利用Apache AB测试Web引擎性能
- 使用循环语句绘制图案-2
- try catch finally 用法
- MySQL性能优化经验
- Xamarin Forms启动自带模拟器缓慢
- JS模块化编程--AMD规范学习01
- Spring4+Struts2+Hibernate 搭建示例
- HDU 2639 Bone Collector II