Giter Club home page Giter Club logo

elasticsearch-mapping-migration's Introduction

Elastic Search Mapping Migration

Build Status Scrutinizer Code Quality Code Coverage

Easy way of executing changes on an existing Elastic Search Mapping through code. This is very similar to Database Migration mechanisms such as DB Migration package.

Installation

yarn add elasticsearch-mapping-migration

Then run

yarn esm-migration help

Help Command

Set the following environment variables

ESMIGRATION_HOST=your-elasticsearch-host
ESMIGRATION_PORT=your-elasticsearch-port
ESMIGRATION_PROTOCOL=your-elasticsearch-protocol-http-or-https
ESMIGRATION_MIGRATION_LIST_FILE=path/to/your/migration-list.json
ESMIGRATION_MIGRATION_INDEX=esm-migration

All paths must be relative to your project root directory. So no absolute path here.

The variable ESMIGRATION_MIGRATION_LIST_FILE set where your list of migrations will be.

the variable ESMIGRATION_MIGRATION_INDEX set which elastic search index will be created to keep track of all migrations.

Quick Start

Initializing the migration index

yarn esm-migration init

This will create an index to store all performed migrations identified by timestamp Help Command

If the init is run again then you have Help Command

Migration list file

Migration list example

[
  {
    "timestamp": "20200612170400",
    "file": "src/migrations/migration-1.json"
  },
  {
    "timestamp": "20200612170401",
    "file": "src/migrations/migration-2.json"
  }
]

The migration list file contains a list of migrations to be executed. Each item has the property timestamp which is an unique identifier.

Once it is performed, then that timestamp is stored. That is how a migration is only executed once.

Migration file

Migration file example

{
  "index_target": "<YOUR-INDEX-NAME>",
  "type": "<YOUR-FIELD-NAME>",
  "migration" : {
    "properties": {
      "<YOUR-FIELD-NAME>": {
        "type": "text",
        "fielddata": true,
        "fields": {
          "raw": {
            "type": "keyword"
          },
          "normalized": {
            "type": "keyword",
            "normalizer": "name_keyword_normalizer"
          }
        }
      }
    }
  }
}

As Elastic Search does not allow multiple field mapping update, every migration file will only have 1 field update

index_target is the index your documents are and where the mapping update will be performed on type is the field name migration is the actual mapping update. See Elastic Search Update Mapping Reference

Performing a migration

yarn esm-migration migrate

Then there should be an output like below Migrate Command

Behind the scenes

When the command esm-migration migrate is executed, the migration list file is loaded. Then all migrations within will be performed.

elasticsearch-mapping-migration's People

Contributors

pcelta avatar

Stargazers

Kiarash avatar

Watchers

 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.