# Calculate date using another field?

**URL:** https://discuss.elastic.co/t/calculate-date-using-another-field/89093
**Category:** Elasticsearch
**Created:** [June 12, 2017, 6:59pm UTC](https://discuss.elastic.co/t/calculate-date-using-another-field/89093 "2017-06-12T18:59:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![adyjayex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adyjayex/32/15748_2.png) [@adyjayex](https://discuss.elastic.co/u/adyjayex)
#### Post date: [June 12, 2017, 6:59pm UTC](https://discuss.elastic.co/t/calculate-date-using-another-field/89093/1 "2017-06-12T18:59:46Z")

</div>

Hello,

I have a few documents which contain relative dates such as:

> 2 Weeks Ago  
> 3 Months Ago

I've been looking into formatting the date field as well as date math but was unable to find something which would specifically address this case.

Would it be possible to set ES to interpret the text and if, for example, **x Months Ago** is detected, extract the **X** , and use date math along another date field inside my document to subtract from it the number of months and create a new date to be stored ?

Any help si greatly appreciated. Thanks!

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [June 12, 2017, 7:32pm UTC](https://discuss.elastic.co/t/calculate-date-using-another-field/89093/2 "2017-06-12T19:32:59Z")

</div>

You should do this interpretation on the client side before sending the document to elasticsearch.

---

<div class="post-metadata">

### Author: ![adyjayex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adyjayex/32/15748_2.png) [@adyjayex](https://discuss.elastic.co/u/adyjayex)
#### Post date: [June 12, 2017, 9:16pm UTC](https://discuss.elastic.co/t/calculate-date-using-another-field/89093/3 "2017-06-12T21:16:37Z")

</div>

You're right, however, we already have a lot of documents indexed, so I was looking into ways to do this through reindexing.

Thanks though! I'll look into going through all the documents and processing them outside of ES!

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [June 12, 2017, 9:54pm UTC](https://discuss.elastic.co/t/calculate-date-using-another-field/89093/4 "2017-06-12T21:54:04Z")

</div>

For reindexing, you could do it through ingest, I think.

---

<div class="post-metadata">

### Author: ![adyjayex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adyjayex/32/15748_2.png) [@adyjayex](https://discuss.elastic.co/u/adyjayex)
#### Post date: [June 12, 2017, 10:09pm UTC](https://discuss.elastic.co/t/calculate-date-using-another-field/89093/5 "2017-06-12T22:09:42Z")

</div>

I'll look into it, thanks!

---

<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 10, 2017, 10:09pm UTC](https://discuss.elastic.co/t/calculate-date-using-another-field/89093/6 "2017-07-10T22:09:49Z")

</div>

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