# Index Mapping Issue - Getting Error: "reason" : "object mapping \[locations\] can't be changed from nested to non-nested"

**URL:** <https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938>\
**Category:** Elasticsearch\
**Created:** [April 14, 2020, 2:42pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938 "2020-04-14T14:42:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![austin-harris](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@austin-harris](https://discuss.elastic.co/u/austin-harris)\
**Post date:** [April 14, 2020, 2:42pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/1 "2020-04-14T14:42:46Z")

</div>

I have found many instances of others resolving this error, but I have not been successful. I have ElasticSearch 7.6 deployed. I create the index and mapping. Then, as a test have a sample JSON I am pushing and I receive this error:

```auto
 {
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "object mapping [locations] can't be changed from nested to non-nested"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "object mapping [locations] can't be changed from nested to non-nested"
  },
  "status" : 400
}

```

The Mapping and the example JSON are:

Mapping:

```auto
PUT vision_events
{
  "settings" : {
        "number_of_shards" : 5
    },
  "mappings" : {
        "properties": {
          "camera_id": {
            "type": "text",
            "fields": {
              "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "hit_counts": {
          "type": "long"
        },
        "id": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "intersection": {
          "type": "boolean"
        },
        "label": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "locations": {
          "type" : "nested",
           "properties": {
            "coords" : {
                "type" : "float"
            },
            "location": {
              "type": "text"
            },
            "street_segment": {
              "type": "text"
            },
            "timestamp": {
              "type": "date"
            }
          }
        },
        "pole_id": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "timestamp": {
        "type": "date"
        }
      }
    }
}

```

Example data:

```auto
POST /vision_events/_doc/1
{
  "pole_id": "mlk-central-2",
  "camera_id": "mlk-central-cam-2",
  "intersection": true,
  "id": "644d1c06-4c60-4ed8-93b4-1aa79b87a622",
  "label": "car",
  "timestamp": 1586838108683,
  "locations": [
    {
      "timestamp": 1586838109448,
      "coords": 1626.3220383482665,
      "street_segment": "None"
    },
    {
      "timestamp": 1586838109832,
      "coords": 1623.3129222859882,
      "street_segment": "None"
    }
  ],
  "hit_counts": 2
}

```

The locations field is a list of "objects" which contain the fields: coords, location, street\_segment, and timestamp. Messages have varying lengths of locations. The code above can be used to recreate the issue. Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 14, 2020, 2:55pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/2 "2020-04-14T14:55:41Z")

</div>

Welcome!

Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.

Instead, paste the text and format it with `</>` icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.

It would be great if you could update your post to solve this.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![austin-harris](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@austin-harris](https://discuss.elastic.co/u/austin-harris)\
**Post date:** [April 14, 2020, 3:01pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/3 "2020-04-14T15:01:42Z")

</div>

Absolutely, I will update it now and add the requested information. Thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 14, 2020, 3:25pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/4 "2020-04-14T15:25:53Z")

</div>

I ran your script (with a small change):

```auto
DELETE vision_events
PUT vision_events
{
  "settings" : {
        "number_of_shards" : 5
    },
  "mappings" : {
        "properties": {
          "camera_id": {
            "type": "text",
            "fields": {
              "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "hit_counts": {
          "type": "long"
        },
        "id": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "intersection": {
          "type": "boolean"
        },
        "label": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "locations": {
          "type" : "nested",
           "properties": {
            "coords" : {
                "type" : "float"
            },
            "location": {
              "type": "text"
            },
            "street_segment": {
              "type": "text"
            },
            "timestamp": {
              "type": "date"
            }
          }
        },
        "pole_id": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "timestamp": {
        "type": "date"
        }
      }
    }
}
PUT /vision_events/_doc/1
{
  "pole_id": "mlk-central-2",
  "camera_id": "mlk-central-cam-2",
  "intersection": true,
  "id": "644d1c06-4c60-4ed8-93b4-1aa79b87a622",
  "label": "car",
  "timestamp": 1586838108683,
  "locations": [
    {
      "timestamp": 1586838109448,
      "coords": 1626.3220383482665,
      "street_segment": "None"
    },
    {
      "timestamp": 1586838109832,
      "coords": 1623.3129222859882,
      "street_segment": "None"
    }
  ],
  "hit_counts": 2
}

```

And got:

```auto
{
  "_index" : "vision_events",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

```

---

<div class="post-metadata">

**Author:** ![austin-harris](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@austin-harris](https://discuss.elastic.co/u/austin-harris)\
**Post date:** [April 14, 2020, 3:30pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/5 "2020-04-14T15:30:39Z")

</div>

This works for me also. However, I still get this error when messages are sent via a Kafka ES Connector. These messages are the exact format as the test message above. I may need to post this else where or reword the post. Any thoughts? Thank you for your help.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 14, 2020, 3:54pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/6 "2020-04-14T15:54:14Z")

</div>

It probably means that the mapping or the documents are not strictly identical to the example you shared.

---

<div class="post-metadata">

**Author:** ![austin-harris](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@austin-harris](https://discuss.elastic.co/u/austin-harris)\
**Post date:** [April 14, 2020, 9:54pm UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/7 "2020-04-14T21:54:45Z")

</div>

I created a dead letter queue for Kafka Connect. Its rejected by ES and sent to the DLQ. I copy the message directly out of the DLQ and paste it into Kibana Dev Tools with a POST and it gets created.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 15, 2020, 4:56am UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/8 "2020-04-15T04:56:45Z")

</div>

But how is read the DLQ? Any chance you could debug/print the exact document which is sent over the network?

---

<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:** [May 13, 2020, 4:56am UTC](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938/9 "2020-05-13T04:56:50Z")

</div>

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