Malekbenz

Hi, I'm MalekBenz. I author this blog, I'm FullStack Developer, create courses & love learning, writing, teaching technology. ( Javascript, C#, ASP.NET , NodeJS, SQL Server )

Reindexing in Elasticsearch

24 Jan 2018

  • Category:elasticsearch
  • tags:elasticsearch
  • Time:24 Jan 2018

In this tutorial I’m going to show you how to index from an existing index in elasticsearch.

Create a sample index

Let’s first create an index and name it myindex with two properties (FirstName and LastName)

PUT localhost:9200/myindex
{
 "mappings": {
    "developer": {
    "properties" : {
        "FirstName": { "type" : "text" },
        "LastName": { "type" : "text" }
        }
      }
    }
}


CMD

Indexing documents

We need to index some documents (sample data ):

POST localhost:9200/myindex/developer
{
        "FirstName": "malek",
        "LastName": "benzemam"
}

POST localhost:9200/myindex/developer
{
        "FirstName": "cristiano",
        "LastName": "ronaldo"
}
POST localhost:9200/myindex/developer
{
        "FirstName": "lionel",
        "LastName": "missi"
}

CMD

We can confirm by asking our index :

GET localhost:9200/myindex/developer/_search

CMD

Create mynewindex & index it from myindex

Create an index and name it mynewindex :

PUT localhost:9200/mynewindex
{
 "mappings": {
    "developer": {
    "properties" : {
        "FirstName": { "type" : "text" },
        "LastName": { "type" : "text" }
        }
      }
    }
}

CMD

Now all we need is to tell elasticsearch to index mynewindex by using myindex as it’s source:

POST localhost:9200/_reindex
{
  "source": {
    "index": "myindex"
  },
  "dest": {
    "index": "mynewindex"
  }
}

CMD

if we ask our index mynewindex :

GET localhost:9200/mynewindex/developer/_search

CMD

NOTE: For more informations , please see ElasticSearch website .

CMD

That’s it see you soon!.