CESinit.Class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * ElasticSearch 初始化脚本
  4. * Created by PhpStorm.
  5. * User: phperstar
  6. * Date: 2019/2/23
  7. * Time: 2:04 PM
  8. */
  9. namespace Jobs\Controller;
  10. use Mall\Framework\Factory;
  11. use Mall\Framework\Core\Request;
  12. class CESinit
  13. {
  14. /**
  15. * Search Demo
  16. */
  17. public function search()
  18. {
  19. $data = Request::params();
  20. $c = $data['b'] ?: 1;
  21. switch ($c) {
  22. // 添加wms日志索引库
  23. case 1 :
  24. $mappings = array(
  25. 'mappings' => array(
  26. "_default_" => [
  27. "properties" => [
  28. 'userId' => ['type' => 'integer'],
  29. "userName" => [
  30. "type" => "text",
  31. "store" => false,
  32. "analyzer" => "ik_max_word",
  33. "search_analyzer" => "ik_max_word",
  34. "boost" => 10
  35. ],
  36. 'object' => ['type' => 'keyword'],
  37. 'actionType' => ['type' => 'keyword'],
  38. "logContent" => [
  39. "type" => "text",
  40. "store" => false,
  41. "analyzer" => "ik_max_word",
  42. "search_analyzer" => "ik_max_word",
  43. "boost" => 5
  44. ],
  45. 'time' => ['type' => 'integer'],
  46. ]
  47. ]
  48. )
  49. );
  50. $searchServer = Factory::search('wms');
  51. $result = $searchServer->createBase('dev_wms_operation_log', $mappings);
  52. if ($result && !isset($result['error'])) {
  53. echo 'dev_wms_operation_log init done.';
  54. return true;
  55. } else {
  56. print_r($result['error']);
  57. return false;
  58. }
  59. break;
  60. // 删除wms索引库
  61. case 2:
  62. $searchServer = Factory::search('wms');
  63. $searchServer->setIndex('dev_wms_operation_log');
  64. $a = $searchServer->deleteBase('dev_wms_operation_log');
  65. print_r($a);
  66. break;
  67. // 添加oms订单状态日志索引库
  68. case 3 :
  69. $mappings = array(
  70. 'mappings' => array(
  71. "_default_" => [
  72. "properties" => [
  73. 'orderNo' => ['type' => 'keyword'],
  74. 'status' => ['type' => 'integer'],
  75. 'operationUserName' => ['type' => 'keyword'],
  76. 'time' => ['type' => 'integer'],
  77. ]
  78. ]
  79. )
  80. );
  81. $searchServer = Factory::search('wms');
  82. $result = $searchServer->createBase('dev_oms_orderstatus_log', $mappings);
  83. if ($result && !isset($result['error'])) {
  84. echo 'dev_oms_orderstatus_log init done.';
  85. return true;
  86. } else {
  87. print_r($result['error']);
  88. return false;
  89. }
  90. break;
  91. // 删除oms订单状态索引库
  92. case 4:
  93. $searchServer = Factory::search('wms');
  94. $searchServer->setIndex('dev_oms_orderstatus_log');
  95. $a = $searchServer->deleteBase('dev_oms_orderstatus_log');
  96. print_r($a);
  97. break;
  98. // 添加capital日志索引库
  99. case 5 :
  100. $mappings = array(
  101. 'mappings' => array(
  102. "_default_" => [
  103. "properties" => [
  104. 'userId' => ['type' => 'integer'],
  105. "userName" => [
  106. "type" => "text",
  107. ],
  108. 'object' => ['type' => 'keyword'],
  109. 'actionType' => ['type' => 'keyword'],
  110. "logContent" => [
  111. "type" => "text",
  112. "store" => false,
  113. "analyzer" => "ik_max_word",
  114. "search_analyzer" => "ik_max_word",
  115. "boost" => 5
  116. ],
  117. 'time' => ['type' => 'integer'],
  118. ]
  119. ]
  120. )
  121. );
  122. $searchServer = Factory::search('capital');
  123. $result = $searchServer->createBase('dev_capital_operation_log', $mappings);
  124. if ($result && !isset($result['error'])) {
  125. echo 'dev_capital_operation_log init done.';
  126. return true;
  127. } else {
  128. print_r($result['error']);
  129. return false;
  130. }
  131. break;
  132. // 删除wms索引库
  133. case 6:
  134. $searchServer = Factory::search('capital');
  135. $searchServer->setIndex('dev_capital_operation_log');
  136. $a = $searchServer->deleteBase('dev_capital_operation_log');
  137. print_r($a);
  138. break;
  139. // 添加oms日志索引库
  140. case 7 :
  141. $mappings = array(
  142. 'mappings' => array(
  143. "_default_" => [
  144. "properties" => [
  145. 'userId' => ['type' => 'integer'],
  146. "userName" => [
  147. "type" => "text",
  148. ],
  149. 'object' => ['type' => 'keyword'],
  150. 'actionType' => ['type' => 'keyword'],
  151. "logContent" => [
  152. "type" => "text",
  153. "store" => false,
  154. "analyzer" => "ik_max_word",
  155. "search_analyzer" => "ik_max_word",
  156. "boost" => 5
  157. ],
  158. 'time' => ['type' => 'integer'],
  159. ]
  160. ]
  161. )
  162. );
  163. $searchServer = Factory::search('oms');
  164. $result = $searchServer->createBase('dev_oms_operation_log', $mappings);
  165. if ($result && !isset($result['error'])) {
  166. echo 'dev_oms_operation_log init done.';
  167. return true;
  168. } else {
  169. print_r($result['error']);
  170. return false;
  171. }
  172. break;
  173. // 删除wms索引库
  174. case 8:
  175. $searchServer = Factory::search('oms');
  176. $searchServer->setIndex('dev_oms_operation_log');
  177. $a = $searchServer->deleteBase('dev_oms_operation_log');
  178. print_r($a);
  179. break;
  180. }
  181. }
  182. }