1

Trying to specify format (in index mapping) for the date field in ES 7.6. Any of these are not accepted:

        "createdAt" : {
          "type" : "date",
          "format": "yyyy-MM-dd'''T'''HH:mm:ss.SSSZZ"
        },
        "createdAt" : {
          "type" : "date",
          "format": "yyyy-MM-dd'T'HH:mm:ss.SSSZZ"
        },

Error is always the same:

"type" : "illegal_argument_exception", "reason" : "Invalid format: [yyyy-MM-ddTHH:mm:ss.SSSZZ]: Unknown pattern letter: T",

Here is full example to reproduce:

curl -X DELETE "localhost:9200/example?pretty"
curl -X PUT   "localhost:9200/example/_mappings?pretty" -H 'Content-Type: application/json' -d' {
      "dynamic": false,
      "properties" : {
        "name" : {
          "type" : "text"
        },
        "createdAt" : {
          "type" : "date",
          "format" : "yyyyMMdd'T'HHmmss.SSSZ"
        }
      }
}'
2
  • it's even before inserting data, just mapping itself. Commented Mar 5, 2020 at 14:14
  • @Lupanoide updated question - added full example Commented Mar 5, 2020 at 14:18

1 Answer 1

3

You can check various supported date format on https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html:

The correct format for your date format is below

"format" : "yyyyMMdd'T'HHmmss.SSSZ" (no - in between yyyyMMdd)

I just created an index with below format, so that you can try yourself:

{
  "mappings": {
    "properties": {
      "date": {
        "type": "date" ,
        "format" : "yyyyMMdd'T'HHmmss.SSSZ" --> notice there is no `-` in yyyyymmdd
      }
    }
  }
}

EDIT:- As per the latest update from OP, he is using the curl command to create the indices, hence he needs to escape the apostrophe('') present in the date T field.

Proper curl command would like below:

curl -X PUT "localhost:9500/example/_mappings?pretty" -H 'Content-Type: application/json' -d' {
      "dynamic": false,
      "properties" : {
        "name" : {
          "type" : "text"
        },
        "createdAt" : {
          "type" : "date",
          "format" : "yyyyMMdd'\''T'\''HHmmss.SSSZ" --> notice escape `T`
        }
      }
}'

Which gives proper output in curl:

{
  "acknowledged" : true
}
Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't work... I tried your example with single and three <'> and getting the same error. "type" : "illegal_argument_exception", "reason" : "Invalid format: [yyyyMMddTHHmmss.SSSZ]: Unknown pattern letter: T", "caused_by" : { "type" : "illegal_argument_exception", "reason" : "Unknown pattern letter: T"} I even checked with just 'yyyyMMdd' to see that it works in at least some way...
@user2220154, you are using curl, this you should have mentioned in first place :-), anyway updated my answer with proper curl command., enjoy
Thanks for teaching us how to properly escape the 'T' part, I was struggling with this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.