正在显示
1 个修改的文件
包含
29 行增加
和
18 行删除
| @@ -190,24 +190,14 @@ class SyncToEsCmd { | @@ -190,24 +190,14 @@ class SyncToEsCmd { | ||
| 190 | public $checkEsIndex = []; | 190 | public $checkEsIndex = []; |
| 191 | 191 | ||
| 192 | 192 | ||
| 193 | - | ||
| 194 | - /** | ||
| 195 | - * 同步数据到es | ||
| 196 | - * @param string $index 索引名称 | ||
| 197 | - * @param int $data_id list表的id | ||
| 198 | - * @param string $doc_id es文档id | ||
| 199 | - * @param array $data es数据 | ||
| 200 | - * @author:dc | ||
| 201 | - * @time 2025/8/5 10:09 | ||
| 202 | - */ | ||
| 203 | - public function toDataEs($index,$data_id,$doc_id,$data){ | ||
| 204 | -// echo $index; | ||
| 205 | -// echo ' ==== '; | 193 | + public function setEsMap($index){ |
| 206 | $this->es->setIndex($index); | 194 | $this->es->setIndex($index); |
| 207 | - // 检查数据库是否存在 | ||
| 208 | - if(empty($this->checkEsIndex[$index])){ | ||
| 209 | - if(!$this->es->getMapping()){ | ||
| 210 | - $map = $this->es->putMapping([ | 195 | + if($this->es->getMapping()){ |
| 196 | + return true; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + if(redis()->add('setmaplock:'.$index,1,20)){ | ||
| 200 | + return $this->es->putMapping([ | ||
| 211 | 'properties' => [ | 201 | 'properties' => [ |
| 212 | 'subject' => ['type' => 'text'], | 202 | 'subject' => ['type' => 'text'], |
| 213 | 'from' => [ | 203 | 'from' => [ |
| @@ -253,8 +243,29 @@ class SyncToEsCmd { | @@ -253,8 +243,29 @@ class SyncToEsCmd { | ||
| 253 | 'number_of_replicas' => 0, // 设置副本数 暂用内存 主片+副片* | 243 | 'number_of_replicas' => 0, // 设置副本数 暂用内存 主片+副片* |
| 254 | ] | 244 | ] |
| 255 | ); | 245 | ); |
| 256 | - _echo("{$index} 创建索引 ".$map); | ||
| 257 | } | 246 | } |
| 247 | + // 暂停1秒在试 | ||
| 248 | + sleep(1); | ||
| 249 | + return $this->setEsMap($index); | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + | ||
| 253 | + /** | ||
| 254 | + * 同步数据到es | ||
| 255 | + * @param string $index 索引名称 | ||
| 256 | + * @param int $data_id list表的id | ||
| 257 | + * @param string $doc_id es文档id | ||
| 258 | + * @param array $data es数据 | ||
| 259 | + * @author:dc | ||
| 260 | + * @time 2025/8/5 10:09 | ||
| 261 | + */ | ||
| 262 | + public function toDataEs($index,$data_id,$doc_id,$data){ | ||
| 263 | +// echo $index; | ||
| 264 | +// echo ' ==== '; | ||
| 265 | + $this->es->setIndex($index); | ||
| 266 | + // 检查数据库是否存在 | ||
| 267 | + if(empty($this->checkEsIndex[$index])){ | ||
| 268 | + _echo("{$index} 创建索引 ".$this->setEsMap($index)); | ||
| 258 | } | 269 | } |
| 259 | // 下次不在检查 | 270 | // 下次不在检查 |
| 260 | $this->checkEsIndex[$index] = 1; | 271 | $this->checkEsIndex[$index] = 1; |
-
请 注册 或 登录 后发表评论