To update the StoreDrugIndex in a batch using Spring Boot and Elasticsearch, you can follow these steps:

  1. Create a new class called StoreDrugIndexRepository for interacting with Elasticsearch:
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface StoreDrugIndexRepository extends ElasticsearchRepository<StoreDrugIndex, String> {
}
  1. Update the StoreDrugIndex class to annotate it as an Elasticsearch document:
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

@Document(indexName = "store_drug_index")
public class StoreDrugIndex {
    @Id
    private String storeId;
    private String state;
    private String b2c;
    private String o2o;

    // getters and setters
}
  1. Create a new service class called StoreDrugIndexService to perform the batch update:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StoreDrugIndexService {
    private final StoreDrugIndexRepository storeDrugIndexRepository;

    @Autowired
    public StoreDrugIndexService(StoreDrugIndexRepository storeDrugIndexRepository) {
        this.storeDrugIndexRepository = storeDrugIndexRepository;
    }

    public void updateStoreDrugIndex(List<StoreDrugIndex> storeDrugIndexList) {
        storeDrugIndexRepository.saveAll(storeDrugIndexList);
    }
}
  1. In your controller class, inject the StoreDrugIndexService and use it to update the StoreDrugIndex in a batch:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/store-drug-index")
public class StoreDrugIndexController {
    private final StoreDrugIndexService storeDrugIndexService;

    @Autowired
    public StoreDrugIndexController(StoreDrugIndexService storeDrugIndexService) {
        this.storeDrugIndexService = storeDrugIndexService;
    }

    @PutMapping("/update")
    public void updateStoreDrugIndex(@RequestBody List<StoreDrugIndex> storeDrugIndexList) {
        storeDrugIndexService.updateStoreDrugIndex(storeDrugIndexList);
    }
}

Now, you can send a PUT request to "/store-drug-index/update" with the list of StoreDrugIndex objects in the request body to perform the batch update.

update StoreDrugIndex set state=set b2c=o2o= where storeId= 根据storeId批量更新 转为Springboot ES处理

原文地址: https://www.cveoy.top/t/topic/jfFI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录