翼度科技»论坛 编程开发 mysql 查看内容

解决Mysql同步到ES时date和time字段类型转换问题

4

主题

4

帖子

12

积分

新手上路

Rank: 1

积分
12
这个问题中发生问题的es字段映射类型为date类型!!!
字符串类型的会好很多,关键我这边是通过logstash生成索引,并且全量同步的,不好改索引类型!!!
问题描述:
  1. 这个报错我该怎么办呢2023-07-10 03:01:39.104 [pool-2-thread-1] INFO  c.a.o.canal.client.adapter.logger.LoggerAdapterExample - DML: {"data":[{"ORDER_ID":"4444","SETTLE_DATE_LOC":"20200329","TRANS_DATE":"20200329","TRANS_TIME":"165440","USER_ID":null,"SPACE_NO":null,"SPACE_NAME":null,"PARK_NO":"JC01331","PARK_NAME":"DELETED","CARNO":"沪A666666","CAR_IN_SEQ":"20200329165438071000000000785843","CAR_OUT_SEQ":null,"START_TIME":"20181126103000","END_TIME":null,"LENGTH":null,"OVER_VALID_TIME":null,"LEAVE_TIME":null,"STATUS":"03","PAY_STYLE":null,"TRANS_AMT":"0","PRE_AMT":"0","BALANCE":"0","FAV_AMT":"0","RET_AMT":"0","RET_STATUS":null,"SETTLE_STATUS":null,"SETTLE_DATE":null,"SETTLE_SEQ":null,"SETTLE_AMT":null,"REC_CRT_TIME":"20200329165440","REC_UPD_TIME":"20200329165440","OPR_FLAG":"0","RESVD1":null,"RESVD2":"11111111111111111111111111111111","IF_HOLD":"0","LAST_UPD_TIME":null,"LAST_UPD_RESV":null,"RESVD3":null,"RESVD4":null,"RESVD5":null,"RESVD6":null,"IN_TYPE":"00","IF_RENT":null,"ORG_ID":"0","MCHNT_NO":"1000058","MCHNT_NAME":"捷顺总部大厦停车场","IN_OUT_DATE":"2018-11-26","LEAVE_DATE":null,"IF_SCORE":"0","EXCEP_TYPE":null,"EXCEP_DATE":null,"EXCEP_TIME":null,"EXCEP_STATUS":null,"IF_PAYBACK":null,"DEVICE_TYPE":"112","SUB_DEVICE_TYPE":"r"}],"database":"cstc245_test","destination":"example","es":1688929250000,"groupId":"g1","isDdl":false,"old":null,"pkNames":["ORDER_ID","IN_OUT_DATE"],"sql":"","table":"tbl_ps_order_in","ts":1688929299104,"type":"INSERT"}2023-07-10 03:01:39.107 [pool-2-thread-1] DEBUG c.a.o.canal.client.adapter.es.core.service.ESSyncService - DML: {"data":[{"ORDER_ID":"4444","SETTLE_DATE_LOC":"20200329","TRANS_DATE":"20200329","TRANS_TIME":"165440","USER_ID":null,"SPACE_NO":null,"SPACE_NAME":null,"PARK_NO":"JC01331","PARK_NAME":"DELETED","CARNO":"沪A666666","CAR_IN_SEQ":"20200329165438071000000000785843","CAR_OUT_SEQ":null,"START_TIME":"20181126103000","END_TIME":null,"LENGTH":null,"OVER_VALID_TIME":null,"LEAVE_TIME":null,"STATUS":"03","PAY_STYLE":null,"TRANS_AMT":"0","PRE_AMT":"0","BALANCE":"0","FAV_AMT":"0","RET_AMT":"0","RET_STATUS":null,"SETTLE_STATUS":null,"SETTLE_DATE":null,"SETTLE_SEQ":null,"SETTLE_AMT":null,"REC_CRT_TIME":"20200329165440","REC_UPD_TIME":"20200329165440","OPR_FLAG":"0","RESVD1":null,"RESVD2":"11111111111111111111111111111111","IF_HOLD":"0","LAST_UPD_TIME":null,"LAST_UPD_RESV":null,"RESVD3":null,"RESVD4":null,"RESVD5":null,"RESVD6":null,"IN_TYPE":"00","IF_RENT":null,"ORG_ID":"0","MCHNT_NO":"1000058","MCHNT_NAME":"捷顺总部大厦停车场","IN_OUT_DATE":"2018-11-26","LEAVE_DATE":null,"IF_SCORE":"0","EXCEP_TYPE":null,"EXCEP_DATE":null,"EXCEP_TIME":null,"EXCEP_STATUS":null,"IF_PAYBACK":null,"DEVICE_TYPE":"112","SUB_DEVICE_TYPE":"r"}],"database":"cstc245_test","destination":"example","es":1688929250000,"groupId":"g1","isDdl":false,"old":null,"pkNames":["ORDER_ID","IN_OUT_DATE"],"sql":"","table":"tbl_ps_order_in","ts":1688929299104,"type":"INSERT"} Affected indexes: tbl_ps_order_in 2023-07-10 03:01:39.116 [pool-2-thread-1] ERROR c.a.otter.canal.adapter.launcher.loader.AdapterProcessor - ES sync commit error ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [START_TIME] of type [date] in document with id '4444'. Preview of field's value: '2018-11-26 10:30:00']]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=failed to parse date field [2018-11-26 10:30:00] with format [strict_date_optional_time||epoch_millis]]]; nested: ElasticsearchException[Elasticsearch exception [type=date_time_parse_exception, reason=Failed to parse with all enclosed parsers]];java.lang.RuntimeException: ES sync commit error ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [START_TIME] of type [date] in document with id '4444'. Preview of field's value: '2018-11-26 10:30:00']]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=failed to parse date field [2018-11-26 10:30:00] with format [strict_date_optional_time||epoch_millis]]]; nested: ElasticsearchException[Elasticsearch exception [type=date_time_parse_exception, reason=Failed to parse with all enclosed parsers]];    at com.alibaba.otter.canal.client.adapter.es7x.support.ESConnection$ES7xBulkResponse.processFailBulkResponse(ESConnection.java:470) ~[na:na]    at com.alibaba.otter.canal.client.adapter.es7x.support.ES7xTemplate.commit(ES7xTemplate.java:175) ~[na:na]    at com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService.commit(ESSyncService.java:873) ~[na:na]    at com.alibaba.otter.canal.client.adapter.es.core.ESAdapter.sync(ESAdapter.java:86) ~[na:na]    at com.alibaba.otter.canal.client.adapter.ProxyOuterAdapter.sync(ProxyOuterAdapter.java:42) ~[client-adapter.common-1.1.7-SNAPSHOT.jar:na]    at com.alibaba.otter.canal.adapter.launcher.loader.AdapterProcessor.batchSync(AdapterProcessor.java:139) ~[client-adapter.launcher-1.1.7-SNAPSHOT.jar:na]    at com.alibaba.otter.canal.adapter.launcher.loader.AdapterProcessor.lambda$null$1(AdapterProcessor.java:97) ~[client-adapter.launcher-1.1.7-SNAPSHOT.jar:na]    at java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:895) ~[na:1.8.0_262]    at com.alibaba.otter.canal.adapter.launcher.loader.AdapterProcessor.lambda$null$2(AdapterProcessor.java:94) ~[client-adapter.launcher-1.1.7-SNAPSHOT.jar:na]    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_262]    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_262]    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_262]    at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_262]2023-07-10 03:01:39.116 [Thread-4] ERROR c.a.otter.canal.adapter.launcher.loader.AdapterProcessor - Outer adapter sync failed!  Error sync and rollback, execute times: 17^C
复制代码
根据错误日志,似乎是Elasticsearch无法解析日期字段
  1. START_TIME
复制代码
。这个字段的格式是
  1. YYYY-MM-DD HH:MM:SS
复制代码
,而Elasticsearch期望的格式是
  1. strict_date_optional_time||epoch_millis
复制代码
  1. strict_date_optional_time
复制代码
格式的例子是
  1. 2015-01-01T12:10:30Z
复制代码
,而
  1. epoch_millis
复制代码
则是自1970-01-01 00:00:00 UTC以来的毫秒数。错误提示的意思是Elasticsearch试图使用这两种格式解析
  1. START_TIME
复制代码
字段,但是都失败了。
从这个错误信息来看,你可能需要将MySQL中的日期时间数据转换为Elasticsearch可以接受的格式。你可以尝试将日期时间数据转换为ISO 8601格式,或者转换为
  1. epoch_millis
复制代码
格式。
如果你有权限更改Elasticsearch索引的映射,你也可以更改
  1. START_TIME
复制代码
字段的类型为
  1. text
复制代码
,这样Elasticsearch就会将其当作普通字符串处理,而不会尝试将其解析为日期。
这种情况下,你可能需要更改日期字段的处理方式,你可以在SQL查询中使用
  1. UNIX_TIMESTAMP()
