2017 © Pedro Peláez
 

library ff-elastica-manager

Elastica manager for creating, rotating, populating and managing ElasticSearch indexes using Elastica client library

image

darklow/ff-elastica-manager

Elastica manager for creating, rotating, populating and managing ElasticSearch indexes using Elastica client library

  • Tuesday, November 19, 2013
  • by darklow
  • Repository
  • 2 Watchers
  • 2 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

FF-Elastica-Manager

FF-Elastica-Manager is php library for creating, rotating, populating and managing ElasticSearch indexes using Elastica client library., (*1)

Work in progress

This package is still under development, however these features are already implemented, (*2)

Features

  • Index creation with user config and mapping
  • Index data population using data provider
  • One document update/insert/delete
  • Index utils: delete, indexExists, addAlias, removeAlias
  • Iterator. Batch iterator iterates through index data (using ES scan/scroll functionality) and performs user specified closure
  • Examples: ShopConfiguration.php, ShopDataProvider.php Go to example directory

Todo: Index copy/clone, index rotate (copy and change alias), Symfony2 Console component commands, (*3)

Installation

The recommended way to install package is through composer. Create a composer.json in your project root-directory:, (*4)

{
    "require": {
        "darklow/ff-elastica-manager": "*"
    }
}

and run curl -s http://getcomposer.org/installer | php to get composer or run php composer.phar install to install package, (*5)

Overview

ElasticaManager package contains of following classes:, (*6)

  1. ElasticaManager - working with indexes and elasticsearch server
  2. IndexManager - create, delete, manage specific index
  3. Batch Iterator - iterates through index data (using ES scan/scroll functionality) and performs user specified closure

For every index you want to manage, you have to create two classes:, (*7)

  1. Configuration - Configuration class which provides necessary info for ElasticSearch index:, (*8)

    • Index default name - default name of the index (can be overridden on IndexManager initiation)
    • Index default alias name
    • Index types - ElasticSearch index type name(s)
    • Index configuration - number of shards and replicas, analysis analyzers and filters
    • Mapping properties - fields and its types for each/all ElasticSearch type
    • Mapping params - params like _all => [ enabled => false] and so on
  2. DataProvider - Data provider class which provides all the data needed to populate whole index or just one document. Following methods must be implemented:, (*9)

    • getData($typeName = null) - Method must return iterable result/array for all the data or one type only if specified
    • iterationRowTransform($data, $typeName = null) - Method must convert iteration row data to DataProviderDocument object which contains three variables
      • id - DocumentID
      • typeName - ElasticSearch index type name
      • data - Array for document source data
    • getTotal($typeName = null) - Optional method. Must return count for all the data or one type only if specified used. Used for iteration closures.
    • getIterationClosure() - Optional method. Must return callback for iteration: function ($i, $total)
    • getDocumentData() - Method must return same type of data as one iteration row in getData()

Example of both classes can be found in example directory, (*10)

When you have setup up everything, working with indexes is really easy:, (*11)

IndexManager Example

<?php
// Get IndexManager
$shopIndexManager = $elasticaManager->getIndexManager('shop');

// Use IndexManager
$shopIndexManager->create();
$shopIndexManager->populate();
$shopIndexManager->updateDocument(1);
$shopIndexManager->delete();

Every time you create index, your configuration and mappings are used and once populated your data is in the index., (*12)

Batch iterator Example

<?php
// Get IndexManager
$shopIndexManager = $elasticaManager->getIndexManager('shop');

// Get iterator instance
$iterator = $shopIndexManager->getIterator();

// Specify query
$query = new Elastica\Query(new Elastica\Query\MatchAll());

// Define closure
$closure = function (DataProviderDocument $doc, $i, $total) {
    // Do whatever you like with $doc->getData()
};

// Start iterating
$iterator->iterate($query, $closure);

Read more on how to setup initial classes in documentation., (*13)

Documentation

Read full documentation on how to initiate and use ElasticaManager and IndexManager here:, (*14)

Documentation wiki, (*15)

License

'FF-Elastica-Manager' is licensed under the MIT license., (*16)

The Versions

19/11 2013

dev-master

9999999-dev

Elastica manager for creating, rotating, populating and managing ElasticSearch indexes using Elastica client library

  Sources   Download

MIT

The Requires

 

by Kaspars Sprogis

elasticsearch manager elastica