What Should I Do If the Log Prompts that the Date Format Fails to Be Parsed?
Symptom
Possible Cause
CSS has a special processing mechanism on the time field. If the stored time data does not contain the time zone information, Kibana considers the time as the GMT.
The time displayed in the log may be different from the local time. For example, the time displayed in the log is eight hours earlier than the local time in the GMT+08:00 time zone. Therefore, when CDM migrates data to Cloud Search Service, if the index and type are automatically created by CDM (for example, if date_test and test1 of the migration destination highlighted in Figure 2 do not exist in Cloud Search Service, CDM automatically creates the index and type in Cloud Search Service), CDM, by default, sets the format of the time field to the standard format of yyyy-MM-dd HH:mm:ss.SSS Z, for example, 2018-01-08 08:08:08.666 +0800.
When data is imported from another data source to CSS, if the date format in the source data is not the standard format, for example, 2018/01/05 15:15:46, the CDM job fails to be executed, and the log shows that the date format cannot be parsed. You need to configure a field converter on CDM to convert the format of the date field to the required format of CSS.
Solution
- Edit the job and go to the Map Field tab page. Click the icon for creating a converter in the row of the source field to create a converter. See Figure 3.
- Select Expression conversion as the converter. Currently, expression conversion supports functions of the character string and date types. The syntax is similar to the Java character string and time functions. For details about how to compile the expression, see Expression Conversion.
- In this example, the source time format is yyyy/MM/dd HH:mm:ss. To convert the source time format to yyyy-MM-dd HH:mm:ss.SSS Z, perform the following operations:
- Add the time zone information +0800 to the end of the original date character string. The corresponding expression is value+" +0800".
- Use the original date format to parse the string to a date object. You can use the DateUtils.parseDate function for parsing. The syntax is DateUtils.parseDate(String value, String format).
- Format the date object into a character string in target format by using the DateUtils.format function. The syntax is DateUtils.format(Date date, String format).
In this example, the complete expression is DateUtils.format(DateUtils.parseDate(value+" +0800","yyyy/MM/dd HH:mm:ss Z"),"yyyy-MM-dd HH:mm:ss.SSS Z"). See Figure 4.
- Save the converter configuration and save and run the job to solve the problem that Cloud Search Service fails to parse the date format.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.