PHPackages                             thadafinser/es-index-switcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. thadafinser/es-index-switcher

ActiveLibrary[Search &amp; Filtering](/categories/search)

thadafinser/es-index-switcher
=============================

Switch your index, without search downtime

v0.1.0(9y ago)1194[1 issues](https://github.com/ThaDafinser/es-index-switcher/issues)MITPHPPHP ~7.0

Since Feb 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ThaDafinser/es-index-switcher)[ Packagist](https://packagist.org/packages/thadafinser/es-index-switcher)[ RSS](/packages/thadafinser-es-index-switcher/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Elasticsearch index switcher
============================

[](#elasticsearch-index-switcher)

[![Build Status](https://camo.githubusercontent.com/4684db2234c0217f60ce11e28b2883444824353a6c2da0f772f97a9d9a751610/68747470733a2f2f7472617669732d63692e6f72672f546861446166696e7365722f65732d696e6465782d73776974636865722e737667)](https://travis-ci.org/ThaDafinser/es-index-switcher)[![Code Coverage](https://camo.githubusercontent.com/7aeb67cf4dcf1f670a845792503d31d4eb93546f2a8acae86f9e4fc4186abd56/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f546861446166696e7365722f65732d696e6465782d73776974636865722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ThaDafinser/es-index-switcher/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/27f3a44ae7f3eca71b0f1013a5aa3af2cd03e0a0a946590f118dd21499ba7220/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f546861446166696e7365722f65732d696e6465782d73776974636865722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ThaDafinser/es-index-switcher/?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/a0f0a731f0df276c55cd8cec571724810eeca9363bb22109b4205c638cd36549/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f65732d696e6465782d73776974636865722f762f737461626c65)](https://packagist.org/packages/thadafinser/es-index-switcher)[![Latest Unstable Version](https://camo.githubusercontent.com/9519d3e4905e65116cdc5153e147dd99c53ef267431ef4762b12321d8a8df28e/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f65732d696e6465782d73776974636865722f762f756e737461626c65)](https://packagist.org/packages/thadafinser/es-index-switcher)[![License](https://camo.githubusercontent.com/c0c80c8f9c824c3445ceb8742b4075cd08e30415b46408db1d96d978f7517b1a/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f65732d696e6465782d73776974636865722f6c6963656e7365)](https://packagist.org/packages/thadafinser/es-index-switcher)[![Total Downloads](https://camo.githubusercontent.com/96b3597de106ca062880176dcc9814ca5d1c2c2c1d2f9ec1de5c0f3572998053/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f65732d696e6465782d73776974636865722f646f776e6c6f616473)](https://packagist.org/packages/thadafinser/es-index-switcher)

If you use Elasticsearch for a end user search, you never want to interrupt your service - even when you "reindex" your data from source.

This small scripts solves this issue. Your end users will always be able to search and you can reindex in parallel your updated data.

How does it work? It's quiet simple! You just need to search over an alias which points to the current full index. If you want to reindex your data, this script will change the alias when the indexing has finished and the user will search over the new data.

Minimal example
---------------

[](#minimal-example)

### Index your data

[](#index-your-data)

```
$hosts = [
    [
        'host' => '...',
        'port' => '9200',
        'scheme' => 'http',
        'user' => '...',
        'pass' => '...'
    ]
];

$client = ClientBuilder::create()->setHosts($hosts)->build();

$es = new EsIndexSwitcher($client, 'test_alias', 'testing');

/*
 * Create the index itself
 */
$result = $es->createNewIndex();

/*
 * Add your documents to the index!
 */
$params = [
    'index' => $es->getNewIndexName(),
    'type' => 'my_document',

    'body' => [
        'field1' => 'test'
    ]
];
$response = $client->index($params);

/*
 * Create/update alias and remove all old indices
 */
$es->finish();
```

### Search

[](#search)

```
$hosts = [
    [
        'host' => '...',
        'port' => '9200',
        'scheme' => 'http',
        'user' => '...',
        'pass' => '...'
    ]
];

$client = ClientBuilder::create()->setHosts($hosts)->build();

$es = new EsIndexSwitcher($client, 'test_alias', 'testing');

/*
 * Add more documents to the old index (by using the alias)
 */
$params = [
    'index' => $es->getAlias(),
    'type' => 'my_document',
    'body' => [
    ]
];

$response = $client->search($params);

var_dump($response);
```

Update document on the current used index
-----------------------------------------

[](#update-document-on-the-current-used-index)

Maybe you don't want to create a new index on every small change.

Just add your document over the alias

```
$client = ClientBuilder::create()->setHosts($hosts)->build();

$es = new EsIndexSwitcher($client, 'test_alias', 'testing');

/*
 * Add more documents to the old index (by using the alias)
 */
$params = [
    'index' => $es->getAlias(),
    'type' => 'my_document',

    'body' => [
        'field1' => 'test2'
    ]
];
$response = $client->index($params);

var_dump($response);
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3367d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c11fd53e7dee0524aa83e44f3928306577f782c37c4fac49ee7254ad17b5f4f?d=identicon)[ThaDafinser](/maintainers/ThaDafinser)

---

Top Contributors

[![ThaDafinser](https://avatars.githubusercontent.com/u/533017?v=4)](https://github.com/ThaDafinser "ThaDafinser (7 commits)")

---

Tags

elasticsearchreindexindexelasticaliasre-index

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/thadafinser-es-index-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/thadafinser-es-index-switcher/health.svg)](https://phpackages.com/packages/thadafinser-es-index-switcher)
```

###  Alternatives

[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.0M6](/packages/babenkoivan-elastic-client)[madewithlove/elasticsearcher

Wrapper on top of the ElasticSearch PHP SDK which allows easier index/document/query management.

264133.2k2](/packages/madewithlove-elasticsearcher)[thomasjsn/laravel-scout-elastic

Elastic Driver for Laravel Scout

1411.5k](/packages/thomasjsn-laravel-scout-elastic)[blomstra/search

Replaces Flarum search with one powered by an elastic search server.

114.9k](/packages/blomstra-search)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
