How to create new index with old index mapping and settings

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

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

You can use the mappings to PUT an index, see Create index API | Elasticsearch Guide [8.2] | Elastic

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

If you head to that docs page, Create index API | Elasticsearch Guide [8.2] | Elastic is what you want to do to include the mapping.

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

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

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,

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

Regards,
Sameer

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 :slight_smile:

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