File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 3
3
return [
4
4
'elasticsearch ' => [
5
5
'url ' => env ('ELASTICSEARCH_URL ' , 'http://localhost:9200 ' ),
6
+ 'port ' => env ('ELASTICSEARCH_PORT ' ),
7
+ 'api_key ' => env ('ELASTICSEARCH_API_KEY ' ),
6
8
],
7
9
];
Original file line number Diff line number Diff line change 2
2
3
3
namespace Olekjs \Elasticsearch ;
4
4
5
- use Illuminate \Contracts \Support \Jsonable ;
6
- use Illuminate \Support \Facades \Http ;
7
5
use Olekjs \Elasticsearch \Contracts \AbstractClient ;
8
6
use Olekjs \Elasticsearch \Contracts \BulkOperationInterface ;
9
7
use Olekjs \Elasticsearch \Contracts \ClientInterface ;
Original file line number Diff line number Diff line change 4
4
5
5
use Illuminate \Http \Client \PendingRequest ;
6
6
use Illuminate \Support \Facades \Http ;
7
+ use Illuminate \Support \Str ;
8
+ use Illuminate \Support \Stringable ;
7
9
use Olekjs \Elasticsearch \Exceptions \ConflictResponseException ;
8
10
use Olekjs \Elasticsearch \Exceptions \DeleteResponseException ;
9
11
use Olekjs \Elasticsearch \Exceptions \IndexNotFoundResponseException ;
@@ -17,9 +19,21 @@ abstract class AbstractClient
17
19
{
18
20
protected function getBaseClient (): PendingRequest
19
21
{
20
- return Http::acceptJson ()
22
+ $ apiKey = config ('services.elasticsearch.api_key ' );
23
+ $ port = config ('services.elasticsearch.port ' );
24
+
25
+ $ url = Str::of (config ('services.elasticsearch.url ' ))
26
+ ->when (!is_null ($ port ), fn (Stringable $ str ) => $ str ->append (': ' . $ port ));
27
+
28
+ $ http = Http::acceptJson ()
21
29
->asJson ()
22
- ->baseUrl (config ('services.elasticsearch.url ' ));
30
+ ->baseUrl ($ url );
31
+
32
+ if (!is_null ($ apiKey )) {
33
+ $ http ->withToken ($ apiKey , 'ApiKey ' );
34
+ }
35
+
36
+ return $ http ;
23
37
}
24
38
25
39
/**
You can’t perform that action at this time.
0 commit comments