Coder Social home page Coder Social logo

slingshot's Introduction

slingshot

Elastic Search Mirgration Lib

  • Use Scan&scroll ES feature is used to fetch all docs by batch.
  • Every doc is given to a business oriented callback func which is responsible for building the bulk instructions
  • Then every batches are indexed in the destination index through a bulk POST call. According to the given bulk options.

What's going to cost the most is the callback func. Specially if you need strong, business oriented, document modifications. E.g. if database connections is required for fetch additional data from production databases in orderenrich each indexed document.

How to use

  • Add it as deps to your composer project
  • Code the call back function
  • Use it in a batch
use \vpg\slingshot;

/**
 * Elastic hosts configuration
 * Here we work on the same host
 */
$esCnfHash = [
    'from' => '192.168.100.100:9200',
    'to'   => '192.168.100.100:9200'
];

/**
 * Replaces all docs of the given index
 * Each new doc is returned by enrichDocCallBack which :
 *     -  Adds 'gar' and 'DT' fields
 *     -  Removes 'foo' field
 */
$enrichDocCallBack = function ($docHash) {
    $docHash['far'] = 'FAAAAAAR' . $docHash['_id'];
    $docHash['DT'] = date('Y-m-d H:i:s');
    return $docHash;
};

/**
 * Migration params
 * Here we replace all doc on the given index
 */
$migrationConfHash = [
    'from' => ['index' => 'new_test', 'type' => 'boo'],
    'to'   => ['index' => 'new_test', 'type' => 'boo'],
    'bulk' => ['action' => 'index', 'batchSize' => 3]
];

// Run the migration
$slingshot = new slingshot\Slingshot($esCnfHash, $migrationConfHash);
$slingshot->migrate($queryHash = [], $enrichDocCallBack);

slingshot's People

Contributors

jrmbrgs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.