Invalid format exception using Date field in nested mapping

I created a mapping for elasticsearch as below:

Put testindex1

{
  "mappings": {
    "SAX_GROUPED": { 
      "_all":       { "enabled": false  }, 
      "properties": { 
        "key":    { "type": "string"  }, 
        "values": {
          "type": "nested", 
          "properties": {
            "x":    { "type": "date", "format": "MM/dd/yy HH:mm"  },
            "y": { "type": "integer"  }
          }
        }  
      }
    }
}
}

And then tried to put in some values:

{
        "key": "visitors",
        "values": [
            {
                "x": "12/23/13 01:03",
                "y": 123
            }
        ]
    }

I get the following exception:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse [values.x]"}],"type":"mapper_parsing_exception","reason":"failed to parse [values.x]","caused_by":{"type":"illegal_argument_exception","reason":"Invalid format: \"12/23/13\" is malformed at \"/23/13\""}},"status":400}

Please suggest what am i doing wrong when I'm trying to use a date field in a nested field.

Your example works perfectly:

DELETE testindex1
PUT testindex1
{
  "mappings": {
    "SAX_GROUPED": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "key": {
          "type": "string"
        },
        "values": {
          "type": "nested",
          "properties": {
            "x": {
              "type": "date",
              "format": "MM/dd/yy HH:mm"
            },
            "y": {
              "type": "integer"
            }
          }
        }
      }
    }
  }
}
PUT testindex1/SAX_GROUPED/1
{
  "key": "visitors",
  "values": [
    {
      "x": "12/23/13 01:03",
      "y": 123
    }
  ]
}

gives:

{
  "_index": "testindex1",
  "_type": "SAX_GROUPED",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "created": true
}

Index creation was successful and I was not able to put in values using:

{
        "key": "visitors",
        "values": [
            {
                "x": "12/23/13 01:03",
                "y": 123
            }
        ]
    }

Was able to resolve the issue, by using the following structure:

  {"SAX_GROUPED":[
{
        "key": "visitors",
        "values": [
            {
                "x": "12/23/13",
                "y": 123
            }
        ]
    }]
}

Thanks for sparing your time.

Then I think you are doing something wrong. SAX_GROUPED is a type according to your first post.

In the last example it's not a type anymore but an object field.

So even if it works, check that it behaves as you actually would like it to behave.

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