# Disable merging to avoid index corruption

**URL:** <https://discuss.elastic.co/t/disable-merging-to-avoid-index-corruption/54374>\
**Category:** Elasticsearch\
**Created:** [June 30, 2016, 7:58am UTC](https://discuss.elastic.co/t/disable-merging-to-avoid-index-corruption/54374 "2016-06-30T07:58:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Selvam\_ayyanar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/selvam_ayyanar/32/11101_2.png) [@Selvam\_ayyanar](https://discuss.elastic.co/u/Selvam_ayyanar)\
**Post date:** [June 30, 2016, 7:58am UTC](https://discuss.elastic.co/t/disable-merging-to-avoid-index-corruption/54374/1 "2016-06-30T07:58:25Z")

</div>

Hi All,

We are facing index corruption due to field conflicts.

for ex:  
i have a field "Number" in type 1 and 2 in a same INDEX.  
in type 1 it is defined as **"integer"**  
in type 2 it is defined as **"string"**

elasticsearch not supporting the above scenario, due to this indices are corrupted during merge.

My question is:  
By stopping the segment merge can avoid this issue?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [June 30, 2016, 8:11am UTC](https://discuss.elastic.co/t/disable-merging-to-avoid-index-corruption/54374/2 "2016-06-30T08:11:44Z")

</div>

This issue is not caused by segment merging. You cannot have mappings in different types in the same index which are not compatible. This is set at the mapping level even before indexing. For the purposes of this explanation I will assume you are relying on Elasticsearch's out of the box dynamic mapping.

Lets imagine you have a new index with no documents. When you index the first document:

```auto
PUT index/type1/1
{
  "number": 12
}

```

Elasticsearch recognises that the JSON type of the number field is an integer so will map the number field in type 1 to the integer type and index the document. Note that when the document is indexed by Lucene the field is `number` (i.e. Lucene has no concept of the document type).

Now you index second document:

```auto
PUT index/type2/2
{
  "number": "40"
}

```

This time Elasticsearch recognises that the JSON type of the number field is a string as tries to map the number field for type2 to the string type. The mapping code then throws an error because there is already a mapping for the number field (provided by type1) that specifies number as an integer field not a string field.

In order to fix this issue, you will either need to normalise your data before you index it into Elasticsearch (using for example Logstash), or explicitly define your mapping using the mapping API.

For more information on Mappings see here: [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/mapping.html)

For information on how to set the mapping using the mapping API see here: [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/indices-put-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/indices-put-mapping.html)

Hope this helps

---

<div class="post-metadata">

**Author:** ![Selvam\_ayyanar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/selvam_ayyanar/32/11101_2.png) [@Selvam\_ayyanar](https://discuss.elastic.co/u/Selvam_ayyanar)\
**Post date:** [July 1, 2016, 5:50am UTC](https://discuss.elastic.co/t/disable-merging-to-avoid-index-corruption/54374/3 "2016-07-01T05:50:43Z")

</div>

Hi @colings86

Thanks for your update,  
we are using elasticsearch 1.3.7.  
yes, whenever we try to update different field types for same field name we got exception like "Failed to merge".

But if we delete and update for the 2nd type mapping update will be successful. 😢 [this is problem]

we had these types of mapping collisions in staging and prod also.  
" All are says upgrade your version will help for you "

But even upgrade i need to solve this mapping issue, any idea to solve this issue .  
also let me know what are the issues in **copy\_to** method

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 1, 2016, 7:36am UTC](https://discuss.elastic.co/t/disable-merging-to-avoid-index-corruption/54374/4 "2016-07-01T07:36:29Z")

</div>

As I said before you need to ensure that fields which are shared between types have the same mapping. Also, you should definitely upgrade to the latest version as there are many improvements in 2.x to mapping to make mapping conflict less possible: [https://www.elastic.co/blog/great-mapping-refactoring](https://www.elastic.co/blog/great-mapping-refactoring)

---

<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 5, 2017, 10:39pm UTC](https://discuss.elastic.co/t/disable-merging-to-avoid-index-corruption/54374/5 "2017-07-05T22:39:01Z")

</div>


