# How to store current date

**URL:** <https://discuss.elastic.co/t/how-to-store-current-date/22323>\
**Category:** Elasticsearch\
**Created:** [February 23, 2015, 8:23am UTC](https://discuss.elastic.co/t/how-to-store-current-date/22323 "2015-02-23T08:23:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tao\_hiko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tao_hiko/32/707_2.png) [@tao\_hiko](https://discuss.elastic.co/u/tao_hiko)\
**Post date:** [February 23, 2015, 8:23am UTC](https://discuss.elastic.co/t/how-to-store-current-date/22323/1 "2015-02-23T08:23:07Z")

</div>

If I have mapping as below  
{  
"name" : { "type" : "string"},  
"location" : { "type" : "string" },  
"created\_date" : { "type" : "date"}  
}

Is it possible to put current date to "created\_date" field automatically?  
If yes, How to do?

Thanks  
Hiko

--  
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/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 23, 2015, 9:07am UTC](https://discuss.elastic.co/t/how-to-store-current-date/22323/2 "2015-02-23T09:07:39Z")

</div>

You can use the \_timestamp field to generate a date.  
If you really need to copy the value in another field, you could use copy\_to.

None will update \_source though.

## HTH

David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 23 févr. 2015 à 09:23, tao hiko [taohiko@gmail.com](mailto:taohiko@gmail.com) a écrit :
> 
> If I have mapping as below  
> {  
> "name" : { "type" : "string"},  
> "location" : { "type" : "string" },  
> "created\_date" : { "type" : "date"}  
> }
> 
> Is it possible to put current date to "created\_date" field automatically? If yes, How to do?
> 
> ## Thanks Hiko
> 
> 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/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/E3532D4C-9E7C-4AF9-ACD7-40B25B7B653C%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/E3532D4C-9E7C-4AF9-ACD7-40B25B7B653C%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![tao\_hiko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tao_hiko/32/707_2.png) [@tao\_hiko](https://discuss.elastic.co/u/tao_hiko)\
**Post date:** [February 23, 2015, 9:41am UTC](https://discuss.elastic.co/t/how-to-store-current-date/22323/3 "2015-02-23T09:41:52Z")

</div>

Hi David

Could you please provide some example for this case?

Thank you  
Hiko

On Monday, February 23, 2015 at 4:07:52 PM UTC+7, David Pilato wrote:

> You can use the \_timestamp field to generate a date.  
> If you really need to copy the value in another field, you could use  
> copy\_to.
> 
> None will update \_source though.
> 
> ## HTH
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 23 févr. 2015 à 09:23, tao hiko \<[tao...@gmail.com](mailto:tao...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> If I have mapping as below  
> {  
> "name" : { "type" : "string"},  
> "location" : { "type" : "string" },  
> "created\_date" : { "type" : "date"}  
> }
> 
> Is it possible to put current date to "created\_date" field automatically?  
> If yes, How to do?
> 
> Thanks  
> Hiko
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/89567448-94b6-4edf-8a7f-f7f361c57747%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/89567448-94b6-4edf-8a7f-f7f361c57747%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 23, 2015, 4:22pm UTC](https://discuss.elastic.co/t/how-to-store-current-date/22323/4 "2015-02-23T16:22:42Z")

</div>

Timestamp doc  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html#mapping-timestamp-field) [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html#mapping-timestamp-field](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html#mapping-timestamp-field)

Copy To doc:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to) [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to)

HTH.

If you don’t succeed, please GIST a full example of what you did so far so we can reproduce and help.  
See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/) [http://www.elasticsearch.org/help/](http://www.elasticsearch.org/help/)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 23 févr. 2015 à 10:41, tao hiko [taohiko@gmail.com](mailto:taohiko@gmail.com) a écrit :
> 
> Hi David
> 
> Could you please provide some example for this case?
> 
> Thank you  
> Hiko
> 
> On Monday, February 23, 2015 at 4:07:52 PM UTC+7, David Pilato wrote:  
> You can use the \_timestamp field to generate a date.  
> If you really need to copy the value in another field, you could use copy\_to.
> 
> None will update \_source though.
> 
> ## HTH
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 23 févr. 2015 à 09:23, tao hiko \<[tao...@gmail.com](mailto:tao...@gmail.com) \<javascript:\>\> a écrit :
> 
> > If I have mapping as below  
> > {  
> > "name" : { "type" : "string"},  
> > "location" : { "type" : "string" },  
> > "created\_date" : { "type" : "date"}  
> > }
> > 
> > Is it possible to put current date to "created\_date" field automatically? If yes, How to do?
> > 
> > Thanks  
> > Hiko
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6a649dd3-ed25-4065-b142-e9bbc382de56%40googlegroups.com?utm_medium=email&utm_source=footer).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/89567448-94b6-4edf-8a7f-f7f361c57747%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/89567448-94b6-4edf-8a7f-f7f361c57747%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/89567448-94b6-4edf-8a7f-f7f361c57747%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/89567448-94b6-4edf-8a7f-f7f361c57747%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/60CF60D5-3E3F-4738-B8D7-088AB79B0A6E%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/60CF60D5-3E3F-4738-B8D7-088AB79B0A6E%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![tao\_hiko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tao_hiko/32/707_2.png) [@tao\_hiko](https://discuss.elastic.co/u/tao_hiko)\
**Post date:** [February 24, 2015, 4:18am UTC](https://discuss.elastic.co/t/how-to-store-current-date/22323/5 "2015-02-24T04:18:40Z")

</div>

I have tried like below this

POST index\_test  
{  
"mapping" : {  
"type\_test" : {  
"\_timestamp" : {  
"enabled" : true,  
"copy\_to" : "created\_date"  
},  
"properties" : {  
"name" : { "type" : "string"},  
"location" : { "type" : "string"},  
"created\_date" : { "type" : "date" }  
}  
}  
}  
}

POST index\_test/type\_test/123  
{  
"name" : "Full Test",  
"location" : "local"  
}

But the result that doesn't have "created\_date" field. What did I do wrong  
or missing?

GET index\_test/\_search

The result

{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "index\_test",  
"\_type": "type\_test",  
"\_id": "123",  
"\_score": 1,  
"\_source": {  
"name": "Full Test",  
"location": "local"  
}  
}  
]  
}  
}

On Monday, February 23, 2015 at 11:22:56 PM UTC+7, David Pilato wrote:

> Timestamp doc
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html#mapping-timestamp-field)
> 
> Copy To doc:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to)
> 
> HTH.
> 
> If you don’t succeed, please GIST a full example of what you did so far so  
> we can reproduce and help.  
> See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> [http://Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

--  
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/8d006d81-28a8-48ab-a571-688e8fabb5e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8d006d81-28a8-48ab-a571-688e8fabb5e5%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:30am UTC](https://discuss.elastic.co/t/how-to-store-current-date/22323/6 "2017-07-06T00:30:35Z")

</div>


