Class_cast_exception for dynamic field with "." in its name

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

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

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?

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

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"
}

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