elasticsearch 中文API 更新(五)
更新API
你能够创建一个UpdateRequest,然后将其发送给client。
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index("index");
updateRequest.type("type");
updateRequest.id("1");
updateRequest.doc(jsonBuilder()
.startObject()
.field("gender", "male")
.endObject());
client.update(updateRequest).get();
或者你也可以利用prepareUpdate方法
1 client.prepareUpdate("ttl", "doc", "1")
2 .setScript("ctx._source.gender = \"male\"" , ScriptService.ScriptType.INLINE)
3 .get();
5 client.prepareUpdate("ttl", "doc", "1")
6 .setDoc(jsonBuilder()
7 .startObject()
8 .field("gender", "male")
9 .endObject())
10 .get();
1-3行用脚本来更新索引,5-10行用doc来更新索引。
当然,java API也支持使用upsert。如果文档还不存在,会根据upsert内容创建一个新的索引。
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();
如果文档index/type/1已经存在,那么在更新操作完成之后,文档为:
{
"name" : "Joe Dalton",
"gender": "male"
}
否则,文档为:
{
"name" : "Joe Smith",
"gender": "male"
}
elasticsearch 中文API 更新(五)的更多相关文章
- elasticsearch 中文API facets(⑩)
facets Elasticsearch提供完整的java API用来支持facets.在查询的过程中,将需要计数的facets添加到FacetBuilders中.然后将该FacetBuilders条 ...
- elasticsearch 中文API 基于查询的删除(九)
基于查询的删除API 基于查询的删除API允许开发者基于查询删除一个或者多个索引.一个或者多个类型.下面是一个例子. import static org.elasticsearch.index.que ...
- elasticsearch 中文API 记数(八)
计数API 计数API允许开发者简单的执行一个查询,返回和查询条件相匹配的文档的总数.它可以跨多个索引以及跨多个类型执行. import static org.elasticsearch.index. ...
- elasticsearch 中文API bulk(六)
bulk API bulk API允许开发者在一个请求中索引和删除多个文档.下面是使用实例. import static org.elasticsearch.common.xcontent.XCont ...
- elasticsearch 中文API 索引(三)
索引API 索引API允许开发者索引类型化的JSON文档到一个特定的索引,使其可以被搜索. 生成JSON文档 有几种不同的方式生成JSON文档 利用byte[]或者作为一个String手动生成 利用一 ...
- elasticsearch 中文API(一)
Java API 这节会介绍elasticsearch支持的Java API.所有的elasticsearch操作都使用Client对象执行.本质上,所有的操作都是并行执行的. 另外,Client中的 ...
- elasticsearch _update api 更新部分字段内容
https://www.elastic.co/guide/cn/elasticsearch/guide/current/partial-updates.htmlupdate 请求最简单的一种形式是接收 ...
- elasticsearch 中文API river
river-jdbc 安装 ./bin/plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/pl ...
- elasticsearch 中文API 删除(四)
删除API 删除api允许你通过id,从特定的索引中删除类型化的JSON文档.如下例: DeleteResponse response = client.prepareDelete("twi ...
随机推荐
- Sublime Text最舒服的主题
Theme - Afterglow (官网链接) 贴上 preferences -> settings 里面的配置 { "theme": "Afterglow-gr ...
- recorder.js 基于H5录音功能
recorder.js 基于HTML5的录音功能,输出格式为mp3文件. 前言 完全依赖H5原生API所涉及的API:WebRTC.AudioContext.Worker.Video/Audio AP ...
- C/C++ ShowWindow()
{ ShowWindow(HWND,0);//不显示窗口 }
- Open CV 环境配置
{ //https://github.com/zhmmmm/ANYTOOL-2.0.0.0.2Version/tree/master/OpenCVProject } /* //各个版本下载 https ...
- Astyle 快速入门,常用指令
--style=java -n -p -c !E astyle是一个命令行工具,命令语法很简单: astyle [options] < original > Beauti ...
- Appium测试过程中,建议使用谷歌输入法。用搜狗输入法报错报找不到元素,卡住
1. 手机使用谷歌输入法,在登录页面输入密码时输入数字时卡住报错 代码: 手机卡住 页面:看到页面上没有显示数字,所以卡住报错
- import time 进度条动态输出26个字母
# 2018-08-06 19:42:51 import time # 调用时间模块 num = 97 # 字母a while num <= 115: # print(chr(num), end ...
- idea的安装与破解
1.下载 官网:https://www.jetbrains.com/idea/download/#section=windows 百度盘:https://pan.baidu.com/s/16mRNPK ...
- 08_springboot2.x自定义starter
概述 starter:启动器 1.这个场景需要使用到的依赖是什么? 2.如何编写自动配置 规则: @Configuration //指定这个类是一个配置类 @ConditionalOnXXX //在指 ...
- 11_springmvc之RESTful支持
一.理解RESTful RESTful架构,就是一种互联网软件架构.它结构清晰.符合标准.易于理解.扩展方便,所以正得到越来越多网站的采用. RESTful(即Representational Sta ...