最近项目组中有个问题 基础数据 对象 场站有个名称
名称是可以修改的 但是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);
或者
Iterablesearch = 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.]];
采用流
Streamsearch = 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"
]
}



