| 
...
 | 
...
 | 
@@ -190,24 +190,14 @@ class SyncToEsCmd { | 
| 
 | 
 | 
     public $checkEsIndex = [];
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 同步数据到es
 | 
| 
 | 
 | 
      * @param string $index 索引名称
 | 
| 
 | 
 | 
      * @param int $data_id list表的id
 | 
| 
 | 
 | 
      * @param string $doc_id es文档id
 | 
| 
 | 
 | 
      * @param array $data es数据
 | 
| 
 | 
 | 
      * @author:dc
 | 
| 
 | 
 | 
      * @time 2025/8/5 10:09
 | 
| 
 | 
 | 
      */
 | 
| 
 | 
 | 
     public function toDataEs($index,$data_id,$doc_id,$data){
 | 
| 
 | 
 | 
 //        echo $index;
 | 
| 
 | 
 | 
 //        echo ' ==== ';
 | 
| 
 | 
 | 
     public function setEsMap($index){
 | 
| 
 | 
 | 
         $this->es->setIndex($index);
 | 
| 
 | 
 | 
         // 检查数据库是否存在
 | 
| 
 | 
 | 
         if(empty($this->checkEsIndex[$index])){
 | 
| 
 | 
 | 
             if(!$this->es->getMapping()){
 | 
| 
 | 
 | 
                 $map = $this->es->putMapping([
 | 
| 
 | 
 | 
         if($this->es->getMapping()){
 | 
| 
 | 
 | 
            return true;
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         if(redis()->add('setmaplock:'.$index,1,20)){
 | 
| 
 | 
 | 
             return $this->es->putMapping([
 | 
| 
 | 
 | 
                 'properties' => [
 | 
| 
 | 
 | 
                     'subject' => ['type' => 'text'],
 | 
| 
 | 
 | 
                     'from' => [
 | 
| 
...
 | 
...
 | 
@@ -253,8 +243,29 @@ class SyncToEsCmd { | 
| 
 | 
 | 
                 'number_of_replicas' => 0, // 设置副本数 暂用内存 主片+副片*
 | 
| 
 | 
 | 
             ]
 | 
| 
 | 
 | 
             );
 | 
| 
 | 
 | 
                 _echo("{$index} 创建索引 ".$map);
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
         // 暂停1秒在试
 | 
| 
 | 
 | 
         sleep(1);
 | 
| 
 | 
 | 
         return $this->setEsMap($index);
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 同步数据到es
 | 
| 
 | 
 | 
      * @param string $index 索引名称
 | 
| 
 | 
 | 
      * @param int $data_id list表的id
 | 
| 
 | 
 | 
      * @param string $doc_id es文档id
 | 
| 
 | 
 | 
      * @param array $data es数据
 | 
| 
 | 
 | 
      * @author:dc
 | 
| 
 | 
 | 
      * @time 2025/8/5 10:09
 | 
| 
 | 
 | 
      */
 | 
| 
 | 
 | 
     public function toDataEs($index,$data_id,$doc_id,$data){
 | 
| 
 | 
 | 
 //        echo $index;
 | 
| 
 | 
 | 
 //        echo ' ==== ';
 | 
| 
 | 
 | 
         $this->es->setIndex($index);
 | 
| 
 | 
 | 
         // 检查数据库是否存在
 | 
| 
 | 
 | 
         if(empty($this->checkEsIndex[$index])){
 | 
| 
 | 
 | 
             _echo("{$index} 创建索引 ".$this->setEsMap($index));
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
         // 下次不在检查
 | 
| 
 | 
 | 
         $this->checkEsIndex[$index] = 1;
 | 
...
 | 
...
 | 
 |