1.1.1 • Published 1 year ago

elasticsearch-reindexer v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Elasticsearch Reindexer

Automatically reindex in elasticsearch like a charm!

Installation

npm i elasticsearch-reindexer

or 

yarn add elasticsearch-reindexer

Usage

Create a file named index.js including the following code:

const reindexer = require('elasticsearch-reindexer');
const fs = require('fs');

const indexDetailsFile = fs.readFileSync('index-details.json', 'utf-8');
const esConfigFile = fs.readFileSync('esclient-config.json', 'utf-8');

reindexer({
	newIndexName: 'test_clone',
	oriIndexName: 'test',
	indexDetailsFile: indexDetailsFile,
	esConfigFile: esConfigFile,
}).catch((error) => {
	console.log(error);
});

Create index-details.json and esclient-config.json files respectively. The former includes the details of the new index like settings and mappings, and the latter includes the elasticsearch configuration. If you want to use the same index name like old one, please swap the two index name and execute the file again.

Make sure that node is already installed in your system.

node index.js

WARNING: The original index (old index) will be deleted automatically after finished reindexing.

Index Details Sample

{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "properties": {
      "field1": {
        "type": "text"
      }
    }
  }
}

ES Configuration Sample

{
  "esClientOptions": {
    "host": "localhost:9200",
    "log": "error",
    "auth": {
      "username": "",
      "password": ""
    }
  },
  "ping": 30000,
  "activeQueueTasks": 4
}

Parameters

When use reindexer you can configure the following options via the parameter.

KeyTypeDefaultDescription
newIndexNamestringNoneThe new index name.
oriIndexNamestringNoneThe original index name (old index name).
indexDetailsFilestringNoneIndex details like mapping and setting.
esConfigFilestringNoneElasticsearch configuration.