-
Notifications
You must be signed in to change notification settings - Fork 2
Home
FF-Elastica-Manager
FF-Elastica-Manager is php library for creating, rotating, populating and managing ElasticSearch indexes using Elastica client library.
Some general info is already specified in package Readme page:
Use following steps to start using elastica manager
<?php
// Create Elastica_Client
$client = new Elastica_Client(array(
'servers' => array(
array(
'host' => '192.168.0.223',
'port' => 9200
)
)
));
// Create Elastica manager
$elasticaManager = new ElasticaManager($client);
Now you have to create Configuration and DataProvider classes for you index.
Some overview on what is required for these classes is described here
You will find ShopConfiguration and ShopDataProvider example classes in example directory.
Once you create these classes you can add them to elastica manager
<?php
// Create your index configuration with data provider
$provider = new ShopDataProvider();
$configuration = new ShopConfiguration($provider);
// Add configuration(s) to the manager
$elasticaManager->addConfiguration($configuration);
Now you have successfully setup ElasticaManager you can get IndexManager using following code:
<?php
$indexManager = $elasticaManager->getIndexManager('shop');
// or you could use configuration constant
$indexManager = $elasticaManager->getIndexManager(ShopConfiguration::NAME);
Note: If you want to use different name for your index, rather than configuration name, specify it as second parameter for getIndexManager()
<?php
$indexManager = $elasticaManager->getIndexManager(ShopConfiguration::NAME, 'custom_index_name');
Now you have $indexManager and you can start using it's methods
Following line will create new index or throw an exception if index will already exist
<?php
$index = $indexManager->create();
You can set $dropIfExists argument for create() to TRUE if you wish to avoid exception and drop existing index
<?php
$index = $indexManager->create(true);
<?php
$index = $indexManager->delete();
Note: Method will throw ElasticaManagerIndexNotFoundException
if index will not be found. Use next method indexExists() to verify before calling delete()
<?php
$index = $indexManager->indexExists();