Hi,
I haven't been able to find any examples about how to access to a date
field inside a java native script.
I have a 'datePublished' field defined as following in the mapping:
mappings: {
doc: {
properties: {
...
datePublished: {
format: dateOptionalTime
type: date
}
}
}
}
However, inside the class:
public class ScoreByAgeScript extends AbstractDoubleSearchScript {
public ScoreByAgeScript(@Nullable Map<String,Object> params) {
...
}
@Override
public double runAsDouble() {
Object datePublishedStr = source().get(fieldDate); // => Get a
string 2013-07-07T12:00:00
Object datePublishedDoc = doc().get(fieldDate); // => Get a
list of strings [00, 03, 07t12, 2013]
}
}
I have been able only to the string text.
I could eventually parse the text to a Date Java object but I would prefer
to avoid it, avoiding any problem about string format or timezone, etc..
Is there any way to get the java date Object?
Thanks
Niccolo
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.