ES(Elastic Search)update操作设置无 docment时进行insert
最近使用一套数据加工中间工具,查看es操作中的update操作。其中方法命名为updateOrInsert。但是没发现代码中有ES的insert方法调用。于是仔细分析了代码逻辑。
经过一路追溯,直至ES java客户端请求发送代码。没找到insert相关内容。
于是到官网查看究竟,可官网对 java Client相关说明比较少。查看不到具体api的说明。于是回到代码调用处:
String jsonText = jsonBuild.endObject().string();
UpdateRequest request = (UpdateRequest)esClient.prepareUpdate(xxx.getDatabase(), xxx.getTable(), docId).setDoc(jsonText).setDetectNoop(true).setDocAsUpsert(true).setRetryOnConflict(this.retryOnConflict).request();
esClient.update(request).get();
代码中属于链式调用,由于太长没有换行,竟然没看到后边的setDetectNoop,setDocAsUpsert参数的调用,于是思考,javaClient只是封装和转换了调用请求,于是再回到官网查看Document APIs,找到update操作的说明,就有了下边关于 Detecting Noop Updates 以及 Upserts说明:
Detecting noop updatesedit
If
docis specified its value is merged with the existing_source. By default the document is only reindexed if the new_sourcefield differs from the old. Settingdetect_nooptofalsewill cause Elasticsearch to always update the document even if it hasn’t changed. For example:curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"doc" : {
"name" : "new_name"
},
"detect_noop": false
}'
上边这段的意思是当更新的文档发生变化时进行更新,如果为fasle,则始终更新。
Upsertsedit
If the document does not already exist, the contents of the
upsertelement will be inserted as a new document. If the document does exist, then thescriptwill be executed instead:curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : {
"inline": "ctx._source.counter += count",
"params" : {
"count" : 4
}
},
"upsert" : {
"counter" : 1
}
}'
scripted_upserteditIf you would like your script to run regardless of whether the document exists or not — i.e. the script handles initializing the document instead of the
upsertelement — then setscripted_upserttotrue:curl -XPOST 'localhost:9200/sessions/session/dh3sgudg8gsrgl/_update' -d '{
"scripted_upsert":true,
"script" : {
"id": "my_web_session_summariser",
"params" : {
"pageViewEvent" : {
"url":"foo.com/bar",
"response":404,
"time":"2014-01-01 12:32"
}
}
},
"upsert" : {}
}'
doc_as_upserteditInstead of sending a partial
docplus anupsertdoc, settingdoc_as_upserttotruewill use the contents ofdocas theupsertvalue:curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"doc" : {
"name" : "new_name"
},
"doc_as_upsert" : true
}'
上边描述:upsert参数的使用,有三种方式:
- 指定upsert内容
- 指定打开脚本upsert开关使用脚本处理upsert
- 使用文档内容做为upsert参数,则打开 doc_as_upsert。显然我们上边所说的javaClient调用中就是使用的 doc_as_upsert,这样当文档不存在时候,就会将传递过来的文档内容insert进去。达到update or Insert 目的。
因此,对于ES java Clent使用不熟的完全可以参照 api命名查找官网的 api说明,java客户端是用java语言对其进行了封装。仔细阅读便知道调用代码逻辑的含义了。仅此记录,为不熟悉ES的其他使用者 引个路子。
官网内容链接:https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-update.html#upserts
可以根据自己使用的ES版本进行切换查看。
ES(Elastic Search)update操作设置无 docment时进行insert的更多相关文章
- elastic search安装与本地测试
elastic search安装与本地测试 elastic search是一个全文搜索引擎 教程: 综合:http://www.ruanyifeng.com/blog/2017/08/elastics ...
- Update操作浅析,一定是先Delete再Insert吗?
Update操作一定是先Delete再Insert吗? Update在数据库中的执行是怎么样的?“Update操作是先把数据删除,然后再插入数据”.在网上看了很多也都是这么认为的.但在查阅到一些不同看 ...
- Elastic Search 小调研
一.概况: Elastic Search 是一个基于Apache Lucene™工具包的开源搜索引擎.无论在开源还是专有领域,Lucene 可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库 ...
- Elastic Search快速上手(2):将数据存入ES
前言 在上手使用前,需要先了解一些基本的概念. 推荐 可以到 https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.htm ...
- elastic search book [ ElasticSearch book es book]
谁在使用ELK 维基百科, github都使用 ELK (ElasticSearch es book) ElasticSearch入门 Elasticsearch入门,这一篇就够了==>http ...
- Elastic Search中Document的CRUD操作
一. 新增Document在索引中增加文档.在index中增加document.ES有自动识别机制.如果增加的document对应的index不存在.自动创建,如果index存在,type不存在自动创 ...
- elastic search(以下简称es)
参考博客园https://www.cnblogs.com/Neeo/p/10304892.html#more 如何学好elasticsearch 除了万能的百度和Google 之外,我们还有一些其他的 ...
- Elastic Search操作入门
前言 Elastic Search是基于Lucene这个非常成熟的索引方案,另加上一些分布式的实现:集群,sharding,replication等.具体可以参考我同事写的文章. 本文主要介绍ES入门 ...
- elastic search&logstash&kibana 学习历程(一)es基础环境的搭建
elastic search 6.1.x 常用框架: 1.Lucene Apache下面的一个开源项目,高性能的.可扩展的工具库,提供搜索的基本架构: 如果开发人员需用使用的话,需用自己进行开发,成本 ...
随机推荐
- hdu3746(kmp最小循环节)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 题意:问在一个字符串末尾加上多少个字符能使得这的字符串首尾相连后能够循环 题解:就是利用next ...
- CentOS 7 下网络无法访问 Failed to start LSB: Bring up/.
[root@localhost Desktop]# ping 192.168.2.1PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.64 byt ...
- WebService学习一
什么是WebService? Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和 ...
- Vue中的slot(占坑,预留位置)
Vue中的slot(占坑,预留位置) 子模板不使用slot 子模板使用slot 子模板使用使用name属性,且传递data 文件名:Slots.vue //slot组件 <template> ...
- Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵动态限流规则
Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵动态限流规则 前面几篇文章较为详细的介绍了Sentinel的使用姿势,还没看过的小伙伴可以访问以下链接查看: &l ...
- 使用java程序作为celery的工作节点
celery是python实现的分布式调度框架,有时候想用celery去调用java服务,正好有一个celery-java的库可以使用,能达到这个效果,记录一下: 先添加依赖: <depende ...
- HBase WAL原理学习
1.概述 客户端往RegionServer端提交数据的时候,会写WAL日志,只有当WAL日志写成功以后,客户端才会被告诉提交数据成功,如果写WAL失败会告知客户端提交失败,换句话说这其实是一个数据落地 ...
- 自定义JDBC工具类
因为数据库的连接代码都是固定的,为了将减少重复的代码的书写,可以将这些代码封装为一个工具类,获取数据库的连接对象. import java.sql.Connection; import java.sq ...
- Java面试-interrupt
我们都知道,Java中停止一个线程不能用stop,因为stop会瞬间强行停止一个线程,且该线程持有的锁并不能释放.大家多习惯于用interrupt,那么使用它又有什么需要注意的呢? interrupt ...
- css3不定宽高水平垂直居中
1 justify-content:center;//子元素水平居中 2 align-items:center;//子元素垂直居中 3 display:-webkit-flex; 在父级元素上面加上上 ...