# Elastic: How to correct the auto generated mapping?

**URL:** <https://discuss.elastic.co/t/elastic-how-to-correct-the-auto-generated-mapping/305819>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 27, 2022, 4:38pm UTC](https://discuss.elastic.co/t/elastic-how-to-correct-the-auto-generated-mapping/305819 "2022-05-27T16:38:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gopala00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gopala00/32/106275_2.png) [@Gopala00](https://discuss.elastic.co/u/Gopala00)\
**Post date:** [May 27, 2022, 4:38pm UTC](https://discuss.elastic.co/t/elastic-how-to-correct-the-auto-generated-mapping/305819/1 "2022-05-27T16:38:03Z")

</div>

I'm using Elastic cloud hosted in Azure and use NEST for the client. I have a part of auto generated mapping that I need to change from

```auto
    "Bonus" : {
      "type" : "text",
      "fields" : {
        "keyword" : {
          "type" : "keyword",
          "ignore_above" : 256
        }
      }
    },

```

to

```auto
    "Bonus" : {
      "properties" : {
        "Amount" : {
          "properties" : {
            "Value" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "PayrollSyncDateTime" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    },

```

When I tried to update the mapping, I get `illegal_argument_exception` error with the message `"can't merge a non object mapping [activityData.Bonus] with an object mapping"` . How can I correct the auto generated mapping?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [May 27, 2022, 6:22pm UTC](https://discuss.elastic.co/t/elastic-how-to-correct-the-auto-generated-mapping/305819/2 "2022-05-27T18:22:28Z")

</div>

Hi @Gopala00 Welcome to the Community.

Think of a mapping as the schema.

A couple fundamental rules...

1. You can not change a mapping of an existing field on an existing index that is what you are trying to do and getting an error. (You are trying to change a field into and object)

2. In general You can ADD a mapping to an existing Index as long as it does not conflict with an existing field / object.

3. In general / best practice you will want to create an index template with the correct mapping so that when you create an index by writing a document to the index the correct mappings will be applied.

4. If you do not want to create a template you can manually create the mappings for an empty index before you start writing documents.

5. Generally you do not need / want both the `keyword` and `text` data types for a fields. Think of `keyword` as Categories, Keyword, Types something you filter and aggregate on and `text` as fill text search

[Mappings Docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)

[Template Docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html)

---

<div class="post-metadata">

**Author:** ![Gopala00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gopala00/32/106275_2.png) [@Gopala00](https://discuss.elastic.co/u/Gopala00)\
**Post date:** [May 31, 2022, 2:50pm UTC](https://discuss.elastic.co/t/elastic-how-to-correct-the-auto-generated-mapping/305819/3 "2022-05-31T14:50:31Z")

</div>

> [@stephenb](#):
>
> general You can ADD a mapping to an existing Index as lon

Thanks @stephenb for your reply. Is it possible to change the mapping for `Bonus` to ignore in the index? Will it remove `Bonus` data from index so that I can redefine the mapping OR will it affect the future data only? What are the steps involved to remove `Bonus` from the index so that I can redefine mapping?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 1, 2022, 6:08am UTC](https://discuss.elastic.co/t/elastic-how-to-correct-the-auto-generated-mapping/305819/4 "2022-06-01T06:08:53Z")

</div>

> [@Gopala00](#):
>
> Is it possible to change the mapping for `Bonus` to ignore in the index?

I am unclear what that means .. apologies.. If you mean can you remove a mapping and will it automatically erase the data .. the answer is no and no.

You can not remove a field mapping from an index.

You can not actually remove a field from an index without reindex.

You can update each document with a new document without that fields ... but the field will still be in the mapping in the index ... and thus you can not change the mapping.

If you really want it gone you need to define a new index with the correct mapping.

---

<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 29, 2022, 6:09am UTC](https://discuss.elastic.co/t/elastic-how-to-correct-the-auto-generated-mapping/305819/5 "2022-06-29T06:09:00Z")

</div>

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