@@ -26,7 +26,7 @@ $hosts = [
26
26
'https://localhost', // SSL to localhost
27
27
'https://192.168.1.3:9200' // SSL to IP + Port
28
28
];
29
- $client = ClientBuilder::create() // Instantiate a new ClientBuilder
29
+ $client = ClientBuilder::create() // Instantiate a new ClientBuilder
30
30
->setHosts($hosts) // Set the hosts
31
31
->build(); // Build the client object
32
32
----
@@ -44,8 +44,8 @@ $hosts = [
44
44
'https://localhost', // SSL to localhost
45
45
'https://192.168.1.3:9200' // SSL to IP + Port
46
46
];
47
- $clientBuilder = ClientBuilder::create(); // Instantiate a new ClientBuilder
48
- $clientBuilder->setHosts($hosts) // Set the hosts
47
+ $clientBuilder = ClientBuilder::create(); // Instantiate a new ClientBuilder
48
+ $clientBuilder->setHosts($hosts); // Set the hosts
49
49
$client = $clientBuilder->build(); // Build the client object
50
50
----
51
51
@@ -70,14 +70,16 @@ $client = ClientBuilder::create()
70
70
=== Enabling the Logger
71
71
Elasticsearch-PHP supports logging, but it is not enabled by default for performance reasons. If you wish to enable logging,
72
72
you need to select a logging implementation, install it, then enable the logger in the Client. The recommended logger
73
- is https://github.com/Seldaek/monolog[Monolog], but any logger that implements the PSR/Log interface will work.
73
+ is https://github.com/Seldaek/monolog[Monolog], but any logger that implements the ` PSR/Log` interface will work.
74
74
75
75
You might have noticed that Monolog was suggested during installation. To begin using Monolog, add it to your `composer.json`:
76
76
77
77
[source,json]
78
78
----------------------------
79
79
{
80
80
"require": {
81
+ ...
82
+ "elasticsearch/elasticsearch" : "~2.0",
81
83
"monolog/monolog": "~1.0"
82
84
}
83
85
}
@@ -98,7 +100,7 @@ to do is provide the path to your desired logging location:
98
100
----
99
101
$logger = ClientBuilder::defaultLogger('path/to/your.log');
100
102
101
- $client = ClientBuilder::create() // Instantiate a new ClientBuilder
103
+ $client = ClientBuilder::create() // Instantiate a new ClientBuilder
102
104
->setLogger($logger) // Set the logger with a default logger
103
105
->build(); // Build the client object
104
106
----
@@ -107,9 +109,10 @@ You can also specify the severity of log messages that you wish to log:
107
109
108
110
[source,php]
109
111
----
110
- $logger = ClientBuilder::defaultLogger('/path/to/logs/', Logger::INFO); // set severity with second parameter
112
+ // set severity with second parameter
113
+ $logger = ClientBuilder::defaultLogger('/path/to/logs/', Logger::INFO);
111
114
112
- $client = ClientBuilder::create() // Instantiate a new ClientBuilder
115
+ $client = ClientBuilder::create() // Instantiate a new ClientBuilder
113
116
->setLogger($logger) // Set the logger with a default logger
114
117
->build(); // Build the client object
115
118
----
@@ -126,7 +129,7 @@ use Monolog\Handler\StreamHandler;
126
129
$logger = new Logger('name');
127
130
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
128
131
129
- $client = ClientBuilder::create() // Instantiate a new ClientBuilder
132
+ $client = ClientBuilder::create() // Instantiate a new ClientBuilder
130
133
->setLogger($logger) // Set your custom logger
131
134
->build(); // Build the client object
132
135
----
@@ -172,12 +175,13 @@ Connection pools are configured via the `setConnectionPool()` method:
172
175
173
176
[source,php]
174
177
----
178
+ $connectionPool = '\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool';
175
179
$client = ClientBuilder::create()
176
- ->setConnectionPool('\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool' )
180
+ ->setConnectionPool($connectionPool )
177
181
->build();
178
182
----
179
183
180
- For more details, please see the dedicated page on link:_connection-pool .html[configuring connection pools].
184
+ For more details, please see the dedicated page on link:_connection_pool .html[configuring connection pools].
181
185
182
186
=== Setting the Connection Selector
183
187
@@ -187,8 +191,9 @@ via the `setSelector()` method:
187
191
188
192
[source,php]
189
193
----
194
+ $selector = '\Elasticsearch\ConnectionPool\Selectors\StickyRoundRobinSelector';
190
195
$client = ClientBuilder::create()
191
- ->setSelector('\Elasticsearch\ConnectionPool\Selectors\StickyRoundRobinSelector' )
196
+ ->setSelector($selector )
192
197
->build();
193
198
----
194
199
@@ -206,8 +211,9 @@ it can be done via the `setSerializer()` method:
206
211
207
212
[source,php]
208
213
----
214
+ $serializer = '\Elasticsearch\Serializers\SmartSerializer';
209
215
$client = ClientBuilder::create()
210
- ->setSerializer('\Elasticsearch\Serializers\SmartSerializer' )
216
+ ->setSerializer($serializer )
211
217
->build();
212
218
----
213
219
@@ -230,10 +236,15 @@ interface.
230
236
class MyConnectionFactory implements ConnectionFactoryInterface
231
237
{
232
238
233
- public function __construct($handler, array $connectionParams, SerializerInterface $serializer, LoggerInterface $logger, LoggerInterface $tracer)
239
+ public function __construct($handler, array $connectionParams,
240
+ SerializerInterface $serializer,
241
+ LoggerInterface $logger,
242
+ LoggerInterface $tracer)
234
243
{
235
244
// Code here
236
245
}
246
+
247
+
237
248
/**
238
249
* @param $hostDetails
239
250
*
@@ -246,10 +257,16 @@ class MyConnectionFactory implements ConnectionFactoryInterface
246
257
}
247
258
248
259
249
- $connectionFactory = new MyConnectionFactory($handler, $connectionParams, $serializer, $logger, $tracer);
260
+ $connectionFactory = new MyConnectionFactory(
261
+ $handler,
262
+ $connectionParams,
263
+ $serializer,
264
+ $logger,
265
+ $tracer
266
+ );
250
267
251
268
$client = ClientBuilder::create()
252
- ->setSerializer ($connectionFactory);
269
+ ->setConnectionFactory ($connectionFactory);
253
270
->build();
254
271
----
255
272
0 commit comments