复制代码
函数将日期时间转换为
  1. epoch
复制代码
格式,或者在数据同步到Elasticsearch之前进行格式转换。具体解决方案需要根据你的实际情况来确定。
提问: 试了没用!!!
  1. 将包含 'date' 的字段使用 DATE_FORMAT 转换,只需要年月日就行,包含time的字段需要年月日时分秒并且尝试将日期时间数据转换为ISO 8601格式
  2. SELECT
  3.     a.ORDER_ID as _id,
  4.     a.ORDER_ID,
  5.     a.SETTLE_DATE_LOC,
  6.     a.TRANS_DATE,
  7.     a.TRANS_TIME,
  8.     a.USER_ID,
  9.     a.SPACE_NO,
  10.     a.SPACE_NAME,
  11.     a.PARK_NO,
  12.     a.PARK_NAME,
  13.     a.CARNO,
  14.     a.CAR_IN_SEQ,
  15.     a.CAR_OUT_SEQ,
  16.     a.START_TIME,
  17.     a.END_TIME,
  18.     a.LENGTH,
  19.     a.OVER_VALID_TIME,
  20.     a.LEAVE_TIME,
  21.     a.STATUS,
  22.     a.PAY_STYLE,
  23.     a.TRANS_AMT,
  24.     a.PRE_AMT,
  25.     a.BALANCE,
  26.     a.FAV_AMT,
  27.     a.RET_AMT,
  28.     a.RET_STATUS,
  29.     a.SETTLE_STATUS,
  30.     a.SETTLE_DATE,
  31.     a.SETTLE_SEQ,
  32.     a.SETTLE_AMT,
  33.     a.REC_CRT_TIME,
  34.     a.REC_UPD_TIME,
  35.     a.OPR_FLAG,
  36.     a.RESVD1,
  37.     a.RESVD2,
  38.     a.IF_HOLD,
  39.     a.LAST_UPD_TIME,
  40.     a.LAST_UPD_RESV,
  41.     a.RESVD3,
  42.     a.RESVD4,
  43.     a.RESVD5,
  44.     a.RESVD6,
  45.     a.IN_TYPE,
  46.     a.IF_RENT,
  47.     a.ORG_ID,
  48.     a.MCHNT_NO,
  49.     a.MCHNT_NAME,
  50.     a.IN_OUT_DATE,
  51.     a.LEAVE_DATE,
  52.     a.IF_SCORE,
  53.     a.EXCEP_TYPE,
  54.     a.EXCEP_DATE,
  55.     a.EXCEP_TIME,
  56.     a.EXCEP_STATUS,
  57.     a.IF_PAYBACK,
  58.     a.DEVICE_TYPE,
  59.     a.SUB_DEVICE_TYPE
  60. FROM tbl_ps_order_in a
