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

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:

 {
  "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:

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:

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.

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. 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.

1 Like

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

I ran your script (with a small change):

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:

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

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.

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

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.

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

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