public class UpdateElasticAPI {
private static RestClient restClient; static {
restClient=RestClient.builder(new HttpHost("localhost",9200,"http")).build();
} /**
* 1.创建文档
* @throws Exception
*/
@Test
public void CreateDocument()throws Exception{ String method = "PUT";
String endpoint = "/update_index/test/1";
HttpEntity entity = new NStringEntity(
"{\n" +
" \"counter\" : 1,\n" +
" \"tags\" : [\"red\"]\n" +
"}", ContentType.APPLICATION_JSON); Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap(),entity);
System.out.println(EntityUtils.toString(response.getEntity()));
} /**
*2. 获取文档
* @throws Exception
*/
@Test
public void getDocument()throws Exception{
String method = "GET";
String endpoint = "/update_index/test/1";
Response response = restClient.performRequest(method,endpoint);
System.out.println(EntityUtils.toString(response.getEntity()));
} /**
* 3.更新文档,给counter字段加4
* @throws Exception
*/
@Test
public void UpdateDocument()throws Exception{ String method = "POST";
String endpoint = "/update_index/test/1/_update";
HttpEntity entity = new NStringEntity(
"{\n" +
" \"script\" : {\n" +
" \"source\": \"ctx._source.counter += params.count\",\n" +
" \"lang\": \"painless\",\n" +
" \"params\" : {\n" +
" \"count\" : 4\n" +
" }\n" +
" }\n" +
"}", ContentType.APPLICATION_JSON); Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap(),entity);
System.out.println(EntityUtils.toString(response.getEntity()));
} /**
* 4.部分文档更新增加字段(不存在name字段),存在则覆盖
* @throws Exception
*/
@Test
public void SomeUpdateDocument()throws Exception{ String method = "POST";
String endpoint = "/update_index/test/1/_update";
HttpEntity entity = new NStringEntity(
"{\n" +
" \"doc\" : {\n" +
" \"user\" : \"kimchy\"\n" +
" }\n" +
"}", ContentType.APPLICATION_JSON); Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap(),entity);
System.out.println(EntityUtils.toString(response.getEntity()));
} /**
* 5.按查询API更新
*/ }

Elasticsearch之更新的更多相关文章

  1. elasticsearch【更新】操作

    基于上一篇博文基础上,进行es的操作,document的新增比较简单,就不说了,这里主要说说更新操作. 更新操作,有两大类,一个是Replace,一个是Update,就是说一个是替换,一个是更新. 替 ...

  2. Elasticsearch之更新(全部更新和局部更新)

    前面的基础, Elasticsearch之curl创建索引库 Elasticsearch之curl创建索引 Elasticsearch之curl创建索引库和索引时注意事项 Elasticsearch之 ...

  3. Elasticsearch 追加更新

    追加更新,学名不知道叫啥,我这里指在历史数据的基础上,追加数据更新.比如 价格数据,我在价格字段里面保存了一个每天价格的数组,追加更新的时候在数组的后面直接add,而不是像一般情况那样覆盖. ES追加 ...

  4. 恕我直言,我也是才知道ElasticSearch条件更新是这么玩的

    背景 ElasticSearch 的使用度越来越普及了,很多公司都在使用.有做日志搜索的,有做商品搜索的,有做订单搜索的. 大部分使用场景都是通过程序定期去导入数据到 ElasticSearch 中, ...

  5. .net core Elasticsearch 查询更新

    记录一下: 数据结构如下: public class ESUserTransaction { public long AccountId { get; set; } public string Var ...

  6. [Elasticsearch] ES更新问题踩坑记录

    问题描述 我们有个系统设计的时候针对Hive创建表.删除表, 需要更新ES中的一个状态,标记是否删除,在几乎同时执行两条下面的语句的时候,发现在ES 中出现表即使被创建了还是无法被查询到的情况,针对该 ...

  7. elasticsearch更新操作问题

    elasticsearch在更新的时候,是通过id进行管理的,我们在前台传入id操作,id如果与elasticsearch相同,则覆盖,否则新增一条记录.且elasticsearch中的插入一条记录和 ...

  8. elasticsearch 大集群,双重别名,滚动更新分词方案

    elasticsearch 滚动更新分词 国内用ik.hanlp.ansj或基于其二次开发的比较多 必然有分词变更的操作(主要是是加词) reindex+别名可以解决一部分问题,但在大集群上会影响业务 ...

  9. Elasticsearch索引(company)_Centos下CURL增删改

    目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 1.Elasticsearch索引说明 a. 通过上面几篇博客已经将Elastics ...

随机推荐

  1. 如何保证FPGA PCIe唤醒能满足PC的100ms 的时间要求(Autonomous Mode)?

    原创By DeeZeng [ Intel FPGA笔记 ]  PC 需要PCIe设备在 100ms 内启动,这样PC 才能扫描到PCIe 设备.对于 FPGA PCIe 板卡,同样也需要满足这个时间要 ...

  2. SpringBoot中读取配置文件的几种方式

    1.读取application文件 在application.yml或者properties文件中添加: info: name: xiaoming age: 13 sex: 1 读取方式如下: imp ...

  3. Spring Boot 中的同一个 Bug,竟然把我坑了两次!

    真是郁闷,不过这事又一次提醒我解决问题还是要根治,不能囫囵吞枣,否则相同的问题可能会以不同的形式出现,每次都得花时间去搞.刨根问底,一步到位,再遇到类似问题就可以分分钟解决了. 如果大家没看过松哥之前 ...

  4. asp.net core 从单机到集群

    asp.net core 从单机到集群 Intro 这篇文章主要以我的活动室预约的项目作为示例,看一下一个 asp.net core 应用从单机应用到分布式应用需要做什么. 示例项目 活动室预约提供了 ...

  5. 通过Blazor使用C#开发SPA单页面应用程序(4) - Ant Design Button

    前面学习了Blazor的特点.环境搭建及基础知识,现在我们尝试的做个实际的组件. Ant Design是蚂蚁金服是基于Ant Design设计体系的 UI 组件库,主要用于研发企业级中后台产品.目前官 ...

  6. 天眼查sign 算法破解

    天眼查sign 算法破解 最近真的在sign算法破解上一去不复返 前几天看过了企查查的sign破解 今天再看看天眼查的sign算法破解,说的好(zhuang)点(bi)就是破解,不好的就是这是很简单的 ...

  7. 神经网络 OCR 参考

    1. https://blog.csdn.net/u010159842/article/details/87271554 2. https://blog.csdn.net/weixin_4286104 ...

  8. Python-demo(video)

    #!/usr/bin/env python# #-*-coding:utf-8-*-import requestsimport randomimport timedef get_json(url): ...

  9. 解决ionic 启动页面图片没有显示及启动页出现黑白屏

    1.ionic 正确打包完app, 并且按照正常的步骤配置config.xml文件之后 ,启动页面还是不能正常的显示出来,而是黑了一下之后,就进入首页了 原因很有可能就是你没有装cordova-plu ...

  10. 分布式日志收集系统 —— Flume

    一.Flume简介 Apache Flume 是一个分布式,高可用的数据收集系统.它可以从不同的数据源收集数据,经过聚合后发送到存储系统中,通常用于日志数据的收集.Flume 分为 NG 和 OG ( ...