|
2 | 2 |
|
3 | 3 | namespace Elastica; |
4 | 4 |
|
| 5 | +use Elastic\Elasticsearch\Exception\ClientResponseException; |
| 6 | +use Elastic\Elasticsearch\Exception\MissingParameterException; |
| 7 | +use Elastic\Elasticsearch\Exception\ServerResponseException; |
| 8 | +use Elastic\Transport\Exception\NoNodeAvailableException; |
5 | 9 | use Elastica\Bulk\Action; |
6 | 10 | use Elastica\Bulk\Action\AbstractDocument as AbstractDocumentAction; |
7 | 11 | use Elastica\Bulk\Response as BulkResponse; |
8 | 12 | use Elastica\Bulk\ResponseSet; |
9 | 13 | use Elastica\Exception\Bulk\ResponseException as BulkResponseException; |
10 | 14 | use Elastica\Exception\ClientException; |
11 | | -use Elastica\Exception\ConnectionException; |
12 | 15 | use Elastica\Exception\InvalidException; |
13 | 16 | use Elastica\Exception\RequestEntityTooLargeException; |
14 | | -use Elastica\Exception\ResponseException; |
15 | 17 | use Elastica\Script\AbstractScript; |
16 | 18 |
|
17 | 19 | class Bulk |
@@ -277,15 +279,22 @@ public function toArray(): array |
277 | 279 | } |
278 | 280 |
|
279 | 281 | /** |
280 | | - * @throws ClientException |
281 | | - * @throws ConnectionException |
282 | | - * @throws ResponseException |
| 282 | + * @throws MissingParameterException if a required parameter is missing |
| 283 | + * @throws NoNodeAvailableException if all the hosts are offline |
| 284 | + * @throws ClientResponseException if the status code of response is 4xx |
| 285 | + * @throws ServerResponseException if the status code of response is 5xx |
283 | 286 | * @throws BulkResponseException |
284 | | - * @throws InvalidException |
| 287 | + * @throws ClientException |
285 | 288 | */ |
286 | 289 | public function send(): ResponseSet |
287 | 290 | { |
288 | | - $response = $this->_client->request($this->getPath(), Request::POST, (string) $this, $this->_requestParams, Request::NDJSON_CONTENT_TYPE); |
| 291 | + $params = ['body' => (string) $this]; |
| 292 | + |
| 293 | + if ($this->hasIndex()) { |
| 294 | + $params['index'] = $this->getIndex(); |
| 295 | + } |
| 296 | + |
| 297 | + $response = $this->_client->baseBulk(\array_merge($params, $this->_requestParams)); |
289 | 298 |
|
290 | 299 | return $this->_processResponse($response); |
291 | 300 | } |
|
0 commit comments