正在显示
1 个修改的文件
包含
10 行增加
和
2 行删除
| @@ -107,7 +107,7 @@ class Es { | @@ -107,7 +107,7 @@ class Es { | ||
| 107 | * @author:dc | 107 | * @author:dc |
| 108 | * @time 2025/3/4 9:47 | 108 | * @time 2025/3/4 9:47 |
| 109 | */ | 109 | */ |
| 110 | - public function count(array $body){ | 110 | + public function count(array $body, $throw = false){ |
| 111 | 111 | ||
| 112 | $params = [ | 112 | $params = [ |
| 113 | 'index' => $this->getIndex(), | 113 | 'index' => $this->getIndex(), |
| @@ -119,11 +119,19 @@ class Es { | @@ -119,11 +119,19 @@ class Es { | ||
| 119 | $response = $this->client->count($params); | 119 | $response = $this->client->count($params); |
| 120 | $this->timeLog($staTime,$params); | 120 | $this->timeLog($staTime,$params); |
| 121 | }catch (\Throwable $e) { | 121 | }catch (\Throwable $e) { |
| 122 | + if($throw){ | ||
| 123 | + throw $e; | ||
| 124 | + } | ||
| 122 | logs("搜索数据es:".$e->getMessage()." \n ".json_encode($params)."\n".$e->getTraceAsString()); | 125 | logs("搜索数据es:".$e->getMessage()." \n ".json_encode($params)."\n".$e->getTraceAsString()); |
| 123 | return 0; | 126 | return 0; |
| 124 | } | 127 | } |
| 128 | + $ret = $response->asArray(); | ||
| 129 | + | ||
| 130 | + if(!isset($ret['count'])){ | ||
| 131 | + return -1; | ||
| 132 | + } | ||
| 125 | 133 | ||
| 126 | - return $response->asArray()['count']??0; | 134 | + return $ret['count']; |
| 127 | } | 135 | } |
| 128 | 136 | ||
| 129 | 137 |
-
请 注册 或 登录 后发表评论