Skip to content

Different behaviour between Object and Dotted notations on ingestion #80584

Closed
@crisdarocha

Description

@crisdarocha

Elasticsearch version (bin/elasticsearch --version): 7.15.1

Description of the problem including expected versus actual behavior:

Trying to avoid fields explosion using the flattened type in a dynamic template.

PUT _template/mytemplate
{
  "order": 1,
  "index_patterns": [
    "myindex-*"
  ],
  "mappings": {
    "dynamic_templates": [
      {
        "no_deep_objects": {
          "path_match": "*.*.*",
          "match_mapping_type": "object",
          "mapping": {
            "type": "flattened"
          }
        }
      }
    ]
  }
}

When ingesting a document in Object notation it works fine:

POST myindex-01/_doc/
{
  "level1": {
    "level2": {
      "level3": {
        "level4": "myvalue"
      }
    }
  }
}

When ingesting the "same" document in Dotted notation it fails:

POST myindex-01/_doc/
{
  "level1.level2.level3.level4": "myvalue"
}

Error message:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Could not dynamically add mapping for field [level1.level2.level3.level4]. Existing mapping for [level1.level2.level3] must be of type object but found [flattened]."
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Could not dynamically add mapping for field [level1.level2.level3.level4]. Existing mapping for [level1.level2.level3] must be of type object but found [flattened]."
  },
  "status" : 400
}

One would expect the same behaviour, but unfortunately it's not happening.

Steps to reproduce:

Please include a minimal but complete recreation of the problem,
including (e.g.) index creation, mappings, settings, query etc. The easier
you make for us to reproduce it, the more likely that somebody will take the
time to look at it.

  1. Add a template that creates a flattened type after a certain level of nesting (see above)
  2. Add a document in Object notation and see it succeed
  3. Add a document in Dotted notation and see it fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search Foundations/MappingIndex mappings, including merging and defining field types>bugTeam:Search FoundationsMeta label for the Search Foundations team in Elasticsearch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions