Provides access to official Elasticsearch PHP API as a middleware implementation for ha framework. Automatically creates a client based on the configuration when it starts the application.
Installation is available via composer:
composer require itrnka/ha-elasticsearch-middleware
This package is based on ha framework. Composer installs ha framework and Elasticsearch PHP API automatically if it is not already installed.
Required configuration keys:
name
: by ha framework requirementshosts
: string[] list of elasticsearch hosts
Add your configuration to the configuration file in ha framework according to this example:
$cfg['middleware'] = [
// ...
// elasticsearch - single server
[
ha\Middleware\NoSQL\Elasticsearch\Elasticsearch::class,
[
'name' => 'ES001',
'hosts' => ['127.0.0.1:9200'],
]
],
// elasticsearch - multi server
[
ha\Middleware\NoSQL\Elasticsearch\Elasticsearch::class,
[
'name' => 'ES002',
'hosts' => ['10.10.10.1:9200', '10.10.10.2:9200'],
]
],
// ...
];
Then the elasticsearch will be available as follows:
// middleware instance
$es1 = main()->middleware->ES001;
$es2 = main()->middleware->ES002;
// es client (instance of \Elasticsearch\Client):
$es1Client = main()->middleware->ES001->driver();
$es2Client = main()->middleware->ES002->driver();
// or (this is the same)
$es1Client = main()->middleware->ES001->client();
$es2Client = main()->middleware->ES002->client();