scriptField in TermsFacet to format a date value

Hi,

I'm trying to get results out of a TermsFacet with the use of scriptField.
What I'm trying to do is to format the date value and truncate the
milliseconds and then get the output from the facet. Can this be done via
an mvel script?

E.g.

I have two docs with the following values

doc1 time: 2013-09-01 22:10:15.123
doc2 time: 2013-09-01 22:10:15.456

and i want to have as an output

term: 2013-09-01 22:10:15.000
count: 2

is it possible to have something like term.setScriptField (
DateFormat.format( doc['time'].value, 'yyyy-MM-dd HH:mm:ss')) )??

Thank you

Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Thomas,
probably not the fastest thing to do using scripting, but here is a little
script that does what you need:

{
"facets": {
"test": {
"terms": {
"size": 10,
"script_field": "new java.text.SimpleDateFormat('yyyy-MM-dd
HH:mm:ss').format(new Date(_doc.time.value))"
}
}
}
}

At the end of the day I just used some Java code within the mvel script :wink:

Cheers
Luca

On Monday, September 2, 2013 3:54:28 PM UTC+2, Thomas wrote:

Hi,

I'm trying to get results out of a TermsFacet with the use of scriptField.
What I'm trying to do is to format the date value and truncate the
milliseconds and then get the output from the facet. Can this be done via
an mvel script?

E.g.

I have two docs with the following values

doc1 time: 2013-09-01 22:10:15.123
doc2 time: 2013-09-01 22:10:15.456

and i want to have as an output

term: 2013-09-01 22:10:15.000
count: 2

is it possible to have something like term.setScriptField (
DateFormat.format( doc['time'].value, 'yyyy-MM-dd HH:mm:ss')) )??

Thank you

Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hey thanks for your reply,

I also used this which might be slight better:

new
org.joda.time.DateTime(doc['time'].value).withMillisOfSecond(0).getMillis()

but is there any way with native mvel which will probably be the fastest
way?

Thanks again :slight_smile:

On Monday, September 2, 2013 4:54:28 PM UTC+3, Thomas wrote:

Hi,

I'm trying to get results out of a TermsFacet with the use of scriptField.
What I'm trying to do is to format the date value and truncate the
milliseconds and then get the output from the facet. Can this be done via
an mvel script?

E.g.

I have two docs with the following values

doc1 time: 2013-09-01 22:10:15.123
doc2 time: 2013-09-01 22:10:15.456

and i want to have as an output

term: 2013-09-01 22:10:15.000
count: 2

is it possible to have something like term.setScriptField (
DateFormat.format( doc['time'].value, 'yyyy-MM-dd HH:mm:ss')) )??

Thank you

Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.