# How to create new index with old index mapping and settings

**URL:** <https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895>\
**Category:** Elasticsearch\
**Tags:** reindex\
**Created:** [May 4, 2022, 4:05am UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895 "2022-05-04T04:05:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sameer\_khamkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sameer_khamkar/32/104910_2.png) [@sameer\_khamkar](https://discuss.elastic.co/u/sameer_khamkar)\
**Post date:** [May 4, 2022, 4:05am UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895/1 "2022-05-04T04:05:15Z")

</div>

Hello Team,

I am new to Elasticsearch, after reading upgrade documents I came to know that we need to reindex old data,

from below command I can get list of existing index ,  
**curl 'localhost:9200/\_cat/indices?v'**

I can get mappings from below command  
**curl -GET [http://localhost:9200/old\_index/\_mapping?pretty](http://localhost:9200/old_index/_mapping?pretty)**

but i am not sure how to add same mappings and settings to new index which I need to create, can someone help me here,

Regards,  
SAMURAI

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 4, 2022, 5:03am UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895/2 "2022-05-04T05:03:07Z")

</div>

You can use the mappings to PUT an index, see [Create index API | Elasticsearch Guide [8.2] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html)

---

<div class="post-metadata">

**Author:** ![sameer\_khamkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sameer_khamkar/32/104910_2.png) [@sameer\_khamkar](https://discuss.elastic.co/u/sameer_khamkar)\
**Post date:** [May 4, 2022, 5:43am UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895/3 "2022-05-04T05:43:22Z")

</div>

Hello @warkolm ,

curl -X PUT "localhost:9200/my-index-000001?pretty"  
here I need to mention new index but how it will add same mapping from old index, can you please guide

basic use case is

create new index which should have same mappings and settings as oldindex

I am sorry for my silly question sine I am new to ES need some help here.

Regards,  
SAMURAI

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 4, 2022, 9:44pm UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895/4 "2022-05-04T21:44:16Z")

</div>

If you head to that docs page, [Create index API | Elasticsearch Guide [8.2] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#mappings) is what you want to do to include the mapping.

---

<div class="post-metadata">

**Author:** ![sameer\_khamkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sameer_khamkar/32/104910_2.png) [@sameer\_khamkar](https://discuss.elastic.co/u/sameer_khamkar)\
**Post date:** [May 10, 2022, 6:17am UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895/5 "2022-05-10T06:17:41Z")

</div>

Hello @warkolm

when i use this  
`curl -X PUT "http://${ES_HOST}:${ES_PORT}/$newindex?pretty"`

it creates the new index  
but when I try to reindex with old it shows success but the values are not correct which means it doenst reindex

```auto
green open old_03 ETKrTJIoRTGdrmxY6lx4nQ 5 1 56220 0 65.8mb 65.8mb
yellow open old_03-new WdNqv-k3Qfi0cklKqQtrBA 5 1 0 0 1.1kb 1.1kb

```

but when I  
` **curl -GET http://localhost:9200/old_index/_mapping?pretty** `

and use the same value to create new index it creates new index and even reindex is working

this is how I am creating new index with mapping value from old index

```auto
curl -X PUT \
http://localhost:9200/old_to_new \
-H 'Content-Type: application/json' \
-d '{"mappings" : {
      "message" : {
        "dynamic_templates" : [
          {
            "internal_fields" : {
              "match" : "gl2_*",
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "keyword"
              }
            }
          },
          {
            "store_generic" : {
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "keyword"
              }
            }
          }
        ],
        "properties" : {
          "LoggerName" : {
            "type" : "keyword"
          },
          "MessageParam0" : {
            "type" : "keyword"
          },
          "MessageParam1" : {
            "type" : "long"
          },
          "MessageParam2" : {
            "type" : "keyword"
          },
          "MessageParam3" : {
            "type" : "keyword"
          },
          "MessageParam4" : {
            "type" : "keyword"
          },
          "MessageParam5" : {
            "type" : "keyword"
          },
          "MessageParam6" : {
            "type" : "keyword"
          },
          "MessageParam7" : {
            "type" : "keyword"
          },
          "MessageParam8" : {
            "type" : "keyword"
          },
          "Severity" : {
            "type" : "keyword"
          },
          "SourceClassName" : {
            "type" : "keyword"
          },
          "SourceMethodName" : {
            "type" : "keyword"
          },
          "SourceSimpleClassName" : {
            "type" : "keyword"
          },
          "StackTrace" : {
            "type" : "keyword"
          },
          "Thread" : {
            "type" : "keyword"
          },
          "Time" : {
            "type" : "keyword"
          },
          "facility" : {
            "type" : "keyword"
          },
          "full_message" : {
            "type" : "text",
            "analyzer" : "standard"
          },
          "gl2_accounted_message_size" : {
            "type" : "long"
          },
          "gl2_message_id" : {
            "type" : "keyword"
          },
          "gl2_processing_timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "gl2_receive_timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "gl2_remote_ip" : {
            "type" : "keyword"
          },
          "gl2_remote_port" : {
            "type" : "long"
          },
          "gl2_source_input" : {
            "type" : "keyword"
          },
          "gl2_source_node" : {
            "type" : "keyword"
          },
          "level" : {
            "type" : "long"
          },
          "message" : {
            "type" : "text",
            "analyzer" : "standard"
          },
          "source" : {
            "type" : "text",
            "analyzer" : "analyzer_keyword",
            "fielddata" : true
          },
          "streams" : {
            "type" : "keyword"
          },
          "timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          }
        }
      }
    }
  }
}'

```

can you please guide what I am doing wrong in reindexing part,

```auto
curl -X POST \
    http://localhost:9200/_reindex \
    -H 'Content-Type: application/json' \
		-d '{
		"source": {
			"index": "old_0"
		},
		"dest": {
			"index": "old_to_new"
		}
	}'

```

Regards,  
Sameer

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 10, 2022, 6:34am UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895/6 "2022-05-10T06:34:32Z")

</div>

Please format your code/logs/config using the `</>` button, or markdown style back ticks. It helps to make things easy to read which helps us help you 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 8, 2022, 3:56am UTC](https://discuss.elastic.co/t/how-to-create-new-index-with-old-index-mapping-and-settings/303895/8 "2022-06-08T03:56:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
