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" }
}
}
}
}
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"
}
We can confirm by asking our index :
GET localhost:9200/myindex/developer/_search
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" }
}
}
}
}
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"
}
}
if we ask our index mynewindex :
GET localhost:9200/mynewindex/developer/_search
NOTE: For more informations , please see ElasticSearch website .
That’s it see you soon!.