task.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package services
  2. import (
  3. "eta/eta_mini_crm/services/elastic"
  4. "eta/eta_mini_crm/utils"
  5. "fmt"
  6. )
  7. func InitTask() {
  8. fmt.Println("start task")
  9. CreateIndex()
  10. fmt.Println("end task!")
  11. }
  12. func CreateIndex() {
  13. var mappingJson = `{
  14. "mappings": {
  15. "properties": {
  16. "ReportPdfId": {"type": "integer"},
  17. "PdfUrl": {"type": "text"},
  18. "PdfName": {"type": "text"},
  19. "Title": {"type": "text"},
  20. "Author": {"type": "text"},
  21. "Abstract": {"type": "text"},
  22. "ClassifyIdFirst": {"type": "integer"},
  23. "ClassifyNameFirst": {"type": "text"},
  24. "ClassifyIdSecond": {"type": "integer"},
  25. "ClassifyNameSecond": {"type": "text"},
  26. "Stage": {"type": "integer"},
  27. "PublishTime": {
  28. "type": "text",
  29. "fields": {
  30. "keyword": {
  31. "type": "keyword",
  32. "ignore_above": 256
  33. }
  34. }
  35. },
  36. "ModifyTime": {"type": "date"},
  37. "Pv": {"type": "integer"},
  38. "Uv": {"type": "integer"},
  39. "SysUserId": {"type": "integer"},
  40. "SysRealName": {"type": "text"},
  41. "State": {"type": "integer"}
  42. }
  43. }
  44. }`
  45. err := elastic.EsCreateIndex(utils.MINI_REPORT_INDEX_NAME, mappingJson)
  46. if err != nil {
  47. fmt.Println(err)
  48. }
  49. }