Skip to content

[BUG] dynamic_template throws class_cast_exception #12298

@sharathganga

Description

@sharathganga

Describe the bug

I trying to use dynamic_templates to map nested objects in a document as flat_object but receive the following error which has something to do with dotted field names:

{
  "error": {
    "root_cause": [
      {
        "type": "class_cast_exception",
        "reason": "class_cast_exception: class org.opensearch.index.mapper.FlatObjectFieldMapper cannot be cast to class org.opensearch.index.mapper.ObjectMapper (org.opensearch.index.mapper.FlatObjectFieldMapper and org.opensearch.index.mapper.ObjectMapper are in unnamed module of loader 'app')"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse",
    "caused_by": {
      "type": "class_cast_exception",
      "reason": "class_cast_exception: class org.opensearch.index.mapper.FlatObjectFieldMapper cannot be cast to class org.opensearch.index.mapper.ObjectMapper (org.opensearch.index.mapper.FlatObjectFieldMapper and org.opensearch.index.mapper.ObjectMapper are in unnamed module of loader 'app')"
    }
  },
  "status": 400
}

Related component

Indexing

To Reproduce

PUT _index_template/test_logs
{
  "index_patterns": [
    "test*"
  ],
  "template": {
    "mappings": {
      "dynamic_templates": [     
        {
          "nested_object_fields": {
            "match": "*",
            "match_mapping_type": "object",
            "mapping": {
              "type": "flat_object"
            }
          }
        }        
      ]   
    }
  }
}

PUT test_logs/_doc/1
{
  "k8s.application.name": "test-app",
  "k8s.container.restart_count": "0",  
  "k8s.namespace.name": "test",
  "k8s.pod.name": "test-app-9f45bf4b-v76fr",  
  "network": {
    "ip_address": "10.10.1.10", 
    "security_group_id": "sg-111111111111111", 
    "subnet_id": "subnet-111111111111111",
    "vpc_id": "vpc-111111111111111"
  }
}

Expected behavior

The dotted field names should be mapped as text and nested objects should be mapped as flat_object when indexed.

Additional Details

Plugins
None

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: AWS Opensearch
  • Version 2.11

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingIndexing, Bulk Indexing and anything related to indexingbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions