# Class\_cast\_exception for dynamic field with "." in its name

**URL:** <https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819>\
**Category:** Elasticsearch\
**Created:** [November 29, 2018, 8:14pm UTC](https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819 "2018-11-29T20:14:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Ensslen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steven_ensslen/32/26984_2.png) [@Steven\_Ensslen](https://discuss.elastic.co/u/Steven_Ensslen)\
**Post date:** [November 29, 2018, 8:14pm UTC](https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819/1 "2018-11-29T20:14:31Z")

</div>

I have an index with dynamic\_templates set as follows

```
"dynamic_templates": [
            {
                "all_dynamic_as_keyword": {
                    "match_mapping_type": "*",
                    "mapping": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        ],

```

I later some data arrives that has new fields like:

```
"order_survey": {
  "2. Adult Name": "N/a",
  "1. Adult Name": "Someones Name",
  "1. Child Name/Age": "A Childs name"
},

```

At that point`GET index/_mapping` shows

```
"order_survey": {
        "properties": {
          "1": {
            "properties": {
              " Adult Name": {
                "type": "keyword",
                "ignore_above": 256
              },
              " Child Name/Age": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "2": {
            "properties": {
              " Adult Name": {
                "type": "keyword",
                "ignore_above": 256
              },
              " Child Name/Age": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },

```

This has occurred because some previous, similar data worked. However some of the data returns

```
{
 "index": {
   "_index": "ticket-v8",
   "_type": "doc",
   "_id": "ffadc8e9-2016-1ec4-7135-9b8806d36ae0",
   "status": 400,
   "error": {
     "type": "mapper_parsing_exception",
     "reason": "failed to parse",
     "caused_by": {
       "type": "class_cast_exception",
       "reason": "org.elasticsearch.index.mapper.KeywordFieldMapper cannot be cast to org.elasticsearch.index.mapper.ObjectMapper"
     }
   }
 }

```

}

Removing the `dynamic_templates` from the index fixes the problem.

I am completely confused. Once one document has been seen with a field, then that field is mapped, and dynamic\_templates are no longer involved. Right? So how can the behavior of a second document with the same field be affected by dynamic\_templates?

Also, even though the mapping has split "1" and "2" into their own objects, when the data is queried the document comes back:

```
"order_survey": {
  "1. Adult Name": "An Adults name",
  "1. Child Name/Age": "A childs name/9yrs. of age",
  "2. Adult Name": "Another adults name"
 },

```

I appreciate that the index design leaves a lot to be desired. I'm trying to discover why the error occurs.

Thanks,

Steven

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 7, 2018, 5:05pm UTC](https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819/2 "2018-12-07T17:05:09Z")

</div>

Can you give an example of a document that triggers the above error?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 7, 2018, 5:07pm UTC](https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819/3 "2018-12-07T17:07:41Z")

</div>

I noticed that the error message reports that the type name is `doc` while the above get-mappings call returns `order_survey` as a type. Could it be that the same field is mapped as an object in one type and as a keyword in another type?

---

<div class="post-metadata">

**Author:** ![Steven\_Ensslen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steven_ensslen/32/26984_2.png) [@Steven\_Ensslen](https://discuss.elastic.co/u/Steven_Ensslen)\
**Post date:** [December 11, 2018, 8:42pm UTC](https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819/4 "2018-12-11T20:42:45Z")

</div>

Hi, order survey is **not** a type, it is an object. I did not include the whole mapping, only the portion of interest.

---

<div class="post-metadata">

**Author:** ![Steven\_Ensslen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steven_ensslen/32/26984_2.png) [@Steven\_Ensslen](https://discuss.elastic.co/u/Steven_Ensslen)\
**Post date:** [December 11, 2018, 8:59pm UTC](https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819/5 "2018-12-11T20:59:22Z")

</div>

This document triggers the error:

```
{
       "@timestamp" => 2018-12-11T20:54:24.433Z,
  "membership_code" => "1876614",
 "event_session_id" => "b62b828b-3f70-0124-51e1-bcd815955228",
      "seller_name" => "confidential data removed",
             "slug" => "confidential data removed",
       "valid_flag" => true,
   "identity_email" => "PII removed",
       "event_name" => "confidential data removed",
       "group_flag" => false,
          "cart_id" => "72fe80c5-4b9d-6444-72b6-ba75695e188d",
               "id" => "8960d6a2-68b1-6073-eba2-a7cab025bdc2",
     "purchased_on" => 2018-11-29T16:03:46.000Z,
   "identity_extra" => {
        "city" => "PII removed",
     "address" => "PII removed",
       "phone" => "PII removed",
    "zip_code" => "PII removed",
     "from_re" => "2018-09-18T06:36:20Z",
       "state" => "PII removed",
     "country" => "PII removed"
},
        "seller_id" => "2a3edbe8-b0dc-4158-3246-c723b7f0b9d5",
      "cart_number" => "72FE80C5",
     "order_number" => "4JB-RFK-973Y",
      "relevant_at" => 2019-02-23T00:00:00.000Z,
"order_and_session" => "48e3424c-7d6d-15fa-a7a4-33888e672bbb:b62b828b-3f70-0124-51e1-bcd815955228",
         "order_id" => "48e3424c-7d6d-15fa-a7a4-33888e672bbb",
    "identity_name" => "PII removed",
   "event_category" => "Upsell",
 "ticket_type_name" => "Adult",
       "face_value" => "65.00",
          "gl_code" => "41406-0-523-0000-0000",
   "adjusted_value" => "65.00",
         "@version" => "1",
           "search" => " 72FE80C5 PII removed 2018-09-18T06:36:20Z PII removed 1876614 4JB-RFK-973Y PII removed B6D3AF9C86",
   "start_datetime" => 2019-02-23T00:00:00.000Z,
"ticket_group_name" => "Individual",
"event_template_id" => "9631a246-aa51-ee65-49e2-99df3b713079",
     "order_survey" => {
    "1. Child Name/Age" => "PII removed/9yrs. of age",
        "1. Adult Name" => "PII removed",
        "2. Adult Name" => "PII removed"
},
      "identity_id" => "0a53a0a2-3999-836c-ba25-c7218337aad6",
       "channel_id" => "cms"
}
```

---

<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:** [January 8, 2019, 8:59pm UTC](https://discuss.elastic.co/t/class-cast-exception-for-dynamic-field-with-in-its-name/158819/6 "2019-01-08T20:59:26Z")

</div>

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