# How to index now as a field value

**URL:** <https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447>\
**Category:** Elasticsearch\
**Created:** [May 11, 2017, 4:23pm UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447 "2017-05-11T16:23:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Vines](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_vines/32/17912_2.png) [@Matthew\_Vines](https://discuss.elastic.co/u/Matthew_Vines)\
**Post date:** [May 11, 2017, 4:23pm UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/1 "2017-05-11T16:23:04Z")

</div>

I'm trying to set 'now' as the timestamp in an index query, but can't seem to find the right syntax.

```
POST /patient-admit/patientAdmit
{
    "systemId": 123,
	"mrn": "xxxx",
	"firstName": "xxx",
	"lastName": "xxx",
	"middleName": "xxx",
	"birthDate": "1988-03-10T00:00:00",
	"gender": "X",
	"race": "X",
	"timestamp": {
		"script": {
			"lang": "painless",
			"inline": "getDate();"
		}
    }
}

```

getDate() is in the painless api, but this obviously isn't how it's done, and I can't seem to find any further guidance in the docs.

I don't want to set up any catch all solutions here, just trying to figure out how I might index a calculated value, in this case 'now'

---

<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:** [May 11, 2017, 4:45pm UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/2 "2017-05-11T16:45:17Z")

</div>

You can use ingest script processor I think

---

<div class="post-metadata">

**Author:** ![Matthew\_Vines](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_vines/32/17912_2.png) [@Matthew\_Vines](https://discuss.elastic.co/u/Matthew_Vines)\
**Post date:** [May 11, 2017, 5:48pm UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/3 "2017-05-11T17:48:31Z")

</div>

Sure, but if I am understanding correctly, this is less than ideal. I don't really want my index to know anything about how how timestamp is set. sometimes I may pass a hard value for timestamp (ie in test scaffolds), and sometimes I may want to use now. I don't want to have to activate/deactivate a pipeline if there is a way around it.

---

<div class="post-metadata">

**Author:** ![Matthew\_Vines](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_vines/32/17912_2.png) [@Matthew\_Vines](https://discuss.elastic.co/u/Matthew_Vines)\
**Post date:** [May 11, 2017, 5:51pm UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/4 "2017-05-11T17:51:15Z")

</div>

I am currently doing this from a utility script I wrote in .net using nest, so I can grab DateTime.Now from there and pass the resulting value in when I index, but I was hoping there was an easy way to do the same inside the json document itself.

---

<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:** [May 11, 2017, 9:24pm UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/5 "2017-05-11T21:24:39Z")

</div>

Elasticsearch will index the Json content as is. No processing logic.

Unless you use a pipeline where you can transform on the fly a doc before it gets indexed.

---

<div class="post-metadata">

**Author:** ![Matthew\_Vines](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_vines/32/17912_2.png) [@Matthew\_Vines](https://discuss.elastic.co/u/Matthew_Vines)\
**Post date:** [May 11, 2017, 9:25pm UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/6 "2017-05-11T21:25:54Z")

</div>

Thanks, that's good to know. But some basic expression syntax would be really handy.

---

<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:** [May 12, 2017, 8:53am UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/7 "2017-05-12T08:53:06Z")

</div>

> But some basic expression syntax would be really handy.

That'd be IMHO over engineering as there is a really simple option which is built for that.

---

<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:** [June 9, 2017, 9:06am UTC](https://discuss.elastic.co/t/how-to-index-now-as-a-field-value/85447/8 "2017-06-09T09:06:46Z")

</div>

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