EsScanJob.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.winhc.task.job;
  2. import com.mongodb.client.MongoCollection;
  3. import com.winhc.task.framework.es.EsFastScan;
  4. import com.winhc.task.util.DateUtils;
  5. import lombok.AllArgsConstructor;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.bson.Document;
  8. import org.elasticsearch.client.RestHighLevelClient;
  9. import org.elasticsearch.search.SearchHit;
  10. import org.springframework.data.mongodb.core.MongoTemplate;
  11. import org.springframework.stereotype.Component;
  12. import java.util.Arrays;
  13. import java.util.List;
  14. import java.util.function.Consumer;
  15. import java.util.stream.Collectors;
  16. /**
  17. * @author: XuJiakai
  18. * 2020/11/16 20:03
  19. */
  20. @Slf4j
  21. @Component
  22. @AllArgsConstructor
  23. public class EsScanJob {
  24. private RestHighLevelClient restHighLevelClient;
  25. private final MongoTemplate mongoTemplate;
  26. public void start() {
  27. }
  28. public void fixBugByDeleted(String dsl, String tn) {
  29. String ymd = DateUtils.getYesterday_ymd();
  30. MongoCollection<Document> person = mongoTemplate.getCollection("company_back_update_0423");
  31. Consumer<SearchHit[]> func = list -> {
  32. List<Document> li = Arrays.stream(list).map(d -> {
  33. String id = d.getId();
  34. Document document = new Document();
  35. // document.put("_id", id);
  36. document.put("rowkey", id);
  37. document.put("ds", ymd);
  38. document.put("tn", tn);
  39. return document;
  40. }).collect(Collectors.toList());
  41. person.insertMany(li);
  42. };
  43. new EsFastScan(restHighLevelClient, func, "winhc_index_" + tn + "_v1", "_doc", dsl,null).scan();
  44. }
  45. public void fixBugByDeleted(String tn) {
  46. String dsl = "{\n" +
  47. " \"query\": {\n" +
  48. " \"bool\": {\n" +
  49. " \"must_not\": [\n" +
  50. " {\"terms\": {\n" +
  51. " \"deleted\": [\n" +
  52. " \"0\",\n" +
  53. " \"9\",\n" +
  54. " \"1\"\n" +
  55. " ]\n" +
  56. " }}\n" +
  57. " ]\n" +
  58. " }\n" +
  59. " }\n" +
  60. "}";
  61. fixBugByDeleted(dsl, tn);
  62. }
  63. }