6

To begin with, the date format that that is stored in the index is 2021-09-16T14:06:02.000000Z

When I log in with the option to remember the user and then I log out, I get the following error.

The response from ElasticSearch is

array:3 [▼
  "took" => 1
  "errors" => true
  "items" => array:1 [▼
    0 => array:1 [▼
      "index" => array:5 [▼
        "_index" => "users"
        "_type" => "_doc"
        "_id" => "313"
        "status" => 400
        "error" => array:3 [▼
          "type" => "mapper_parsing_exception"
          "reason" => "failed to parse field [created_at] of type [date] in document with id '313'. Preview of field's value: '2021-09-16 11:37:49'"
          "caused_by" => array:3 [▼
            "type" => "illegal_argument_exception"
            "reason" => "failed to parse date field [2021-09-16 11:37:49] with format [strict_date_optional_time||epoch_millis]"
            "caused_by" => array:2 [▼
              "type" => "date_time_parse_exception"
              "reason" => "Failed to parse with all enclosed parsers"
            ]
          ]
        ]
      ]
    ]
  ]
]

This happens because when a user logs out, the remember_token attribute is modified and since the User model is modified, the index is updated.

The problem is that when it tries to update the index, the format of the date it tries to store in the index is not 2021-09-16T14:06:02.000000Z anymore

Instead, now the date format is 2021-09-16 11:37:49 and therefore there is a conflict in the date format that is already in the index and the date format that it tries to store.

This happens only when the framework updates the User model, when a user logs out. This does not happen if I update the attribute of any model myself.

UPDATED

I just noticed that then laravel updates the remember_token, it disables the timestamps and that is why the date format changes to 2021-09-16 11:37:49.

However, I still don't know how to fix this issue.

Orestis uRic
  • 347
  • 1
  • 6
  • 11

2 Answers2

10

It seem that your application break the rule (date type format) required by Elasticsearch. Type date format default to strict_date_optional_time||epoch_millis, see the doc.

Either you fix your application so that it write 2021-09-16T14:06:02.000000Z rather than 2021-09-16 11:37:49, or just 2021-09-16, because default format require that, see the doc Built In Formats:

date_optional_time or strict_date_optional_time

A generic ISO datetime parser, where the date must include the year at a minimum, and the time (separated by T), is optional. Examples: yyyy-MM-dd'T'HH:mm:ss.SSSZ or yyyy-MM-dd.

Or you change the mapping of your Elasticsearch index to allow the format of 2021-09-16 11:37:49 use multiple date formats when mapping. You will need to explicitly set type of the index (and perform a _reindex afterwards to pull the data into your new index if necessary).

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "created_at": {
        "type":   "date",
        "format": "yyyy-MM-dd HH:mm:ss||strict_date_optional_time ||epoch_millis"
      }
    }
  }
}

The yyyy-MM-dd HH:mm:ss format should be able to parse your data entry similar to 2021-09-16 11:37:49.

Hopefully this will help.

Han Ye
  • 128
  • 2
  • 8
1

I just faced the same issue and this format solved my problem: 2023-01-10 20:15:25.000+0300.

Other formats I had tried but not working:

  • 2022-01-01
  • 2021-09-16 11:37:49
  • 2023-01-19 05:30:00.000Z
  • 2023-01-19 05:30:00.0000
menoktaokan
  • 346
  • 3
  • 13