赞
踩
一、原生语句
1、match
- POST /infomations/infomations/_update_by_query
- JSON请求格式
- {
- "query": {
- "match": {
- "status": "UP_SHELF"
- }
- },
- "script": {
- "inline": "ctx._source['status'] = 'DOWN_SHELF'"
- }
- }
假如是修改多个:多个的话就用分号隔开。
ctx._source[字段名] = “值”;ctx._source[字段名] = “值”;
2.term
- {
- "query": {
- "term": {
- "ssjg": "440000"
- }
- },
- "script": {
- "inline": "ctx._source['isonline'] = '1'"
- }
- }
- negative/negative/_update_by_query post
- {
- "query": {
- "prefix": {
- "sjlb.keyword": "药品广告(特殊医学用途配方食品广告适用药品广告管理规定,中华人民共和国食品安全法(2018修正)第"
- }
- },
- "script": {
- "lang": "painless",
- "source": "ctx._source.sjlb = params.live_name",
- "params": {
- "live_name": "药品广告(特殊医学用途配方食品广告适用药品广告管理规定,中华人民共和国食品安全法(2018修正)第80条)"
- }
- }
- }
2.java操作
- 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();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。