elasticsearch中的upsert
来源:互联网 发布:linux时间同步 chrony 编辑:程序博客网 时间:2024/06/05 15:53
elasticsearch的更新功能是非常强大的,一直知道在update中有一个upsert功能,因为一直用不到也就没有去仔细看一下,最近,因为有业务可能要用到该功能,这里简单的说一下:
通过curl去更新数据如下:
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{ "doc" : { "name" : "new_name" }, "upsert" : { "counter" : 1 }}'上面的例子就是实现_id为1的文档的更新操作,如果_id为1的文档存在,则去更新doc中的内容,如果不存在,则将upsert中的内容插入进去.这里需要注意,如果doc中要更新的字段,比如name不存在,则会将这个name数据插入进去.当然,如果配置了禁止动态生成mapping,则会失败.
java中的代码实现,如下:
IndexRequest indexRequest = new IndexRequest("index", "type", "1") .source(jsonBuilder() .startObject() .field("name", "Joe Smith") .field("gender", "male") .endObject());UpdateRequest updateRequest = new UpdateRequest("index", "type", "1") .doc(jsonBuilder() .startObject() .field("gender", "male") .endObject()) .upsert(indexRequest); client.update(updateRequest).get();
0 0
- elasticsearch中的upsert
- elasticsearch中批量的upsert
- Upsert
- PostgreSQL upsert
- pymongo upsert
- elasticsearch中的mapping简介
- Elasticsearch中的CRUD
- elasticsearch中的mapping简介
- ElasticSearch中的bucket容器
- Elasticsearch中的动态映射
- elasticsearch中的数据类型
- elasticsearch中的mapping简介
- ElasticSearch中的一些基本概念
- elasticsearch中的mapping简介
- Elasticsearch中的CRUD
- elasticsearch中的API
- Elasticsearch中的doc是咋回事
- Elasticsearch中的segment理解
- popupWindow 在指定位置上的显示
- 孩子们的游戏(圆圈中最后剩下的数)
- swing显示图片
- APK 的自我保护
- 我的的一篇博客
- elasticsearch中的upsert
- 三层之窗体登录
- 视频的分辨率
- 在Windows 7 上安装 Mapnik
- cmd
- 想跳槽?先看什么是好工作
- iOS UIWebView 修改user-agent
- QMainWindow布局和QDialog布局的区别
- Linux系统下以RPM方式安装mysql-5.7.9【5.7版本以后,启动mysqld服务首次登录需要密码,为root生成的随机密码在错误日志文件/var/log/mysqld.log】