This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Transport : connect to the ES server and get your client
scharrier edited this page Jul 19, 2012
·
2 revisions
The transport part of the application is, in fact, a mix between the transport and the client layers : because we wanted something simple to use, we prefered something with less complex calls.
So, this is the transport layer witch will give you the client you will use for each request. A client can be linked to :
- only an host, giving you the ability to request on every index, on every type
- an host and an index, giving you the ability to request on every type
- an host, an index and a type
You can use the static Simples class to get your client :
// Get a client. Note that you can use Simples::current() to get your current connection later.
$client = Simples::connect(array(
'host' => 'your.host.net', // Default : localhost
'port' => '9200', // The ES server port. Default : 9200
'index' => 'your.index', // Optionnal : it can be specified in each request
'type' => 'your.type' // Optionnal : it can be specified in each request
'protocol' => 'http', // The transport protocol to use. Actually, only "http" is supported
'timeout' => 1000, // Timeout of the connection, in milliseconds. Default : 1000
'check' => true // Check the server before anything on each connection. Default : true
));
If you use this, Simples will keep your client in memory and you will be able to get it back everywhere in your code, calling Simples::current().
If you want multiple connections, you can call Simples::client(array $options) which is the clients factory, or instanciate the transport class directly :
// This ...
$client = new Simples_Transport_Http(array('host' => 'my.host')) ;
// ... is equivalent to :
$client = Simples::client(array('protocol' => 'http', 'host' => 'my.host')) ;