We are trying to visualize some data based on a timespan between two dates date1 and date2. I'm trying to create a scripted field to return the amount of days between the two dates. This works as expected however date2 can in certain cases be in the future in which case we need to use the span between date1 and current time.
Expression I would like to run:
doc['date2'].value < now) ? doc['date2'] - doc['date1'] : now - doc['date1']
I cannot find any way to access current time in a scripted field expression. Is this possible?
This isn't possible with Lucene, which is the default query language. Elasticsearch will be getting a query language in the future that should allow this, but that doesn't really help you right now...
Based on some other replies here, it sounds like you should be able to do this with groovy scripting, something you can do today, though it's a little trickier to use. See the scripting docs to learn more.
If you've enabled Groovy scripting, I believe they should work. Note that this won't work by default in scripted fields in Kibana, since those are currently limited to Lucene query expressions, which apparently don't have a way to query the current date. You have to go out of your way to enable and use Groovy scripts.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.