Skip to content

Commit 1278c5d

Browse files
committed
Fixed accidental wrong ES version
1 parent 9868508 commit 1278c5d

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"illuminate/container": "^5.8|^6.0",
2323
"illuminate/database": "^5.8|^6.0",
2424
"illuminate/events": "^5.8|^6.0",
25-
"elasticsearch/elasticsearch": "8.7"
25+
"elasticsearch/elasticsearch": "^7.16"
2626
},
2727
"autoload": {
2828
"psr-4": {

src/Connection.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PDPhilip\Elasticsearch;
44

55
use PDPhilip\Elasticsearch\DSL\Bridge;
6-
use Elastic\Elasticsearch\ClientBuilder;
6+
use Elasticsearch\ClientBuilder;
77
use Illuminate\Database\Connection as BaseConnection;
88
use Illuminate\Support\Arr;
99
use Illuminate\Support\Str;
@@ -142,15 +142,15 @@ protected function buildConnection()
142142
{
143143
$type = config('database.connections.elasticsearch.auth_type') ?? null;
144144
$type = strtolower($type);
145-
if (!in_array($type, ['https', 'cloud',])) {
145+
if (!in_array($type, ['http', 'cloud', 'api'])) {
146146
throw new RuntimeException('Invalid [auth_type] in database config. Must be: http, cloud or api');
147147
}
148148

149149
return $this->{'_'.$type.'Connection'}();
150150

151151
}
152152

153-
protected function _httpsConnection()
153+
protected function _httpConnection()
154154
{
155155
$hosts = config('database.connections.elasticsearch.hosts') ?? null;
156156
$username = config('database.connections.elasticsearch.username') ?? null;
@@ -161,7 +161,7 @@ protected function _httpsConnection()
161161
$cb->setBasicAuthentication($username, $pass)->build();
162162
}
163163
if ($certPath) {
164-
$cb->setCABundle($certPath);
164+
$cb->setSSLVerification($certPath);
165165
}
166166

167167
return $cb->build();
@@ -177,7 +177,7 @@ protected function _cloudConnection()
177177
$certPath = config('database.connections.elasticsearch.ssl_cert') ?? null;
178178
$cb = ClientBuilder::create()->setElasticCloudId($cloudId);
179179
if ($apiId && $apiKey) {
180-
$cb->setApiKey($apiKey, $apiId)->build();
180+
$cb->setApiKey($apiId, $apiKey)->build();
181181
} elseif ($username && $pass) {
182182
$cb->setBasicAuthentication($username, $pass)->build();
183183
}
@@ -189,6 +189,20 @@ protected function _cloudConnection()
189189
}
190190

191191

192+
protected function _apiConnection()
193+
{
194+
$apiId = config('database.connections.elasticsearch.api_id') ?? null;
195+
$apiKey = config('database.connections.elasticsearch.api_key') ?? null;
196+
$certPath = config('database.connections.elasticsearch.ssl_cert') ?? null;
197+
$cb = ClientBuilder::create()->setApiKey($apiId, $apiKey);
198+
if ($certPath) {
199+
$cb->setSSLVerification($certPath);
200+
}
201+
202+
return $cb->build();
203+
}
204+
205+
192206
//----------------------------------------------------------------------
193207
// Dynamic call routing to DSL bridge
194208
//----------------------------------------------------------------------

src/DSL/Bridge.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PDPhilip\Elasticsearch\DSL;
44

55
use Exception;
6-
use Elastic\Elasticsearch\Client;
6+
use Elasticsearch\Client;
77

88

99
class Bridge
@@ -294,13 +294,13 @@ public function processIncrementMany($wheres, $newValues, $options, $refresh): R
294294

295295
public function processDeleteAll($wheres, $options = []): Results
296296
{
297-
$params = [
298-
'index' => $this->index,
299-
'id' => $wheres['_id'],
300-
];
297+
301298

302299
if (isset($wheres['_id'])) {
303-
300+
$params = [
301+
'index' => $this->index,
302+
'id' => $wheres['_id'],
303+
];
304304
try {
305305
$response = $this->client->delete($params);
306306
$response['deleteCount'] = $response['result'] === 'deleted' ? 1 : 0;
@@ -317,7 +317,7 @@ public function processDeleteAll($wheres, $options = []): Results
317317

318318
return $this->_return($response['deleteCount'], $response, $params, $this->_queryTag(__FUNCTION__));
319319
} catch (Exception $e) {
320-
$error = $this->_returnError($e->getMessage(), $e->getCode(), $params, $this->_queryTag(__FUNCTION__));
320+
$error = $this->_returnError($e->getMessage(), $e->getCode(), [], $this->_queryTag(__FUNCTION__));
321321
throw new Exception($error->errorMessage);
322322
}
323323

@@ -370,7 +370,7 @@ public function processIndexMappings($index)
370370
$response = $this->client->indices()->getMapping($params);
371371
$result = $this->_return($response, $response, $params, $this->_queryTag(__FUNCTION__));
372372

373-
return $result->data->asArray();
373+
return $result->data;
374374
} catch (Exception $e) {
375375
$result = $this->_returnError($e->getMessage(), $e->getCode(), $params, $this->_queryTag(__FUNCTION__));
376376
throw new Exception($result->errorMessage);
@@ -387,7 +387,7 @@ public function processIndexSettings($index)
387387
$response = $this->client->indices()->getSettings($params);
388388
$result = $this->_return($response, $response, $params, $this->_queryTag(__FUNCTION__));
389389

390-
return $result->data->asArray();
390+
return $result->data;
391391
} catch (Exception $e) {
392392
$result = $this->_returnError($e->getMessage(), $e->getCode(), $params, $this->_queryTag(__FUNCTION__));
393393
throw new Exception($result->errorMessage);

0 commit comments

Comments
 (0)