复制代码
回答
你想将查询中包含 ‘date’ 的字段用 DATE_FORMAT 转换为仅包含年月日的格式,同时,包含 ‘time’ 的字段需要年月日时分秒,而且要将日期时间数据转换为ISO 8601格式。以下是你可以使用的SQL语句:
  1. SELECT
  2.     a.ORDER_ID as _id,
  3.     a.ORDER_ID,
  4.     DATE_FORMAT(a.SETTLE_DATE_LOC, '%Y-%m-%d') as SETTLE_DATE_LOC,
  5.     DATE_FORMAT(a.TRANS_DATE, '%Y-%m-%d') as TRANS_DATE,
  6.     DATE_FORMAT(a.TRANS_TIME, '%Y-%m-%dT%H:%i:%s') as TRANS_TIME,
  7.     a.USER_ID,
  8.     a.SPACE_NO,
  9.     a.SPACE_NAME,
  10.     a.PARK_NO,
  11.     a.PARK_NAME,
  12.     a.CARNO,
  13.     a.CAR_IN_SEQ,
  14.     a.CAR_OUT_SEQ,
  15.     DATE_FORMAT(a.START_TIME, '%Y-%m-%dT%H:%i:%s') as START_TIME,
  16.     DATE_FORMAT(a.END_TIME, '%Y-%m-%dT%H:%i:%s') as END_TIME,
  17.     a.LENGTH,
  18.     a.OVER_VALID_TIME,
  19.     DATE_FORMAT(a.LEAVE_TIME, '%Y-%m-%dT%H:%i:%s') as LEAVE_TIME,
  20.     a.STATUS,
  21.     a.PAY_STYLE,
  22.     a.TRANS_AMT,
  23.     a.PRE_AMT,
  24.     a.BALANCE,
  25.     a.FAV_AMT,
  26.     a.RET_AMT,
  27.     a.RET_STATUS,
  28.     a.SETTLE_STATUS,
  29.     DATE_FORMAT(a.SETTLE_DATE, '%Y-%m-%d') as SETTLE_DATE,
  30.     a.SETTLE_SEQ,
  31.     a.SETTLE_AMT,
  32.     DATE_FORMAT(a.REC_CRT_TIME, '%Y-%m-%dT%H:%i:%s') as REC_CRT_TIME,
  33.     DATE_FORMAT(a.REC_UPD_TIME, '%Y-%m-%dT%H:%i:%s') as REC_UPD_TIME,
  34.     a.OPR_FLAG,
  35.     a.RESVD1,
  36.     a.RESVD2,
  37.     a.IF_HOLD,
  38.     DATE_FORMAT(a.LAST_UPD_TIME, '%Y-%m-%dT%H:%i:%s') as LAST_UPD_TIME,
  39.     a.LAST_UPD_RESV,
  40.     a.RESVD3,
  41.     a.RESVD4,
  42.     a.RESVD5,
  43.     a.RESVD6,
  44.     a.IN_TYPE,
  45.     a.IF_RENT,
  46.     a.ORG_ID,
  47.     a.MCHNT_NO,
  48.     a.MCHNT_NAME,
  49.     DATE_FORMAT(a.IN_OUT_DATE, '%Y-%m-%d') as IN_OUT_DATE,
  50.     DATE_FORMAT(a.LEAVE_DATE, '%Y-%m-%d') as LEAVE_DATE,
  51.     a.IF_SCORE,
  52.     a.EXCEP_TYPE,
  53.     DATE_FORMAT(a.EXCEP_DATE, '%Y-%m-%d') as EXCEP_DATE,
  54.     DATE_FORMAT(a.EXCEP_TIME, '%Y-%m-%dT%H:%i:%s') as EXCEP_TIME,
  55.     a.EXCEP_STATUS,
  56.     a.IF_PAYBACK,
  57.     a.DEVICE_TYPE,
  58.     a.SUB_DEVICE_TYPE
  59. FROM tbl_ps_order_in a
复制代码
注意,这个 SQL 查询是针对 MySQL 数据库的,假设所有的时间字段都是以字符串形式存储,如果字段的存储形式不同,这个查询可能需要做相应的调整。此外,‘%Y-%m-%dT%H:%i:%s’ 是 ISO 8601 时间格式的 MySQL 版本,如果你的数据库不支持这种格式,你可能需要在应用层面进行处理。
这个貌似解决不了!!!!!
下面是重头戏
你可以使用
  1. UNIX_TIMESTAMP()
复制代码
函数将日期和时间字段转换为epoch格式。这个函数将日期和时间的值转换为自1970-01-01 00:00:00 UTC以来的秒数。以下是你的SQL查询的一部分,展示了如何进行这种转换:
  1. SELECT
  2.     a.ORDER_ID as _id,
  3.     a.ORDER_ID,
  4.     UNIX_TIMESTAMP(a.SETTLE_DATE_LOC) as SETTLE_DATE_LOC,
  5.     UNIX_TIMESTAMP(a.TRANS_DATE) as TRANS_DATE,
  6.     UNIX_TIMESTAMP(STR_TO_DATE(a.TRANS_TIME, '%Y-%m-%d %H:%i:%s')) as TRANS_TIME,
  7.     a.USER_ID,
  8.     ...
  9.     UNIX_TIMESTAMP(STR_TO_DATE(a.START_TIME, '%Y-%m-%d %H:%i:%s')) as START_TIME,
  10.     UNIX_TIMESTAMP(STR_TO_DATE(a.END_TIME, '%Y-%m-%d %H:%i:%s')) as END_TIME,
  11.     ...
  12.     UNIX_TIMESTAMP(a.SETTLE_DATE) as SETTLE_DATE,
  13.     ...
  14.     UNIX_TIMESTAMP(STR_TO_DATE(a.REC_CRT_TIME, '%Y-%m-%d %H:%i:%s')) as REC_CRT_TIME,
  15.     UNIX_TIMESTAMP(STR_TO_DATE(a.REC_UPD_TIME, '%Y-%m-%d %H:%i:%s')) as REC_UPD_TIME,
  16.     ...
  17.     UNIX_TIMESTAMP(STR_TO_DATE(a.LAST_UPD_TIME, '%Y-%m-%d %H:%i:%s')) as LAST_UPD_TIME,
  18.     ...
  19.     UNIX_TIMESTAMP(a.IN_OUT_DATE) as IN_OUT_DATE,
  20.     UNIX_TIMESTAMP(a.LEAVE_DATE) as LEAVE_DATE,
  21.     ...
  22.     UNIX_TIMESTAMP(a.EXCEP_DATE) as EXCEP_DATE,
  23.     UNIX_TIMESTAMP(STR_TO_DATE(a.EXCEP_TIME, '%Y-%m-%d %H:%i:%s')) as EXCEP_TIME,
  24.     ...
  25. FROM tbl_ps_order_in a
