| @@ 128-160 (lines=33) @@ | ||
| 125 | /** |
|
| 126 | * @throws \Longman\LaravelLodash\ElasticSearch\ElasticSearchException |
|
| 127 | */ |
|
| 128 | public function addDocumentsToIndex(string $index_name, string $type_name, array $items) |
|
| 129 | { |
|
| 130 | if (! $this->isEnabled()) { |
|
| 131 | return; |
|
| 132 | } |
|
| 133 | ||
| 134 | $params = [ |
|
| 135 | 'body' => [], |
|
| 136 | ]; |
|
| 137 | ||
| 138 | if (! empty($this->timeout)) { |
|
| 139 | $params['client'] = [ |
|
| 140 | 'timeout' => $this->timeout, |
|
| 141 | ]; |
|
| 142 | } |
|
| 143 | ||
| 144 | foreach ($items as $id => $item) { |
|
| 145 | $params['body'][] = [ |
|
| 146 | 'create' => [ |
|
| 147 | '_index' => $index_name, |
|
| 148 | '_type' => $type_name, |
|
| 149 | '_id' => $id, |
|
| 150 | ], |
|
| 151 | ]; |
|
| 152 | ||
| 153 | $params['body'][] = $item; |
|
| 154 | } |
|
| 155 | ||
| 156 | $responses = $this->client->bulk($params); |
|
| 157 | if ($responses['errors'] === true) { |
|
| 158 | $this->handleBulkError($responses); |
|
| 159 | } |
|
| 160 | } |
|
| 161 | ||
| 162 | /** |
|
| 163 | * @throws \Longman\LaravelLodash\ElasticSearch\ElasticSearchException |
|
| @@ 165-197 (lines=33) @@ | ||
| 162 | /** |
|
| 163 | * @throws \Longman\LaravelLodash\ElasticSearch\ElasticSearchException |
|
| 164 | */ |
|
| 165 | public function updateDocumentsInIndex(string $index_name, string $type_name, array $items) |
|
| 166 | { |
|
| 167 | if (! $this->isEnabled()) { |
|
| 168 | return; |
|
| 169 | } |
|
| 170 | ||
| 171 | $params = [ |
|
| 172 | 'body' => [], |
|
| 173 | ]; |
|
| 174 | ||
| 175 | if (! empty($this->timeout)) { |
|
| 176 | $params['client'] = [ |
|
| 177 | 'timeout' => $this->timeout, |
|
| 178 | ]; |
|
| 179 | } |
|
| 180 | ||
| 181 | foreach ($items as $id => $item) { |
|
| 182 | $params['body'][] = [ |
|
| 183 | 'update' => [ |
|
| 184 | '_index' => $index_name, |
|
| 185 | '_type' => $type_name, |
|
| 186 | '_id' => $id, |
|
| 187 | ], |
|
| 188 | ]; |
|
| 189 | ||
| 190 | $params['body'][] = ['doc' => $item]; |
|
| 191 | } |
|
| 192 | ||
| 193 | $responses = $this->client->bulk($params); |
|
| 194 | if ($responses['errors'] === true) { |
|
| 195 | $this->handleBulkError($responses); |
|
| 196 | } |
|
| 197 | } |
|
| 198 | ||
| 199 | /** |
|
| 200 | * @throws \Longman\LaravelLodash\ElasticSearch\ElasticSearchException |
|