# Logstash not preserving mappings when copying docs from one index to another

**URL:** <https://discuss.elastic.co/t/logstash-not-preserving-mappings-when-copying-docs-from-one-index-to-another/42815>\
**Category:** Logstash\
**Created:** [February 26, 2016, 6:58am UTC](https://discuss.elastic.co/t/logstash-not-preserving-mappings-when-copying-docs-from-one-index-to-another/42815 "2016-02-26T06:58:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinivas](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@srinivas](https://discuss.elastic.co/u/srinivas)\
**Post date:** [February 26, 2016, 6:58am UTC](https://discuss.elastic.co/t/logstash-not-preserving-mappings-when-copying-docs-from-one-index-to-another/42815/1 "2016-02-26T06:58:00Z")

</div>

I am using the following pipeline to copy data from index to another.  
input {  
elasticsearch {  
hosts =\> ["sourcehost:9200"]  
index =\> "source-index"  
query =\> '{"query":{"match\_all":{}}}'  
size =\> 500  
scroll =\> "5m"  
docinfo =\> true  
}  
}  
output {  
elasticsearch {  
hosts =\> ["targethost:9200"]  
index =\> "target-index"  
manage\_template =\> false  
workers =\> 2  
}  
}

The issue with logstash is its not preserving the mapping of the source index.  
For ex : an field is having following mappings in source index  
"INSERT\_DATE": {  
"type": "date",  
"store": true,  
"format": "yyyy-MM-dd HH:mm:ss"  
}  
But in target index the mapping is  
"INSERT\_DATE": {  
"type": "string"  
}

---

<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:** [February 26, 2016, 6:59am UTC](https://discuss.elastic.co/t/logstash-not-preserving-mappings-when-copying-docs-from-one-index-to-another/42815/2 "2016-02-26T06:59:27Z")

</div>

LS has no concept of copy the mappings over.  
You need to either pull the mapping down and define it in the output, or copy it over before (or use templates).

---

<div class="post-metadata">

**Author:** ![srinivas](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@srinivas](https://discuss.elastic.co/u/srinivas)\
**Post date:** [February 26, 2016, 7:02am UTC](https://discuss.elastic.co/t/logstash-not-preserving-mappings-when-copying-docs-from-one-index-to-another/42815/3 "2016-02-26T07:02:48Z")

</div>

I tried creating the targetindex with mappings before starting logstash.  
But logstash is throwing the below error:

Failed action. {:status=\>400, :action=\>["index", {:\_id=\>nil, :\_index=\>"target-index", :\_type=\>"logs", :\_routing=\>nil}, #\<LogStash::Event:0x509b7581 @metadata\_accessors=#\<LogStash::Util::Accessors:0x5c17038f @store={"\_index"=\>"source-index", "\_type"=\>"logs", "\_id"=\>"AVMYI34\_m0t6GmsVN69I"}, @lut={}\>, @cancelled=false, @data={"ACTION\_EXPRESSION"=\>nil, "ResponseTime\_Number"=\>0, "INSERT\_DATE"=\>"2016-01-11 01:34:47",

The docs are not copied to target index and its printing all docs on console like above

---

<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:** [July 6, 2017, 5:09am UTC](https://discuss.elastic.co/t/logstash-not-preserving-mappings-when-copying-docs-from-one-index-to-another/42815/4 "2017-07-06T05:09:40Z")

</div>

Closed on July 6, 2017, 5:09am UTC


