# Add field with timestamp in documents

**URL:** <https://discuss.elastic.co/t/add-field-with-timestamp-in-documents/25814>\
**Category:** Elasticsearch\
**Created:** [July 17, 2015, 3:38pm UTC](https://discuss.elastic.co/t/add-field-with-timestamp-in-documents/25814 "2015-07-17T15:38:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smasell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smasell/32/43483_2.png) [@Smasell](https://discuss.elastic.co/u/Smasell)\
**Post date:** [July 17, 2015, 3:38pm UTC](https://discuss.elastic.co/t/add-field-with-timestamp-in-documents/25814/1 "2015-07-17T15:38:03Z")

</div>

Hi!!!  
I've created index:  
PUT '[http://localhost:9200/twitter/](http://localhost:9200/twitter/)  
and i want that my index add automaticly @timestamp field to all my documents when indexing.  
What should I do? THX for helping me.

---

<div class="post-metadata">

**Author:** ![Pradeep\_Gowda](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@Pradeep\_Gowda](https://discuss.elastic.co/u/Pradeep_Gowda)\
**Post date:** [July 17, 2015, 8:43pm UTC](https://discuss.elastic.co/t/add-field-with-timestamp-in-documents/25814/2 "2015-07-17T20:43:17Z")

</div>

Did you check below link?

[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html)

Add timestamp field in mapping.

---

<div class="post-metadata">

**Author:** ![Smasell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smasell/32/43483_2.png) [@Smasell](https://discuss.elastic.co/u/Smasell)\
**Post date:** [July 19, 2015, 7:26pm UTC](https://discuss.elastic.co/t/add-field-with-timestamp-in-documents/25814/3 "2015-07-19T19:26:46Z")

</div>

@Pradeep_Gowda  
Yeah I checked it but still not see it in the \_source like a field.

---

<div class="post-metadata">

**Author:** ![Pradeep\_Gowda](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@Pradeep\_Gowda](https://discuss.elastic.co/u/Pradeep_Gowda)\
**Post date:** [July 20, 2015, 6:56pm UTC](https://discuss.elastic.co/t/add-field-with-timestamp-in-documents/25814/4 "2015-07-20T18:56:57Z")

</div>

Can you try below?

Mapping

```
 PUT tweets
    {
      
      "settings": {
        "number_of_shards": 1
      },
      "mappings": {
        "_default_": {
          "_timestamp": {
            "enabled": true,
            "store": true,
            "_field_names": "_timestamp"
          }
        }
      }
    }

```

Insert

```
curl -XPUT 'http://localhost:9200/tweets/tweet/1' -d '{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:11",
    "message" : "trying out Elasticsearch"
}'

```

Query

```
GET tweets/_search 
{
"fields": ["_timestamp", "_source"],
  "query": {
    "match_all": {}
  }
}

```

Result

```
{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "tweets",
            "_type": "tweet",
            "_id": "2",
            "_score": 1,
            "_source": {
               "user": "kimchy1",
               "post_date": "2009-11-15T14:12:11",
               "message": "trying out Elasticsearch"
            },
            "fields": {
               "_timestamp": 1437418271898
            }
         }
      ]
   }
}

```

\_timestamp field will be added automatically and you can access it by \_timestamp

---

<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:00am UTC](https://discuss.elastic.co/t/add-field-with-timestamp-in-documents/25814/5 "2017-07-06T00:00:18Z")

</div>


