ES Docs-3:Modifying Data
2016-04-18 18:48
344 查看
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删除Doces@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相关文章推荐
- Ubuntu14.04安装搜狗输入法
- Python学习笔记(三)——字符串
- sass的编译工具Koala
- solr入门之edismax权重排序使用之Java代码实现自定义权重
- Oracle笔记(十二) 集合、序列
- DAY3
- Spring MVC Controller中解析GET方式的中文参数会乱码的问题
- 每日站立会议(一)
- 【笔记】iOS开发基础笔记<四>
- 自定义View(三),仿支付宝芝麻信用自定义控件
- 初时mysql
- Hibernate 性能优化法则
- HDU 3062 Party 2-SAT
- ES Docs-2:Exploring ES cluster
- ES Docs-1:Installation Elasticsearch-2.3.1
- click事件和mousedown、mouseup事件
- [Rho大整数分解] BZOJ 4522 [Cqoi2016]密钥破解
- Mybatis最入门---Mapper文件配置详解(下)
- springmvc 后端返回到前端乱码
- 知识梳理计划