All Projects → zumba → elasticsearch-index-rotator

zumba / elasticsearch-index-rotator

Licence: other
Safely rotate Elasticsearch indexes with no downtime to end users.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to elasticsearch-index-rotator

passport-activedirectory
Active Directory strategy for passport.js
Stars: ✭ 28 (+64.71%)
Mutual labels:  strategy
quick trade
convenient script for trading with python.
Stars: ✭ 63 (+270.59%)
Mutual labels:  strategy
passport-yandex
Yandex authentication strategy for Passport and Node.js.
Stars: ✭ 19 (+11.76%)
Mutual labels:  strategy
presso
Event-driven backtest/realtime quantitative trading system.
Stars: ✭ 59 (+247.06%)
Mutual labels:  strategy
YAAdapterTableViewWithResponderChain
No description or website provided.
Stars: ✭ 15 (-11.76%)
Mutual labels:  strategy
NextCommunity.github.io
Join FREE: Community of open-source programmers and software engineers.
Stars: ✭ 29 (+70.59%)
Mutual labels:  strategy
NSE-Stock-Scanner
National Stock Exchange (NSE), India based Stock screener program. Supports Live Data, Swing / Momentum Trading, Intraday Trading, Connect to online brokers as Zerodha Kite, Risk Management, Emotion Control, Screening, Strategies, Backtesting, Automatic Stock Downloading after closing, live free day trading data and much more
Stars: ✭ 78 (+358.82%)
Mutual labels:  strategy
evolving
A free stock trading interface for CH stock-market. MacOS下控制同花顺进行交易, 无券商限制.
Stars: ✭ 32 (+88.24%)
Mutual labels:  strategy
engine
Online 4X Grand Strategy RPG Engine
Stars: ✭ 19 (+11.76%)
Mutual labels:  strategy
reactive-trader
In the coming weeks this plans to become a Gekko plugin that reacts to market changes, finding and running only the most profitable strategies.
Stars: ✭ 91 (+435.29%)
Mutual labels:  strategy
ueberauth slack
Slack OAuth2 Strategy for Überauth
Stars: ✭ 23 (+35.29%)
Mutual labels:  strategy
TradingView-Machine-Learning-GUI
Let Python optimize the best stop loss and take profits for your TradingView strategy.
Stars: ✭ 396 (+2229.41%)
Mutual labels:  strategy
pokerwars.io-starterbot-python
A starter bot written in python for the pokerwars.io platform. To play: pull this code, register on pokerwars.io, get your API token and play!
Stars: ✭ 37 (+117.65%)
Mutual labels:  strategy
cult
Evil Cult is a turn-based strategy about world domination.
Stars: ✭ 16 (-5.88%)
Mutual labels:  strategy
Road2StrategyPM
产品策划开发修炼手记 👩🏻‍💻
Stars: ✭ 80 (+370.59%)
Mutual labels:  strategy
On-The-Roadside
A turn-based ASCII strategy game.
Stars: ✭ 21 (+23.53%)
Mutual labels:  strategy
sirius
Modern coffeescript/javascript framework
Stars: ✭ 20 (+17.65%)
Mutual labels:  strategy
ccapi
A header-only C++ library for interacting with crypto exchanges. Binding for Python is provided. A spot market making application is also provided as an end-to-end solution for liquidity providers.
Stars: ✭ 227 (+1235.29%)
Mutual labels:  strategy
SwordCoastStratagems
Sword Coast Stratagems (SCS) adds over 130 optional components to Baldur's Gate: Enhanced Edition, Baldur's Gate II: Enhanced Edition, Baldur's Gate II: Throne of Bhaal, Baldur's Gate Trilogy, mostly focused around improving monster AI and encounter difficulties, but also including cosmetic and ease-of-use components, tweaks to abilities or spells.
Stars: ✭ 43 (+152.94%)
Mutual labels:  strategy
Stareater
4X turn based strategy
Stars: ✭ 27 (+58.82%)
Mutual labels:  strategy

Elasticsearch Index Rotator

A library to enable you to safely rotate indexes with no downtime to end users.

Build Status

Why would I use this?

In many situations, Elasticsearch is used as an ephemeral datastore used to take structured or relational data and make it fast to search on that data. Often this is achieved via scheduled jobs that read data from a permanent datastore (such as MySQL or Postgres) and translate it into an Elasticsearch index.

