doudou5421 2015-02-10 14:09
浏览 149
已采纳

无法将mysql时间戳映射到elasticsearch

I want to insert one of my mysql tables into elasticsearch for search purposes but I am having problem mapping a timestamp from mysql into ES.

In mysql my timestamp looks like "2015-01-01 15:30:34", I have tried mapping it as "timestamp" / "int" / "long" but nothing works. And looking at the ES docs it looks like ES expect a timestamp to look like "2015-01-01T15:30:34"

with a "T" in it.

Cant I map a normal mysql timestamp as "2015-01-01 15:30:34" into ES?

Second question: Since I only have one table in MySql that I want to be searched I only have that table in ES. And I am doing so by: Every time a new row gets inserted/updated/deleted in MySql that same row gets inserted/updated/deleted right after into ES. Is that the right way to do it? In order to keep the index updated live.

I am using the Laravel package: https://github.com/adamfairholm/Elasticquent

Since thats the easiest one I found for someone whos new at ES.

  • 写回答

1条回答 默认 最新

  • dounangqie4819 2015-02-10 16:18
    关注

    The timestamp containing the T is in ISO 8601 format. Since Laravel uses Carbon you can use it to convert the string to ISO 8601 like so:

    $myDateTime->toIso8601String();
    

    As for your second question, you're approach is good. By syncing your MySQL insert, update and delete actions with ES, you assure that the ES index is up to date in near real time.

    If doing real time reindexing of the ES documents turns out to be bad for performance (usually if you have frequent inserts, updates and deletes), you can setup a cron to sync and reindex the ES documents at a given interval.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据