复制代码
这里,我将所有的日期时间字段都用
  1. UNIX_TIMESTAMP()
复制代码
函数进行了处理。对于时间字段(如
  1. TRANS_TIME
复制代码
  1. START_TIME
复制代码
等),我还使用了
  1. STR_TO_DATE()
复制代码
函数,将其从字符串格式转换为日期时间格式,然后再调用
  1. UNIX_TIMESTAMP()
复制代码

注意,
  1. UNIX_TIMESTAMP()
复制代码
函数返回的是秒数,而Elasticsearch的
  1. epoch_millis
复制代码
格式是毫秒数。如果你需要毫秒数,你可以将
  1. UNIX_TIMESTAMP()
复制代码
函数的结果乘以1000。
以上的方案适用于MySQL。如果你的数据库是其他类型,可能需要用不同的方法来进行转换。
**提问:**试了有用!!!!
  1. SELECT
  2.     a.ORDER_ID as _id,
  3.     a.ORDER_ID,
  4.     a.SETTLE_DATE_LOC,
  5.     a.TRANS_DATE,
  6.     a.TRANS_TIME,
  7.     a.USER_ID,
  8.     a.SPACE_NO,
  9.     a.SPACE_NAME,
  10.     a.PARK_NO,
  11.     a.PARK_NAME,
  12.     a.CARNO,
  13.     a.CAR_IN_SEQ,
  14.     a.CAR_OUT_SEQ,
  15.     a.START_TIME,
  16.     a.END_TIME,
  17.     a.LENGTH,
  18.     a.OVER_VALID_TIME,
  19.     a.LEAVE_TIME,
  20.     a.STATUS,
  21.     a.PAY_STYLE,
  22.     a.TRANS_AMT,
  23.     a.PRE_AMT,
  24.     a.BALANCE,
  25.     a.FAV_AMT,
  26.     a.RET_AMT,
  27.     a.RET_STATUS,
  28.     a.SETTLE_STATUS,
  29.     a.SETTLE_DATE,
  30.     a.SETTLE_SEQ,
  31.     a.SETTLE_AMT,
  32.     a.REC_CRT_TIME,
  33.     a.REC_UPD_TIME,
  34.     a.OPR_FLAG,
  35.     a.RESVD1,
  36.     a.RESVD2,
  37.     a.IF_HOLD,
  38.     a.LAST_UPD_TIME,
  39.     a.LAST_UPD_RESV,
  40.     a.RESVD3,
  41.     a.RESVD4,
  42.     a.RESVD5,
  43.     a.RESVD6,
  44.     a.IN_TYPE,
  45.     a.IF_RENT,
  46.     a.ORG_ID,
  47.     a.MCHNT_NO,
  48.     a.MCHNT_NAME,
  49.     a.IN_OUT_DATE,
  50.     a.LEAVE_DATE,
  51.     a.IF_SCORE,
  52.     a.EXCEP_TYPE,
  53.     a.EXCEP_DATE,
  54.     a.EXCEP_TIME,
  55.     a.EXCEP_STATUS,
  56.     a.IF_PAYBACK,
  57.     a.DEVICE_TYPE,
  58.     a.SUB_DEVICE_TYPE
  59. FROM tbl_ps_order_in a将包含 'date' 的字段使用 DATE_FORMAT 转换,只需要年月日就行,包含time的字段需要格式化成年月日时分秒,并且用UNIX_TIMESTAMP()函数进行处理,然后还要将UNIX_TIMESTAMP()函数的结果乘以1000
