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
- 下一篇: 锁和分布式锁