我正在使用NiFi将一些数据放入ElasticSearch。我创建了以下ES索引:
curl -XPUT http://localhost:9200/test_index -H 'Content-Type: application/json' -d'
{
"index_patterns" : ["test_index"],
"mappings" : {
"doc" : {
"properties" : {
"example1" : { "type": "text" },
"example2" : { "type": "text" },
"Date" :
{ "type": "date",
"format": "yyyy-MM-dd HH:mm:ss" }
}
}
}
}'
这加载到ES中,没问题。但是,通过我的NiFi流传来的Date
对象是这样的:
"Date" : "Fri, 09 Nov 2018 18:30:49 GMT"
我的PutElasticsearchHttp
处理器给我一个错误:
ERROR [Timer-Driven Process Thread-1] o.a.n.p.e.PutElasticsearchHttp
PutElasticsearchHttp[id=55b31b9a-3319-124c-4ede-0d3e8c02e9cb] Failed to
process StandardFlowFileRecord[uuid=5b6d8fc7-0dfd-435d-8a5c-
adb4cdb08495,claim=StandardContentClaim
[resourceClaim=StandardResourceClaim[id=1541788260542-269,
container=default, section=269], offset=176034,
length=187],offset=0,name=ba74c484-9719-418f-a665-
7b7d492b40a4,size=187] due to failed to parse [Date], transferring to
failure
我需要更改日期格式吗? (也许通过UpdateAttribute
吗?)
答案 0 :(得分:1)
是的,您需要将nifi中的日期设置为更常见的格式,例如https://en.wikipedia.org/wiki/ISO_8601,或在es映射中设置自定义日期格式。
请查看此处描述的模式:https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
如果您需要了解如何在es中定义自定义日期映射,请查看以下内容:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html