AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
# 使用 ElasticsearchRepository 时间格式待处理 创建 repository 文件夹, 创建 EsTestRepository 并继承 ElasticsearchRepository ``` public interface EsTestRepository extends ElasticsearchRepository<TestIndex, String> { } ``` # 添加 ``` esTestRepository.save(testIndex); ``` # 批量添加 底层还是用的 elasticsearchOperations 的 ``` @Override public void batchSave(List<TestIndex> list) { Iterable<TestIndex> testIndices = esTestRepository.saveAll(list); } ``` # 更新 把要更新的数据转成json字符串, 然后根据主键去更新 test_index 是索引名称 ``` Document doc = Document.parse(JSONObject.toJSONString(testIndex)); UpdateQuery updateQuery = UpdateQuery.builder(testIndex.getId()).withDocument(doc).build(); UpdateResponse test_index = restTemplate.update(updateQuery, IndexCoordinates.of("test_index")); ``` # 批量更新 bulkUpdate , 就是把单个的更新, UpdateQuery 放到 list里, 一次去更新 ``` updateQuery 就是上面单条更新的数据 List<UpdateQuery> updateQueryList = new ArrayList<>(); updateQueryList.add(updateQuery); restTemplate.bulkUpdate(updateQueryList, IndexCoordinates.of("test_index")); ```