# Updating DATE type filed

**URL:** https://discuss.elastic.co/t/updating-date-type-filed/23252
**Category:** Elasticsearch
**Created:** [April 15, 2015, 1:43pm UTC](https://discuss.elastic.co/t/updating-date-type-filed/23252 "2015-04-15T13:43:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Amir\_Mofakhar](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Amir\_Mofakhar](https://discuss.elastic.co/u/Amir_Mofakhar)
#### Post date: [April 15, 2015, 1:43pm UTC](https://discuss.elastic.co/t/updating-date-type-filed/23252/1 "2015-04-15T13:43:26Z")

</div>

I have below index :

curl -XPUT localhost:9200/test/type1/1 -d '{  
"timestamp":"2015-04-15T12:00:00"  
}'

I can update it and change all timestamp to another date by below command :

curl-XPOST localhost:9200/test/type1/1/\_updat -d '{  
"script" :"ctx.\_source.timestamp = newts",  
"params":{  
"newts":"2015-03-15T08:15:00"  
}  
}'

But I need a way to update only some part of my time stamp for example I  
want to :

new timestamp = old timestamp + 3 days

or

new timestamp = old timestamp + 1 year

any suggestion?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/aad82cd9-b57b-4bea-9ce0-d60b979defdb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/aad82cd9-b57b-4bea-9ce0-d60b979defdb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Amir\_Mofakhar](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Amir\_Mofakhar](https://discuss.elastic.co/u/Amir_Mofakhar)
#### Post date: [April 15, 2015, 2:35pm UTC](https://discuss.elastic.co/t/updating-date-type-filed/23252/2 "2015-04-15T14:35:04Z")

</div>

I found this solution :

curl -XPOST localhost:9200/test/type1/1/\_update -d '  
{  
,  
"script" : "ctx.\_source.timestamp =  
((ctx.\_source.timestamp).split(/-/)[0].toInteger()-1)+"-"+(ctx.\_source.timestamp).split(/-/)[1]  
+"-"+ctx.\_source.timestamp.split(/-/)[2] ",  
}'

On Wednesday, April 15, 2015 at 3:43:27 PM UTC+2, Amir Mofakhar wrote:

> I have below index :
> 
> curl -XPUT localhost:9200/test/type1/1 -d '{  
> "timestamp":"2015-04-15T12:00:00"  
> }'
> 
> I can update it and change all timestamp to another date by below command :
> 
> curl-XPOST localhost:9200/test/type1/1/\_updat -d '{  
> "script" :"ctx.\_source.timestamp = newts",  
> "params":{  
> "newts":"2015-03-15T08:15:00"  
> }  
> }'
> 
> But I need a way to update only some part of my time stamp for example I  
> want to :
> 
> new timestamp = old timestamp + 3 days
> 
> or
> 
> new timestamp = old timestamp + 1 year
> 
> any suggestion?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/94d90df0-4a49-49c7-9867-f572fb50bf86%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/94d90df0-4a49-49c7-9867-f572fb50bf86%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:19am UTC](https://discuss.elastic.co/t/updating-date-type-filed/23252/3 "2017-07-06T00:19:36Z")

</div>


