ElasticSearch 更新数据
2018-03-06 00:00
141 查看
1. 创建测试索引
PUT test { "mappings": { "test1": { "properties": { "num1": { "type": "integer" }, "num2": { "type": "integer" }, "num3": { "type": "nested", "properties": { "num31": { "type": "integer" }, "num32": { "type": "integer" } } } } } } }
2. 添加测试数据
PUT test/test1/1 { "num1": 11, "num2": 12, "num3": [ { "num31": 131, "num32": 132 }, { "num31": 133, "num32": 134 } ] } PUT test/test1/2 { "num1": 21, "num2": 12, "num3": [ { "num31": 231, "num32": 232 }, { "num31": 233, "num32": 234 } ] }
3. 查看数据
GET test/test1/_search
4. 根据id更新数据
POST test/test1/1/_update { "doc": { "num1": 10 } }
5. 使用 update_by_query 更新数据
POST test/test1/_update_by_query { "script": { "lang": "painless", "source": "ctx._source.num1=111;ctx._source.num2=222" }, "query": { "bool": { "must": [ { "term": { "num2": { "value": "12" } } } ] } } }
6. 使用 update_by_query 为 nested 类型追加单条数据
POST test/test1/_update_by_query { "script": { "lang": "painless", "source": "ctx._source.num3.add(params.new_data)", "params": { "new_data": { "num31":1111, "num32":2222 } } }, "query": { "bool": { "must": [ { "term": { "num2": { "value": "22" } } } ] } } }
7. 使用 update_by_query 为 nested 类型追加多条数据
POST test/test1/_update_by_query { "script": { "lang": "painless", "source": "ctx._source.num3.addAll(params.new_datas)", "params": { "new_datas": [ { "num31":1111, "num32":2222 }, { "num31":3333, "num32":4444 }, { "num31":5555, "num32":6666 } ] } }, "query": { "bool": { "must": [ { "term": { "num2": { "value": "12" } } } ] } } }
相关文章推荐
- ElasticSearch教程--第十一章:修改您的数据--更新文档
- elasticsearch更新数据
- 极速快三平台出租关于elasticsearch中更新数据的几种方式
- ElasticSearch-jdbc从Mysql数据库导入和更新数据
- Elasticsearch数据更新API
- elasticsearch更新文档数据
- 关于elasticsearch中更新数据的几种方式
- Python中elasticsearch如何插入和更新数据
- 关于ElasticSearch中更新数据的几种方式
- Python中elasticsearch插入和更新数据的实现方法
- 选择数据库中重复的记录,用一个表中的数据更新另一个表
- 用另一个表数据更新字段
- NSOperation 数据返回后更新tableview
- mongodb基础数据更新
- Ajax实现无刷新的获取数据并绑定到GridView,以及无刷新更新数据
- PHP实现更新中间关联表数据的两种方法
- Zabbix 3.4.6 新特性:历史数据支持 Elasticsearch
- ORACLE 闪回删除的表/数据,闪回更新数据
- Ext 4.2 grid 读脏数据问题:某一行数据被更新,更新前后获取这一行数据数据不匹配的问题
- Mybatis批量更新数据