OpenSearch icon indicating copy to clipboard operation
OpenSearch copied to clipboard

[BUG] dynamic_template throws class_cast_exception

Open sharathganga opened this issue 1 year ago • 2 comments

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.

sharathganga avatar Feb 13 '24 07:02 sharathganga

[Triage - attendees 1 2 3 4 5 6 7 8] @sharathganga Thanks for filing, we'd welcome a pull request to address this issue.

peternied avatar Feb 14 '24 16:02 peternied

@peternied I'm not familiar with Java. Would anyone be so kind as to provide a fix for this problem? Your assistance would be greatly appreciated.

Also is there a workaround for this issue?

sharathganga avatar Feb 16 '24 05:02 sharathganga