How to index now as a field value

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'

You can use ingest script processor I think

1 Like

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.

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.

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.

1 Like

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

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.

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