栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

elasticsearch 怎么做批量更新

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

elasticsearch 怎么做批量更新

最近项目组中有个问题 基础数据 对象 场站有个名称

名称是可以修改的 但是es里面存了名称 需要更新 用户ID 更新用户名称

类似sql update t_record set user_name = xxx where user_id = xx

es 里面有几百万条数据

怎么能做到更新名称呢?

springboot  2.2.6

org.springframework.data:spring-data-elasticsearch:jar:3.2.6.RELEASE

用 dsl rest 请求可以用 但是

POST http://localhost:9200/article/_update_by_query
{
    "script": {
        "source":"ctx._source['status']=0;"
    },
    "query": {
        "term": {
            "userId": 1
        }
    } 
}

这个方法查询结果会溢出

 CommonTermsQueryBuilder matchQueryBuilder = QueryBuilders.commonTermsQuery("locationId", locationId);

            Iterable search = chargeDetailRecordBillRepository.search(matchQueryBuilder);
            search.forEach(chargeDetailRecordBill -> chargeDetailRecordBill.setLocationName(locationName));
            chargeDetailRecordBillRepository.saveAll(search);

或者

  Iterable search = chargeDetailRecordBillRepository.search(matchQueryBuilder);
        search.forEach(chargeDetailRecordBill -> chargeDetailRecordBill.setPileName(opEvseInfoDTO.getPileName()));
        chargeDetailRecordBillRepository.saveAll(search);

ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Result window is too large, from + size must be less than or equal to: [10000] but was [20000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Result window is too large, from + size must be less than or equal to: [10000] but was [20000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.]];

采用流

  Stream search = chargeDetailRecordBillRepository.findByLocationId(locationId);
            Iterator iterator = search.iterator();
            while (iterator.hasNext()) {
                ChargeDetailRecordBill chargeDetailRecordBill = iterator.next();
                chargeDetailRecordBill.setLocationName(locationName);
                chargeDetailRecordBillRepository.save(chargeDetailRecordBill);
            }
            search.close();
{
    "from": 0,
    "size": 10000,
    "query": {
        "match": {
            "locationId": 44
        }
    },
    "_source": [
        "_id",
        "id",
        "orderNumber",
        "locationId",
        "locationName"
    ]
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/919211.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号