Skip to content
darklow edited this page Oct 23, 2012 · 18 revisions

FF-Elastica-Manager

FF Elastica Manager docs

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:

Documentation

Getting started

Use following steps to start using elastica manager

1) Create Elastica_Client and ElasticaManager

<?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);

2) Configuration and DataProvider classes

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);

3) Get IndexManager

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

Methods

Create index

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);

Delete index

<?php
$index = $indexManager->delete();

Note: Method will throw ElasticaManagerIndexNotFoundException if index will not be found. Use next method indexExists() to verify before calling delete()

Index Exists

<?php
$index = $indexManager->indexExists();