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.

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料