# Add \_timestamp on already inserted document

**URL:** <https://discuss.elastic.co/t/add--timestamp-on-already-inserted-document/10029>\
**Category:** Elasticsearch\
**Created:** [December 11, 2012, 9:11am UTC](https://discuss.elastic.co/t/add--timestamp-on-already-inserted-document/10029 "2012-12-11T09:11:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Gindre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexandre_gindre/32/2577_2.png) [@Alexandre\_Gindre](https://discuss.elastic.co/u/Alexandre_Gindre)\
**Post date:** [December 11, 2012, 9:11am UTC](https://discuss.elastic.co/t/add--timestamp-on-already-inserted-document/10029/1 "2012-12-11T09:11:44Z")

</div>

Hi all,

I try to add \_timestamp field into my documents.  
For example, let assume that I have document tweet :  
curl-XGET [http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)

{

"tweet" : {  
"properties" : {  
"author" : {  
"type" : "string",  
"store" : "yes"  
},  
"text" : {  
"type" : "string",  
"store": "yes"  
}  
}

}

curl -XPUT [http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2) -d '  
{  
"author" : "test",  
"text" : "Toto"  
}'

Now, I want to add \_timestamp to this document so I modify the mapping like  
this :  
curl -XPUT "$baseUrl/transactions/\_mapping?pretty=true" -d '  
{  
"transactions" : {  
"properties" : {  
"author" : {

```
          "type" : "string",
          "store" : "yes"
        },
       "text" : {
          "type" : "string"
       },
       "_timestamp" : {"enabled" : true}

   }
 }

```

}

The question is : Is there a way to add \_timestamp field on documents that  
are already inserted ? In this case, in my tweet.  
I saw the update in the API but I don't know which script should I use to  
do. Do you have example to do a such thing ?

Regards

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 13, 2012, 5:24pm UTC](https://discuss.elastic.co/t/add--timestamp-on-already-inserted-document/10029/2 "2012-12-13T17:24:58Z")

</div>

You cannot enable timestamp for the types that are already created. You  
will have to delete the type and reindex all records into it again.

By the way, when you will create the new type, move the \_mapping definition  
to the same level as properties (not inside properties) so it looks like  
this:

{  
"tweet" : {  
"properties" : {  
"author" : {  
"type" : "string",  
"store" : "yes"  
},  
"text" : {  
"type" : "string"  
}  
},  
"\_timestamp" : {"enabled" : true}  
}  
}

On Tuesday, December 11, 2012 4:11:44 AM UTC-5, Alexandre Gindre wrote:

> Hi all,
> 
> I try to add \_timestamp field into my documents.  
> For example, let assume that I have document tweet :  
> curl-XGET [http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)
> 
> {
> 
> "tweet" : {  
> "properties" : {  
> "author" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "text" : {  
> "type" : "string",  
> "store": "yes"  
> }  
> }
> 
> }
> 
> curl -XPUT [http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2) -d '  
> {  
> "author" : "test",  
> "text" : "Toto"  
> }'
> 
> Now, I want to add \_timestamp to this document so I modify the mapping  
> like this :  
> curl -XPUT "$baseUrl/transactions/\_mapping?pretty=true" -d '  
> {  
> "transactions" : {  
> "properties" : {  
> "author" : {
> 
> ```
> "type" : "string",
> "store" : "yes"
> },
> "text" : {
> "type" : "string"
> },
> "_timestamp" : {"enabled" : true}
> 
> }
> }
> 
> ```
> 
> }
> 
> The question is : Is there a way to add \_timestamp field on documents  
> that are already inserted ? In this case, in my tweet.  
> I saw the update in the API but I don't know which script should I use to  
> do. Do you have example to do a such thing ?
> 
> Regards

--

---

<div class="post-metadata">

**Author:** ![Alexandre\_Gindre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexandre_gindre/32/2577_2.png) [@Alexandre\_Gindre](https://discuss.elastic.co/u/Alexandre_Gindre)\
**Post date:** [December 13, 2012, 5:38pm UTC](https://discuss.elastic.co/t/add--timestamp-on-already-inserted-document/10029/3 "2012-12-13T17:38:21Z")

</div>

Thank you for the tip.

2012/12/13 Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com)

> You cannot enable timestamp for the types that are already created. You  
> will have to delete the type and reindex all records into it again.
> 
> By the way, when you will create the new type, move the \_mapping  
> definition to the same level as properties (not inside properties) so it  
> looks like this:
> 
> {  
> "tweet" : {  
> "properties" : {  
> "author" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "text" : {  
> "type" : "string"  
> }  
> },  
> "\_timestamp" : {"enabled" : true}  
> }  
> }
> 
> On Tuesday, December 11, 2012 4:11:44 AM UTC-5, Alexandre Gindre wrote:
> 
> > Hi all,
> > 
> > I try to add \_timestamp field into my documents.  
> > For example, let assume that I have document tweet :  
> > curl-XGET [http://localhost:9200/twitter/\*\*tweet/\_mapping](http://localhost:9200/twitter/**tweet/_mapping)
> > 
> > {
> > 
> > "tweet" : {
> > 
> > ```
> > "properties" : {
> > "author" : {
> > 
> > "type" : "string",
> > 
> > "store" : "yes"
> > },
> > 
> > "text" : {
> > "type" : "string",
> > 
> > "store": "yes"
> > }
> > 
> > ```
> > 
> > }
> > 
> > }
> > 
> > curl -XPUT [http://localhost:9200/twitter/\*\*tweet/2](http://localhost:9200/twitter/**tweet/2) -d '  
> > {  
> > "author" : "test",  
> > "text" : "Toto"  
> > }'
> > 
> > Now, I want to add _timestamp to this document so I modify the mapping  
> > like this :  
> > curl -XPUT "$baseUrl/transactions/_\*\*mapping?pretty=true" -d '  
> > {  
> > "transactions" : {  
> > "properties" : {  
> > "author" : {
> > 
> > ```
> > "type" : "string",
> > 
> > "store" : "yes"
> > 
> > },
> > "text" : {
> > 
> > "type" : "string"
> > 
> > },
> > "_timestamp" : {"enabled" : true}
> > 
> > }
> > }
> > 
> > ```
> > 
> > }
> > 
> > The question is : Is there a way to add \_timestamp field on documents  
> > that are already inserted ? In this case, in my tweet.  
> > I saw the update in the API but I don't know which script should I use to  
> > do. Do you have example to do a such thing ?
> > 
> > Regards
> > 
> > --

--  
Alexandre Gindre

--

---

<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, 2:59am UTC](https://discuss.elastic.co/t/add--timestamp-on-already-inserted-document/10029/4 "2017-07-06T02:59:57Z")

</div>

Closed on July 6, 2017, 2:59am UTC


