Elasticsearch之更新
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之更新的更多相关文章
- elasticsearch【更新】操作
		
基于上一篇博文基础上,进行es的操作,document的新增比较简单,就不说了,这里主要说说更新操作. 更新操作,有两大类,一个是Replace,一个是Update,就是说一个是替换,一个是更新. 替 ...
 - Elasticsearch之更新(全部更新和局部更新)
		
前面的基础, Elasticsearch之curl创建索引库 Elasticsearch之curl创建索引 Elasticsearch之curl创建索引库和索引时注意事项 Elasticsearch之 ...
 - Elasticsearch 追加更新
		
追加更新,学名不知道叫啥,我这里指在历史数据的基础上,追加数据更新.比如 价格数据,我在价格字段里面保存了一个每天价格的数组,追加更新的时候在数组的后面直接add,而不是像一般情况那样覆盖. ES追加 ...
 - 恕我直言,我也是才知道ElasticSearch条件更新是这么玩的
		
背景 ElasticSearch 的使用度越来越普及了,很多公司都在使用.有做日志搜索的,有做商品搜索的,有做订单搜索的. 大部分使用场景都是通过程序定期去导入数据到 ElasticSearch 中, ...
 - .net core Elasticsearch 查询更新
		
记录一下: 数据结构如下: public class ESUserTransaction { public long AccountId { get; set; } public string Var ...
 - [Elasticsearch] ES更新问题踩坑记录
		
问题描述 我们有个系统设计的时候针对Hive创建表.删除表, 需要更新ES中的一个状态,标记是否删除,在几乎同时执行两条下面的语句的时候,发现在ES 中出现表即使被创建了还是无法被查询到的情况,针对该 ...
 - elasticsearch更新操作问题
		
elasticsearch在更新的时候,是通过id进行管理的,我们在前台传入id操作,id如果与elasticsearch相同,则覆盖,否则新增一条记录.且elasticsearch中的插入一条记录和 ...
 - elasticsearch 大集群,双重别名,滚动更新分词方案
		
elasticsearch 滚动更新分词 国内用ik.hanlp.ansj或基于其二次开发的比较多 必然有分词变更的操作(主要是是加词) reindex+别名可以解决一部分问题,但在大集群上会影响业务 ...
 - Elasticsearch索引(company)_Centos下CURL增删改
		
目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 1.Elasticsearch索引说明 a. 通过上面几篇博客已经将Elastics ...
 
随机推荐
- byte数组和正数BigInteger之间的相互转换
			
旧代码 public static void main(String[] args) { SecureRandom random = new SecureRandom(); byte[] key = ...
 - charles(version4.2.1)抓包手机数据
			
点击菜单栏的Proxy项,选择Proxy Settings. 设置HTTP Proxy的Port. 勾选透明代理Enable transparent HTTP proxying,也可不勾选. 设置代理 ...
 - Oracle中查看最近被修改过的表的方法
			
1.select uat.table_name from user_all_tables uat 该SQL可以获得所有用户表的名称 2.select object_name, created,last ...
 - 利用反射搭建orm框架
			
1思路 根据java反射获取属性上的 注解的value的值 然后拼接成sql去执行 这就是完成了一个orm实体关系映射 package src.Test.Reflect;import java.lan ...
 - 第一次亲密接触——二狗子初识 CDN
			
二狗子是国内知名XXX大学的在校学生,作为一名编程爱好者,他利用业余时间搭建了一个网站,把平时的学习心得和技术分享全都 PO 在自己的网站上.渐渐地,二狗子的网站因为文章质量高,技术分享全面,受到了很 ...
 - 在Linux和Windows系统中输出目录结构
			
前言 一直以来就想在写文章时,能以文本形式(而不是截图)附上项目的目录结构,今天终于知道怎么操作了,在这分享一下. Linux 首先说下Linux上输出目录结构的方法. yum安装tree 需要支持t ...
 - python骚操作---Print函数用法
			
---恢复内容开始--- python骚操作---Print函数用法 在 Python 中,print 可以打印所有变量数据,包括自定义类型. 在 3.x 中是个内置函数,并且拥有更丰富的功能. 参数 ...
 - npm执行命令行报错
			
今天在学习react-router时候使用命令npm start 报了一个错误 npm ERR! missing script: start npm ERR! A complete log of th ...
 - Mybatis-plus的使用
			
接口mapper需要继承BaseMapper<要操作的类>外加@Mapper mport org.apache.ibatis.annotations.Mapper; import org. ...
 - 0807   创建vue实例以及vue的基础指令
			
lession1 1.Vue的了解 渐进式框架 作者:尤雨溪 mvvm 2.创建vue实例 引入<script src="vue.js"><scr ...