In many cases, rebuilding an index requires a clean slate so that the entire index is rebuilt. How do you do this without interrupting end users searching on that index? The answer is a rotating index.

User search disrupted by rebuild

Here the user's search is fully disrupted when the index is first removed, and only partially available while the index is being rebuilt. While the index is being rebuilt, users get incomplete data.

User search contiguous

Here the user's search is never disrupted because we construct a new index and after it is built/settled, we change the what index to search by the client.

Installation

composer require zumba/elasticsearch-index-rotate

Elasticsearch Index Rotator supports multiple versions of ElasticSearch server and uses the official elasticsearch library for execute the commands. On your application, make sure you include this package as well and specify the version supported by your Elasticsearch server. See the library documentation for the versions.

Usage

Example Search

<?php

$client = new \Elasticsearch\Client();
$indexRotator = new \Zumba\ElasticsearchRotator\IndexRotator($client, 'pizza_shops');
$client->search([
	'index' => $indexRotator->getPrimaryIndex(), // Get the current primary!
	'type' => 'shop',
	'body' => [] //...
]);

Example Build

<?php

$client = new \Elasticsearch\Client();
$indexRotator = new \Zumba\ElasticsearchRotator\IndexRotator($client, 'pizza_shops');
// Build your index here
$newlyBuiltIndexName = 'my_new_built_index_name';
$indexRotator->copyPrimaryIndexToSecondary();
$indexRotator->setPrimaryIndex($newlyBuiltIndexName);
// optionally remove the old index right now
$indexRotator->deleteSecondaryIndices();

All together

<?php

use \Elasticsearch\Client;
use \Zumba\ElastsearchRotator\IndexRotator;

class MySearchIndex {

	const INDEX_PREFIX = 'pizza_shops';

	public function __constructor(\Elasticsearch\Client $client) {
		$this->client = $client;
	}

	public function search($params) {
		$indexRotator = new IndexRotator($this->client, static::INDEX_PREFIX);
		return $client->search([
			'index' => $indexRotator->getPrimaryIndex(), // Get the current primary!
			'type' => 'shop',
			'body' => $params
		]);
	}

	public function rebuildIndex() {
		$indexRotator = new IndexRotator($client, static::INDEX_PREFIX);
		$newlyBuiltIndexName = $this->buildIndex($client);
		$indexRotator->copyPrimaryIndexToSecondary();
		$indexRotator->setPrimaryIndex($newlyBuiltIndexName);
		// optionally remove the old index right now
		$indexRotator->deleteSecondaryIndices();
	}

	private function buildIndex(\Elasticsearch\Client $client) {
		$newIndex = static::INDEX_PREFIX . '_' . time();
		// get data and build index for `$newIndex`
		return $newIndex;
	}

}

Using Strategies

You can now customize the strategy of getting/setting the primary index. By default, the ConfigurationStrategy is employed, however we have also included an AliasStrategy. The main difference is when setPrimaryIndex is called, instead of creating an entry in the configuration index, it adds an alias (specified by alias_name option) on the specified index and deletes all other aliases for the old primary indices (specified by index_pattern).

Using the AliasStrategy

<?php

$client = new \Elasticsearch\Client();
$indexRotator = new \Zumba\ElasticsearchRotator\IndexRotator($client, 'pizza_shops');
$aliasStrategy = $indexRotator->strategyFactory(IndexRotator::STRATEGY_ALIAS, [
	'alias_name' => 'pizza_shops',
	'index_pattern' => 'pizza_shops_*'
]);
// Build your index here
$newlyBuiltIndexName = 'pizza_shops_1234102874';
$indexRotator->copyPrimaryIndexToSecondary();
$indexRotator->setPrimaryIndex($newlyBuiltIndexName);

// Now that the alias is set, you can search on that alias instead of having to call `getPrimaryIndex`.
$client->search([
	'index' => 'pizza_shops',
	'type' => 'shop',
	'body' => [] //...
])

Since the alias (pizza_shops) is mapped to the primary index (pizza_shops_1234102874), you can use the alias directly in your client application rather than having to call getPrimaryIndex() on the IndexRotator. That being said, calling getPrimaryIndex won't return the alias, but rather the index that it is aliasing. The secondary entries in the configuration index are still used and reference the actual index names, since the alias can be updated at any time and there wouldn't be a reference to remove the old one.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].