elasticsearch批量修改,批量更新某个字段
生活随笔
收集整理的这篇文章主要介绍了
elasticsearch批量修改,批量更新某个字段
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1.源生API
在这里没有用官方提供的bulk API,而是用的另外一种方式。
POST /infomations/infomations/_update_by_query JSON请求格式 {"query": {"match": {"status": "UP_SHELF"}},"script": {"inline": "ctx._source['status'] = 'DOWN_SHELF'"} }POST请求/索引/文档名/_update_by_query主要看一下下面的scriptctx._source[字段名] = “值”;ctx._source[字段名] = “值”;
多个的话就用分号隔开。
2.JAVA API操作
//集群模式,获取链接Client client = elasticsearchTemplate.getClient();
UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client);String name = "修改数值";updateByQuery.source("索引")
//查询要修改的结果集.filter(QueryBuilders.termQuery("field", 412))
//修改操作 .script(new Script( "ctx._source['field']='"+ name+"';ctx._source['field']='"+name+"'"));//响应结果集
BulkByScrollResponse response = updateByQuery.get();long updated = response.getUpdated();
转载于:https://www.cnblogs.com/technologykai/p/9983098.html
总结
以上是生活随笔为你收集整理的elasticsearch批量修改,批量更新某个字段的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Lint found fatal err
- 下一篇: 锁和分布式锁