# Insert {now-1m/d} failure

**URL:** https://discuss.elastic.co/t/insert-now-1m-d-failure/204160
**Category:** Elasticsearch
**Created:** [October 18, 2019, 3:48am UTC](https://discuss.elastic.co/t/insert-now-1m-d-failure/204160 "2019-10-18T03:48:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ajhstn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ajhstn/32/24629_2.png) [@ajhstn](https://discuss.elastic.co/u/ajhstn)
#### Post date: [October 18, 2019, 3:48am UTC](https://discuss.elastic.co/t/insert-now-1m-d-failure/204160/1 "2019-10-18T03:48:57Z")

</div>

Hello is it possible to insert a document using the current time, like this?

```
PUT /tmp
{
  "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date" 
      }
    }
  }
}

POST tmp/_doc/1
{
  "@timestamp":"{now-1m/d}"
}

```

So far i am unsuccessful, but unsure it this is not possible, or i am doing something wrong.

```
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [@timestamp] of type [date] in document with id '1'. Preview of field's value: '{now-1m/d}'"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse field [@timestamp] of type [date] in document with id '1'. Preview of field's value: '{now-1m/d}'",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "failed to parse date field [{now-1m/d}] with format [strict_date_optional_time||epoch_millis]",
      "caused_by": {
        "type": "date_time_parse_exception",
        "reason": "Failed to parse with all enclosed parsers"
      }
    }
  },
  "status": 400

```

It is hard to tell if what i am trying IS possible, but i need to set the date format, or what i am trying is NOT possible.

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [October 22, 2019, 6:42am UTC](https://discuss.elastic.co/t/insert-now-1m-d-failure/204160/2 "2019-10-22T06:42:59Z")

</div>

Unfortunately, you cannot use the `now` syntax at index time. It is a query-time construct.

What you could do instead is define an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html) that automatically adds a timestamp to your documents. [This post](https://discuss.elastic.co/t/dec-12th-2018-en-elasticsearch-automatically-adding-a-timestamp-to-documents/159314) explains how to do that. Instead of the `set` processor used in that post, you'd use a [`script` processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/script-processor.html) to format the date exactly how you want it.

---

<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: [November 19, 2019, 6:43am UTC](https://discuss.elastic.co/t/insert-now-1m-d-failure/204160/3 "2019-11-19T06:43:16Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
