正在显示
1 个修改的文件
包含
60 行增加
和
49 行删除
| @@ -190,6 +190,65 @@ class SyncToEsCmd { | @@ -190,6 +190,65 @@ class SyncToEsCmd { | ||
| 190 | public $checkEsIndex = []; | 190 | public $checkEsIndex = []; |
| 191 | 191 | ||
| 192 | 192 | ||
| 193 | + public function setEsMap($index){ | ||
| 194 | + $this->es->setIndex($index); | ||
| 195 | + if($this->es->getMapping()){ | ||
| 196 | + return true; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + if(redis()->add('setmaplock:'.$index,1,20)){ | ||
| 200 | + return $this->es->putMapping([ | ||
| 201 | + 'properties' => [ | ||
| 202 | + 'subject' => ['type' => 'text'], | ||
| 203 | + 'from' => [ | ||
| 204 | + 'type' => 'object', // 定义 from 字段为对象 | ||
| 205 | + 'properties' => [ | ||
| 206 | + 'name' => [ | ||
| 207 | + 'type' => 'keyword' // 或者 'keyword',根据需求选择 | ||
| 208 | + ], | ||
| 209 | + 'email' => [ | ||
| 210 | + 'type' => 'text' // email 通常使用 keyword 类型 | ||
| 211 | + ] | ||
| 212 | + ] | ||
| 213 | + ], | ||
| 214 | + 'to' => ['type' => 'text'], | ||
| 215 | + 'cc' => ['type' => 'keyword'], | ||
| 216 | + 'bcc' => ['type' => 'keyword'], | ||
| 217 | + 'uid' => ['type' => 'integer'], | ||
| 218 | + 'udate' => ['type' => 'integer'], | ||
| 219 | + 'folder_id' => ['type' => 'integer'], | ||
| 220 | + 'email_id' => ['type' => 'integer'], | ||
| 221 | + 'size' => ['type' => 'integer'], | ||
| 222 | + 'recent' => ['type' => 'integer'], | ||
| 223 | + 'flagged' => ['type' => 'integer'], | ||
| 224 | + 'deleted' => ['type' => 'integer'], | ||
| 225 | + 'seen' => ['type' => 'integer'], | ||
| 226 | + 'draft' => ['type' => 'integer'], | ||
| 227 | + 'is_file' => ['type' => 'integer'], | ||
| 228 | + 'is_hots' => ['type' => 'integer'], | ||
| 229 | + 'is_auto' => ['type' => 'integer'], | ||
| 230 | + 'folder_as_int' => ['type' => 'integer'], | ||
| 231 | + 'postid' => ['type' => 'integer'], | ||
| 232 | + 'source' => ['type' => 'integer'], | ||
| 233 | + 'created_at' => ['type' => 'date'], | ||
| 234 | + 'updated_at' => ['type' => 'date'], | ||
| 235 | + 'description' => ['type' => 'keyword'], | ||
| 236 | + 'references' => ['type' => 'keyword'] | ||
| 237 | + ] | ||
| 238 | + ],$index == 'email_lists_copy' ? [ | ||
| 239 | + 'number_of_shards' => 21, // 设置分片数 | ||
| 240 | + 'number_of_replicas' => 1, // 设置副本数 暂用内存 主片+副片* | ||
| 241 | + ]:[ | ||
| 242 | + 'number_of_shards' => 1, // 设置分片数 | ||
| 243 | + 'number_of_replicas' => 0, // 设置副本数 暂用内存 主片+副片* | ||
| 244 | + ] | ||
| 245 | + ); | ||
| 246 | + } | ||
| 247 | + // 暂停1秒在试 | ||
| 248 | + sleep(1); | ||
| 249 | + return $this->setEsMap($index); | ||
| 250 | + } | ||
| 251 | + | ||
| 193 | 252 | ||
| 194 | /** | 253 | /** |
| 195 | * 同步数据到es | 254 | * 同步数据到es |
| @@ -206,55 +265,7 @@ class SyncToEsCmd { | @@ -206,55 +265,7 @@ class SyncToEsCmd { | ||
| 206 | $this->es->setIndex($index); | 265 | $this->es->setIndex($index); |
| 207 | // 检查数据库是否存在 | 266 | // 检查数据库是否存在 |
| 208 | if(empty($this->checkEsIndex[$index])){ | 267 | if(empty($this->checkEsIndex[$index])){ |
| 209 | - if(!$this->es->getMapping()){ | ||
| 210 | - $map = $this->es->putMapping([ | ||
| 211 | - 'properties' => [ | ||
| 212 | - 'subject' => ['type' => 'text'], | ||
| 213 | - 'from' => [ | ||
| 214 | - 'type' => 'object', // 定义 from 字段为对象 | ||
| 215 | - 'properties' => [ | ||
| 216 | - 'name' => [ | ||
| 217 | - 'type' => 'keyword' // 或者 'keyword',根据需求选择 | ||
| 218 | - ], | ||
| 219 | - 'email' => [ | ||
| 220 | - 'type' => 'text' // email 通常使用 keyword 类型 | ||
| 221 | - ] | ||
| 222 | - ] | ||
| 223 | - ], | ||
| 224 | - 'to' => ['type' => 'text'], | ||
| 225 | - 'cc' => ['type' => 'keyword'], | ||
| 226 | - 'bcc' => ['type' => 'keyword'], | ||
| 227 | - 'uid' => ['type' => 'integer'], | ||
| 228 | - 'udate' => ['type' => 'integer'], | ||
| 229 | - 'folder_id' => ['type' => 'integer'], | ||
| 230 | - 'email_id' => ['type' => 'integer'], | ||
| 231 | - 'size' => ['type' => 'integer'], | ||
| 232 | - 'recent' => ['type' => 'integer'], | ||
| 233 | - 'flagged' => ['type' => 'integer'], | ||
| 234 | - 'deleted' => ['type' => 'integer'], | ||
| 235 | - 'seen' => ['type' => 'integer'], | ||
| 236 | - 'draft' => ['type' => 'integer'], | ||
| 237 | - 'is_file' => ['type' => 'integer'], | ||
| 238 | - 'is_hots' => ['type' => 'integer'], | ||
| 239 | - 'is_auto' => ['type' => 'integer'], | ||
| 240 | - 'folder_as_int' => ['type' => 'integer'], | ||
| 241 | - 'postid' => ['type' => 'integer'], | ||
| 242 | - 'source' => ['type' => 'integer'], | ||
| 243 | - 'created_at' => ['type' => 'date'], | ||
| 244 | - 'updated_at' => ['type' => 'date'], | ||
| 245 | - 'description' => ['type' => 'keyword'], | ||
| 246 | - 'references' => ['type' => 'keyword'] | ||
| 247 | - ] | ||
| 248 | - ],$index == 'email_lists_copy' ? [ | ||
| 249 | - 'number_of_shards' => 21, // 设置分片数 | ||
| 250 | - 'number_of_replicas' => 1, // 设置副本数 暂用内存 主片+副片* | ||
| 251 | - ]:[ | ||
| 252 | - 'number_of_shards' => 1, // 设置分片数 | ||
| 253 | - 'number_of_replicas' => 0, // 设置副本数 暂用内存 主片+副片* | ||
| 254 | - ] | ||
| 255 | - ); | ||
| 256 | - _echo("{$index} 创建索引 ".$map); | ||
| 257 | - } | 268 | + _echo("{$index} 创建索引 ".$this->setEsMap($index)); |
| 258 | } | 269 | } |
| 259 | // 下次不在检查 | 270 | // 下次不在检查 |
| 260 | $this->checkEsIndex[$index] = 1; | 271 | $this->checkEsIndex[$index] = 1; |
-
请 注册 或 登录 后发表评论