开发者社区> 问答> 正文

ES:索引模板不会从UNIX时间戳转换为日期

我将来自Apache Spark的文档通过Structured Streaming插入到ES中。

但是Spark-ES连接器中存在一个未解决的错误(https://github.com/elastic/elasticsearch-hadoop/issues/1173),其负面影响是源端(Spark)上的日期字段作为unix发送-timestamps / long类型到接收器(ES)。

我认为在ES端转换它的索引模板可能是一个很好的解决方法,可以在ES中使用正确的格式(日期)。

我的索引模板是:

{
"index_patterns": "my_index_*",
"mappings": {

"peerType_count": {
  "dynamic_templates": [
    {
      "timestamps": {
        "path_match": "*.window.*",
        "match_mapping_type": "long",
        "mapping": {
          "type": "date",
          "format": "epoch_millis"
        }
      }
    }
  ]
}

}
}
但是ES中的文档仍然是unix时间戳: - /

{
"_index": "my_index",
"_type": "peerType_count",
"_id": "kUGWNmcBtkL7EG0gS280",
"_version": 1,
"_score": 1,
"_source": {

"window": {
  "start": 1535958000000,
  "end": 1535958300000
},
"input__source_peerType": "peer2",
"count": 1

}
}
有人知道可能是什么问题吗?

PS:有没有可用的es-mapping-debugger?

展开
收起
社区小助手 2018-12-12 11:10:38 5432 0
1 条回答
写回答
取消 提交回答
  • 社区小助手是spark中国社区的管理员,我会定期更新直播回顾等资料和文章干货,还整合了大家在钉群提出的有关spark的问题及回答。

    只需在ES中使用以下http请求创建一个摄取管道:

    PUT _ingest/pipeline/fix_date_1173
    {

    "description": "converts from unix ms to date, workaround for https://github.com/elastic/elasticsearch-hadoop/issues/1173",
    "processors": [
      {
        "date": {
          "field": "window.start",
          "formats": ["UNIX_MS"],
          "target_field":"window.start"
        }
      },
      {
        "date": {
          "field": "window.end",
          "formats": ["UNIX_MS"],
          "target_field":"window.end"
        }
      }
    ]

    }
    并在你的spark 代码中启用它

    .option("es.ingest.pipeline", "fix_date_1173")

    2019-07-17 23:20:02
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载