From fae6eaf690e51fe593116cd2e18640eadae599d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Dev=C3=A8ze?= Date: Fri, 9 Sep 2011 11:35:15 +0200 Subject: [PATCH] add time value definition of ttl inside source --- .../index/mapper/internal/TTLFieldMapper.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java index 3841dcb87bf..d6669d51e56 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java @@ -22,7 +22,9 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.AlreadyExpiredException; import org.elasticsearch.index.mapper.InternalMapper; import org.elasticsearch.index.mapper.Mapper; @@ -136,7 +138,12 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R @Override public void parse(ParseContext context) throws IOException, MapperParsingException { if (context.sourceToParse().ttl() < 0) { // no ttl has been provided externally - long ttl = context.parser().longValue(); + long ttl; + if (context.parser().currentToken() == XContentParser.Token.VALUE_STRING) { + ttl = TimeValue.parseTimeValue(context.parser().text(), null).millis(); + } else { + ttl = context.parser().longValue(); + } if (ttl <= 0) { throw new MapperParsingException("TTL value must be > 0. Illegal value provided [" + ttl + "]"); }