zoukankan      html  css  js  c++  java
  • 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
    
    主要看一下下面的script
    
    ctx._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();
  • 相关阅读:
    SPOJ 8093 JZPGYZ
    UVA1030 Image Is Everything
    UVA11996 Jewel Magic
    UVA11922 Permutation Transformer
    UVA1479 Graph and Queries
    P3224 [HNOI2012]永无乡
    UVA11020 Efficient Solutions
    UVA12206 Stammering Aliens
    UVA11107 Life Forms
    UVA11019 Matrix Matcher
  • 原文地址:https://www.cnblogs.com/technologykai/p/9983098.html
Copyright © 2011-2022 走看看