How to index now as a field value


(Matthew Vines) #1

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'


(David Pilato) #2

You can use ingest script processor I think


(Matthew Vines) #3

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.


(Matthew Vines) #4

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.


(David Pilato) #5

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.


(Matthew Vines) #6

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


(David Pilato) #7

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.


(system) #8

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