test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package docs
  2. func AddDoc() {
  3. //ctx := context.TODO()
  4. //table := "chapter_logs_1"
  5. //
  6. ////
  7. //////// 创建索引
  8. //////err := ChapterLogs.CreateIndex(ctx, table)
  9. //////if err != nil {
  10. ////// logrus.Warnf("CreateIndex err:%+v", err)
  11. ////// //return
  12. //////}
  13. //////
  14. //// 添加数据
  15. //var (
  16. // tab = config.DB.Scopes(model.ChapterLogTableSetName(table))
  17. // q = query.Use(tab).ChapterLog.Table("")
  18. //)
  19. //
  20. //lists, err := q.Limit(100).Find() // 4.6以后的数据
  21. //if err != nil {
  22. // logrus.Warnf("Find err:%+v", err)
  23. // return
  24. //}
  25. //for _, v := range lists {
  26. // err = eapi.Insert(ctx, table, v.ID, v)
  27. // if err != nil {
  28. // logrus.Warnf("Insert err:%+v", err)
  29. // return
  30. // }
  31. //}
  32. //query := map[string]interface{}{
  33. // "query": map[string]interface{}{
  34. // "match_phrase": map[string]interface{}{
  35. // "extra": `{"type":1}`,
  36. // },
  37. // },
  38. // //"aggs": map[string]interface{}{ // 合查询语句的简写
  39. // // "count_name": map[string]interface{}{ // 给聚合查询取个名字,
  40. // // "value_count": map[string]interface{}{
  41. // // "field": "name.keyword", //
  42. // // },
  43. // // },
  44. // //},
  45. // //"from": 0,
  46. // //"size": 1,
  47. // //"sort": []map[string]interface{}{
  48. // // {"pubDate": []map[string]interface{}{
  49. // // {"order": "desc"},
  50. // // },
  51. // // },
  52. // //},
  53. //}
  54. //count, err := ChapterLogs.Count(ctx, table, query)
  55. //if err != nil {
  56. // logrus.Warnf("Count err:%+v", err)
  57. // return
  58. //}
  59. //
  60. //logrus.Warnf("Count:%+v", count)
  61. //
  62. //res, err := config.Elastic.Cat.Shards(
  63. // config.Elastic.Cat.Shards.WithContext(ctx),
  64. //)
  65. //if err != nil {
  66. // logrus.Warnf("Shards err:%+v", err)
  67. // return
  68. //}
  69. //
  70. //shards, err := String(res.Body)
  71. //if err != nil {
  72. // logrus.Warnf("Shards String err:%+v", err)
  73. // return
  74. //}
  75. //
  76. //logrus.Warnf("shards:%+v", shards)
  77. //
  78. //ss := strings.Split(shards, "\n")
  79. //for _, s := range ss {
  80. // s2 := strings.Split(s, " ")
  81. // if len(s2) < 1 {
  82. // continue
  83. // }
  84. //
  85. // if s2[0] != "" {
  86. // logrus.Warnf("s3:%+v \n", s2[0])
  87. // }
  88. //
  89. // //for k, s3 := range s2 {
  90. // // if k == 0 {
  91. // // logrus.Warnf("===================")
  92. // // }
  93. // // logrus.Warnf("s3:%+v \n", s3)
  94. // //}
  95. //}
  96. }
  97. //func AddDoc() {
  98. //
  99. // body := &bytes.Buffer{}
  100. // pubDate := time.Now()
  101. // json.NewEncoder(body).Encode(&Book{
  102. // Author: "金庸",
  103. // Price: 96.0,
  104. // Name: "天龙八部",
  105. // Pages: 1978,
  106. // PubDate: &pubDate,
  107. // Summary: "...",
  108. // })
  109. //
  110. // // 创建
  111. // response, err := config.Elastic.Create("es_test_book", "1", body)
  112. // if err != nil {
  113. // logrus.Warnf("docs err:%+v", err)
  114. // }
  115. //
  116. // logrus.Warnf("response:%+v", response)
  117. //}