Skip to content

Mapping: Specifying a date format as array creates invalid mapping #23650

@spinscale

Description

@spinscale

... yet it is allowed. See this example

Elasticsearch version: 5.2.1

DELETE test
DELETE test2

PUT test
{
  "mappings": {
    "foo": {
      "properties": {
        "x": {
          "type": "date",
          "format": "yyyy-MM-dd"
        }
      }
    }
  }
}

PUT test2
{
  "mappings": {
    "foo": {
      "properties": {
        "x": {
          "type": "date",
          "format": [ "yyyy-MM-dd" ]
        }
      }
    }
  }
}

GET test/foo/_mapping

GET test2/foo/_mapping

PUT _bulk
{ "index" : {"_index" : "test", "_type" : "foo" } }
{ "x" : "2017-03-20" }
{ "index" : {"_index" : "test2", "_type" : "foo" } }
{ "x" : "2017-03-20" }

the mapping calls return

GET test/foo/_mapping
{
  "test": {
    "mappings": {
      "foo": {
        "properties": {
          "x": {
            "type": "date",
            "format": "yyyy-MM-dd"
          }
        }
      }
    }
  }
}

GET test2/foo/_mapping
{
  "test2": {
    "mappings": {
      "foo": {
        "properties": {
          "x": {
            "type": "date",
            "format": "[yyyy-MM-dd]"
          }
        }
      }
    }
  }
}

Trying to index the same document in both indices results in

PUT _bulk
{ "index" : {"_index" : "test", "_type" : "foo" } }
{ "x" : "2017-03-20" }
{ "index" : {"_index" : "test2", "_type" : "foo" } }
{ "x" : "2017-03-20" }

{
  "took": 5,
  "errors": true,
  "items": [
    {
      "index": {
        "_index": "test",
        "_type": "foo",
        "_id": "AVrq5TOq1NgG2ZBFgd-y",
        "_version": 1,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "created": true,
        "status": 201
      }
    },
    {
      "index": {
        "_index": "test2",
        "_type": "foo",
        "_id": "AVrq5TOq1NgG2ZBFgd-z",
        "status": 400,
        "error": {
          "type": "mapper_parsing_exception",
          "reason": "failed to parse [x]",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": """Invalid format: "2017-03-20""""
          }
        }
      }
    }
  ]
}

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