# Add the current date in mapping elasticsearch

**URL:** https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983
**Category:** Elasticsearch
**Created:** [July 20, 2016, 1:25pm UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983 "2016-07-20T13:25:19Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![ericpietro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericpietro/32/9685_2.png) [@ericpietro](https://discuss.elastic.co/u/ericpietro)
#### Post date: [July 20, 2016, 1:25pm UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/1 "2016-07-20T13:25:19Z")

</div>

Hi,  
I want to add - as a new field - the current date (now) in my index thus, i'll keep the elasticsearch indexing time in my index.  
How can I do it in the mapping settings ?  
I saw that the '\_timestamp' is deprecated...

something like : 'indexing\_ts' = now() ...

ty for your answer

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [July 20, 2016, 2:02pm UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/2 "2016-07-20T14:02:52Z")

</div>

Hi @ericpietro,

you cannot define this in the mapping directly. Rather you should define `indexing_ts` as a normal `date` field in the mapping and set `indexing_ts` explicitly to the current timestamp in your client application for each document.

Daniel

---

<div class="post-metadata">

### Author: ![ericpietro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericpietro/32/9685_2.png) [@ericpietro](https://discuss.elastic.co/u/ericpietro)
#### Post date: [July 20, 2016, 2:35pm UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/3 "2016-07-20T14:35:44Z")

</div>

ty danielmitterdorfer 🙂  
but can you give me the syntax ?  
I have to declare in the mapping a new field (that doesn't exist in my JSON message 'incoming'), like this ?  
"properties": {  
"my field x": {...},  
"my field y" :{...},  
...  
"indexing\_ts": { "type": "date", "format": "strict\_date\_optional\_time||epoch\_millis"}  
}  
??  
Is it enough ? How can it get the current timestamp (now) ?

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [July 20, 2016, 2:50pm UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/4 "2016-07-20T14:50:41Z")

</div>

Hi @ericpietro,

Here is a complete example. I cannot tell you which date format you have to use. That depends on your application and your requirements. I have chosen epoch\_millis for my example.

```auto
PUT /logs
{
   "mappings": {
      "incoming": {
         "properties": {
            "timestamp": {
               "type": "date",
               "format": "epoch_millis"
            },
            "message": {
               "type": "string",
               "index": "not_analyzed"
            }
         }
      }
   }
}

```

You can now add a log record like this:

```auto
POST /logs/incoming/1
{
  "timestamp": 1469025859000,
  "message": "Hi there"
}

```

> How can it get the current timestamp (now) ?

As you can see in the example above your application / the client has to provide it. Elasticsearch does not set this value anymore.

Daniel

---

<div class="post-metadata">

### Author: ![ericpietro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericpietro/32/9685_2.png) [@ericpietro](https://discuss.elastic.co/u/ericpietro)
#### Post date: [July 29, 2016, 1:42pm UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/5 "2016-07-29T13:42:55Z")

</div>

ty again daniel... but it doen't help very much.  
by goal is to date the instant when elasticsearch index my doc (log line)...  
in my global solution, i have, for every event :  
harvest-ts (when i catch the log line)  
shipping-ts (when i transport it to kafka by logstash)  
consuming-ts (when i consume log line from kafka and parse it)  
indexing-ts (when i insert the log line in elasticsearch cluster. this is missing !!!)  
thus, i can calculate the lag between two steps or stages...  
so sorry that \_timestamp be deprecated ... 😒

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [August 1, 2016, 6:34am UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/6 "2016-08-01T06:34:25Z")

</div>

Hi @ericpietro,

so, which application puts your log lines into Elasticsearch? Do you use Logstash or is this a homegrown application? In the former case: Can't you use add a [mutate filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) to add `indexing_ts`? In the latter case: Can't the application add the field `indexing_ts`?

Daniel

---

<div class="post-metadata">

### Author: ![ericpietro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericpietro/32/9685_2.png) [@ericpietro](https://discuss.elastic.co/u/ericpietro)
#### Post date: [August 1, 2016, 7:05am UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/7 "2016-08-01T07:05:25Z")

</div>

hi daniel  
thanks very much to answer 🙂  
i use logstash and i already 'time' the treatment of my log line by a consuming-ts.  
that is ok.  
but i send each log line to elasticsearch using the output plugin and i would know the lag between I consume the log line by logtash and elasticsearch index the log line in the nosql database ... (\_timestamp used before)...  
have a nice day 🙂

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [August 1, 2016, 7:25am UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/8 "2016-08-01T07:25:02Z")

</div>

Hi Eric,

ah, now I got you. If you want this, then I guess you could use the [Ingest Node API](https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html). This runs within Elasticsearch so you get a chance to measure the time lag you're after.

Daniel

---

<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 5, 2017, 10:31pm UTC](https://discuss.elastic.co/t/add-the-current-date-in-mapping-elasticsearch/55983/9 "2017-07-05T22:31:20Z")

</div>


