# ISO8601 Durations

**URL:** <https://discuss.elastic.co/t/iso8601-durations/920>\
**Category:** Elasticsearch\
**Created:** [May 19, 2015, 6:39pm UTC](https://discuss.elastic.co/t/iso8601-durations/920 "2015-05-19T18:39:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oravecz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oravecz/32/44822_2.png) [@oravecz](https://discuss.elastic.co/u/oravecz)\
**Post date:** [May 19, 2015, 6:39pm UTC](https://discuss.elastic.co/t/iso8601-durations/920/1 "2015-05-19T18:39:24Z")

</div>

I would like to use [ISO8601 style duration](http://en.wikipedia.org/wiki/ISO_8601#Durations) values in my indexed documents, but ES does not support it natively. Is there a way to use custom analyzers or some other approach to convert these time periods to milliseconds on indexing and querying?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 19, 2015, 6:56pm UTC](https://discuss.elastic.co/t/iso8601-durations/920/2 "2015-05-19T18:56:00Z")

</div>

I'm reasonably sure you can write a plugin that adds a new datatype for  
that. Or you can convert on your side which is probably less work unless  
you are particularly used to Elasticsearch.

I don't think durations like that map to milliseconds though. You'd need to  
know the start dates and leap year rules for that. Maybe leap second rules  
if you are being super careful.

---

<div class="post-metadata">

**Author:** ![oravecz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oravecz/32/44822_2.png) [@oravecz](https://discuss.elastic.co/u/oravecz)\
**Post date:** [May 19, 2015, 7:40pm UTC](https://discuss.elastic.co/t/iso8601-durations/920/3 "2015-05-19T19:40:23Z")

</div>

Durations map ok to numerical values. What you are referring to is a time interval, which has the implication of a date component.

I don't see any documentation on how to achieve the type of mapping I want. I did review the docs on custom [transforms](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-transform.html), which is promising from the indexing point of view, but would not help me when it comes time to query.

Perhaps it doesn't make sense to query for a duration using ISO8601 formats, even though it might make sense to index in that way.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 19, 2015, 8:44pm UTC](https://discuss.elastic.co/t/iso8601-durations/920/4 "2015-05-19T20:44:36Z")

</div>

> [@oravecz](#):
>
> Durations map ok to numerical values. What you are referring to is a time interval, which has the implication of a date component.

I'm pretty sure they don't but that isn't really the issue here.

> [@oravecz](#):
>
> I don't see any documentation on how to achieve the type of mapping I want. I did review the docs on custom transforms, which is promising from the indexing point of view, but would not help me when it comes time to query.
> 
> Perhaps it doesn't make sense to query for a duration using ISO8601 formats, even though it might make sense to index in that way.

Transform isn't what you want at all - its move like `copy_to` on steroids. If you could do this you'd do it by writing a plugin. But now that I dug around a little while I couldn't find out how [plugins could register new types](https://github.com/elastic/elasticsearch/issues/11242). So you might be out of luck.

---

<div class="post-metadata">

**Author:** ![Grauen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grauen/32/88529_2.png) [@Grauen](https://discuss.elastic.co/u/Grauen)\
**Post date:** [October 24, 2015, 9:16am UTC](https://discuss.elastic.co/t/iso8601-durations/920/5 "2015-10-24T09:16:28Z")

</div>

I also have to store ISO8601 durations.  
Did you build your own plugin? Is this feature available in a current version of elasticsearch without any plugin?

EDIT: As a eorkaround I just convert the ISO8601 durations to seconds.  
When I read values from elasticsearch, I convert them back from seconds to ISO8601. But It would be great if elasticsearch would support ISO8601 anyway.

---

<div class="post-metadata">

**Author:** ![James\_Cook\_2](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@James\_Cook\_2](https://discuss.elastic.co/u/James_Cook_2)\
**Post date:** [October 24, 2015, 2:35pm UTC](https://discuss.elastic.co/t/iso8601-durations/920/6 "2015-10-24T14:35:50Z")

</div>

We didn't write a plugin, we convert before write. I understand that I t's difficult for Elasticsearch to introduce a way of supporting higher level types because of Lucene dependencies, but it would be nice to have a clean way of converting a higher level construct into a number, Boolean, date or string value.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:42pm UTC](https://discuss.elastic.co/t/iso8601-durations/920/7 "2017-07-05T23:42:47Z")

</div>