复制代码
回答
根据您的需求,我将对包含 ‘date’ 的字段使用 DATE_FORMAT 进行年月日的格式化,对包含 ‘time’ 的字段,先将其格式化为年月日时分秒,然后使用 UNIX_TIMESTAMP() 函数处理,最后将结果乘以1000。以下是更新后的 SQL 查询:
  1. SELECT
  2.     a.ORDER_ID as _id,
  3.     a.ORDER_ID,
  4.     DATE_FORMAT(a.SETTLE_DATE_LOC, '%Y-%m-%d') as SETTLE_DATE_LOC,
  5.     DATE_FORMAT(a.TRANS_DATE, '%Y-%m-%d') as TRANS_DATE,
  6.     UNIX_TIMESTAMP(DATE_FORMAT(a.TRANS_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as TRANS_TIME,
  7.     a.USER_ID,
  8.     a.SPACE_NO,
  9.     a.SPACE_NAME,
  10.     a.PARK_NO,
  11.     a.PARK_NAME,
  12.     a.CARNO,
  13.     a.CAR_IN_SEQ,
  14.     a.CAR_OUT_SEQ,
  15.     UNIX_TIMESTAMP(DATE_FORMAT(a.START_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as START_TIME,
  16.     UNIX_TIMESTAMP(DATE_FORMAT(a.END_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as END_TIME,
  17.     a.LENGTH,
  18.     a.OVER_VALID_TIME,
  19.     UNIX_TIMESTAMP(DATE_FORMAT(a.LEAVE_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as LEAVE_TIME,
  20.     a.STATUS,
  21.     a.PAY_STYLE,
  22.     a.TRANS_AMT,
  23.     a.PRE_AMT,
  24.     a.BALANCE,
  25.     a.FAV_AMT,
  26.     a.RET_AMT,
  27.     a.RET_STATUS,
  28.     a.SETTLE_STATUS,
  29.     DATE_FORMAT(a.SETTLE_DATE, '%Y-%m-%d') as SETTLE_DATE,
  30.     a.SETTLE_SEQ,
  31.     a.SETTLE_AMT,
  32.     UNIX_TIMESTAMP(DATE_FORMAT(a.REC_CRT_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as REC_CRT_TIME,
  33.     UNIX_TIMESTAMP(DATE_FORMAT(a.REC_UPD_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as REC_UPD_TIME,
  34.     a.OPR_FLAG,
  35.     a.RESVD1,
  36.     a.RESVD2,
  37.     a.IF_HOLD,
  38.     UNIX_TIMESTAMP(DATE_FORMAT(a.LAST_UPD_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as LAST_UPD_TIME,
  39.     a.LAST_UPD_RESV,
  40.     a.RESVD3,
  41.     a.RESVD4,
  42.     a.RESVD5,
  43.     a.RESVD6,
  44.     a.IN_TYPE,
  45.     a.IF_RENT,
  46.     a.ORG_ID,
  47.     a.MCHNT_NO,
  48.     a.MCHNT_NAME,
  49.     DATE_FORMAT(a.IN_OUT_DATE, '%Y-%m-%d') as IN_OUT_DATE,
  50.     DATE_FORMAT(a.LEAVE_DATE, '%Y-%m-%d') as LEAVE_DATE,
  51.     a.IF_SCORE,
  52.     a.EXCEP_TYPE,
  53.     DATE_FORMAT(a.EXCEP_DATE, '%Y-%m-%d') as EXCEP_DATE,
  54.     UNIX_TIMESTAMP(DATE_FORMAT(a.EXCEP_TIME, '%Y-%m-%d %H:%i:%s')) * 1000 as EXCEP_TIME,
  55.     a.EXCEP_STATUS,
  56.     a.IF_PAYBACK,
  57.     a.DEVICE_TYPE,
  58.     a.SUB_DEVICE_TYPE
  59. FROM tbl_ps_order_in a
复制代码
注意:上述查询是在假设所有包含 ‘time’ 的字段都是 TIMESTAMP 类型,可以被转换为 ‘%Y-%m-%d %H:%i:%s’ 这种格式。如果不是这种类型,可能需要进行一些调整。
到此这篇关于Mysql同步到ES时date和time字段类型转换问题解决办法的文章就介绍到这了,更多相关mysql同步到ES内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

来源:https://www.jb51.net/database/291755dqc.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具