Time Field (Hours/Minutes) Format "HH:mm"


(Mehdi AOUADI) #1

I need a field with HH:mm format. I mapped it in the index usgin a HH:mm Format :

"hour_start" : { "type" : "date", "format" : "HH:mm" }

I retrieve the values from a semicolon separated values file :

valueA;valueB;21:00;otherValues

I use an exec input command cat on the file and hen a split filter. The time field is retrieved correctly but when the field is indexed it generates an error both in logstash and elasticsearch :

MapperParsingException[failed to parse [hour_start]]; nested: IllegalArgumentException[Invalid format: "hour_start"];
        at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:329)
        at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:311)
        at org.elasticsearch.index.mapper.DocumentParser.parseValue(DocumentParser.java:438)
        at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:264)
        at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:124)
        at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:309)
        at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:580)
        at org.elasticsearch.index.shard.IndexShard.prepareIndexOnPrimary(IndexShard.java:559)
        at org.elasticsearch.action.index.TransportIndexAction.prepareIndexOperationOnPrimary(TransportIndexAction.java:211)
        at org.elasticsearch.action.index.TransportIndexAction.executeIndexRequestOnPrimary(TransportIndexAction.java:223)
        at org.elasticsearch.action.bulk.TransportShardBulkAction.shardIndexOperation(TransportShardBulkAction.java:327)
        at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:120)
        at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:68)
        at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryPhase.doRun(TransportReplicationAction.java:648)
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
        at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:279)
        at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:271)
        at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77)
        at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376)
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Invalid format: "hour_start"
        at org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187)
        at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:826)
        at org.elasticsearch.index.mapper.core.DateFieldMapper$DateFieldType.parseStringValue(DateFieldMapper.java:366)
        at org.elasticsearch.index.mapper.core.DateFieldMapper.innerParseCreateField(DateFieldMapper.java:534)
        at org.elasticsearch.index.mapper.core.NumberFieldMapper.parseCreateField(NumberFieldMapper.java:241)
        at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:321)
        ... 22 more

And then the value is stored in the document with a full date format :

hour_start:December 31st 1969, 21:00:00.000

How to manage time field with only hours and minutes ?


(Mark Walkom) #2

This sounds like an ES question more than an LS one.

Have you tried hour_minute or strict_hour_minute from https://www.elastic.co/guide/en/elasticsearch/reference/5.1/mapping-date-format.html


(Mehdi AOUADI) #3

I updated the mapping using strict_hour_minute Date Format :
"hour_start" : { "type" : "date", "format" : "HH:mm" }

It is working !


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.