elasticsearch api中的Update API操作
来源:互联网 发布:淘宝动漫周边那家店好 编辑:程序博客网 时间:2024/06/04 20:12
You can either create an UpdateRequest
and send it to the 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();
Or you can use prepareUpdate()
method:
client.prepareUpdate("ttl", "doc", "1") .setScript(new Script("ctx._source.gender = \"male\"" , ScriptService.ScriptType.INLINE, null, null)) .get();client.prepareUpdate("ttl", "doc", "1") .setDoc(jsonBuilder() .startObject() .field("gender", "male") .endObject()) .get();
Your script. It could also be a locally stored script name.In that case, you’ll need to useScriptService.ScriptType.FILE
Document which will be merged to the existing one.
Note that you can’t provide both script
and doc
.
Update by scriptedit
The update API allows to update a document based on a script provided:
UpdateRequest updateRequest = new UpdateRequest("ttl", "doc", "1") .script(new Script("ctx._source.gender = \"male\""));client.update(updateRequest).get();
Update by merging documentsedit
The update API also support passing a partial document, which will be merged into the existing document (simplerecursive merge, inner merging of objects, replacing core "keys/values" and arrays). For example:
UpdateRequest updateRequest = new UpdateRequest("index", "type", "1") .doc(jsonBuilder() .startObject() .field("gender", "male") .endObject());client.update(updateRequest).get();
Upsertedit
There is also support for upsert
. If the document does not exist, the content of theupsert
element will be used to index the fresh doc:
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();
If the document does not exist, the one in indexRequest
will be added
If the document index/type/1
already exists, we will have after this operation a document like:
{ "name" : "Joe Dalton", "gender": "male" }
This field is added by the update request
If it does not exist, we will have a new document:
{ "name" : "Joe Smith", "gender": "male"}
- elasticsearch api中的Update API操作
- elasticsearch api中的Multi Get API操作
- elasticsearch api中的Bulk API操作
- elasticsearch api中的get操作
- elasticsearch api中的delete操作
- ElasticSearch API 之 UPDATE
- elasticsearch api中的Delete By Query API操作
- Elasticsearch API操作01
- elasticsearch rest api操作
- elasticsearch中的API
- elasticsearch中的API
- elasticsearch中的API
- elasticsearch中的API
- elasticsearch之Document APIs【Update API】
- Elasticsearch之API CUED操作
- java操作ElasticSearch的API
- Elasticsearch Java-API CRUD Java操作Elasticsearch
- 使用Elasticsearch的java api,操作elasticsearch
- 这4种云部署模式,说明云计算已成为数字化社会中枢
- Codeforces 799C Fountains 题解
- Eclipse基本快捷键
- imooc java学习之异常与异常处理作业
- 微信中h5中的视频无法播放,提示视频解析失败的根本原因。
- elasticsearch api中的Update API操作
- java 工具包
- MediaPlayer播放多媒体时注册音频播放焦点
- java 二维码生成与解析
- 微信开发示例程序
- 量化交易——传统技术分析布林通道BollingerBands的原理及实现
- Elasticsearch教程,Elasticsearch安全篇,通过Nginx http basic 限制访问
- 发布新文章和管理文章
- vue-交互 -取值- 赋值