瀏覽代碼

fix:初始化es索引结构

zqbao 8 月之前
父節點
當前提交
2d9bfc3823
共有 3 個文件被更改,包括 60 次插入3 次删除
  1. 3 1
      .gitignore
  2. 5 2
      main.go
  3. 52 0
      services/task.go

+ 3 - 1
.gitignore

@@ -5,4 +5,6 @@
 *.exe~
 go.sum
 scheduler/etalogs/
-scheduler/conf/
+scheduler/conf/
+/test/
+*_test.go

+ 5 - 2
main.go

@@ -4,6 +4,7 @@ import (
 	"eta/eta_mini_crm/controllers"
 	_ "eta/eta_mini_crm/routers"
 	"eta/eta_mini_crm/scheduler"
+	"eta/eta_mini_crm/services"
 	"eta/eta_mini_crm/utils"
 	"fmt"
 	"runtime"
@@ -19,10 +20,12 @@ func main() {
 		web.BConfig.WebConfig.DirectoryIndex = true
 		web.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
 	}
-
+	web.BConfig.WebConfig.AutoRender = false
 	// 启动定时任务
 	go scheduler.InitJob()
-	web.BConfig.WebConfig.AutoRender = false
+
+	// 初始化Es索引
+	services.InitTask()
 	web.ErrorController(&controllers.ErrorController{})
 	// 内存调整
 	web.BConfig.MaxMemory = 1024 * 1024 * 128

+ 52 - 0
services/task.go

@@ -0,0 +1,52 @@
+package services
+
+import (
+	"eta/eta_mini_crm/services/elastic"
+	"eta/eta_mini_crm/utils"
+	"fmt"
+)
+
+func InitTask() {
+	fmt.Println("start task")
+	CreateIndex()
+	fmt.Println("end task!")
+}
+
+func CreateIndex() {
+	var mappingJson = `{
+  "mappings": {
+    "properties": {
+      "ReportPdfId": {"type": "integer"},
+      "PdfUrl": {"type": "text"},
+      "PdfName": {"type": "text"},
+      "Title": {"type": "text"},
+      "Author": {"type": "text"},
+      "Abstract": {"type": "text"},
+      "ClassifyIdFirst": {"type": "integer"},
+      "ClassifyNameFirst": {"type": "text"},
+      "ClassifyIdSecond": {"type": "integer"},
+      "ClassifyNameSecond": {"type": "text"},
+      "Stage": {"type": "integer"},
+      "PublishTime": {
+        "type": "text",
+        "fields": {
+          "keyword": {
+            "type": "keyword",
+            "ignore_above": 256
+          }
+        }
+      },
+      "ModifyTime": {"type": "date"},
+      "Pv": {"type": "integer"},
+      "Uv": {"type": "integer"},
+      "SysUserId": {"type": "integer"},
+      "SysRealName": {"type": "text"},
+      "State": {"type": "integer"}
+	}
+   }
+}`
+	err := elastic.EsCreateIndex(utils.MINI_REPORT_INDEX_NAME, mappingJson)
+	if err != nil {
+		fmt.Println(err)
+	}
+}