Skip to content

Elasticsearch client middleware implementation for ha framework based on official elasticsearch PHP API.

License

Notifications You must be signed in to change notification settings

itrnka/ha-elasticsearch-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elasticsearch for ha framework

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

Installation is available via composer:

composer require itrnka/ha-elasticsearch-middleware

Requirements

This package is based on ha framework. Composer installs ha framework and Elasticsearch PHP API automatically if it is not already installed.

Configuration

Required configuration keys:

  • name: by ha framework requirements
  • hosts: 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();

About

Elasticsearch client middleware implementation for ha framework based on official elasticsearch PHP API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages