Range Facet with Dates

On a field query where my document contains a collection of samples, each
with a collection time, I only want to count the number of samples where
the collection time is between a pair of dates. The goal is to return an
accurate number of collected samples within a time range. Will using a
Range Facet do the trick?

The website states:
*
*

"The range facet support also providing the range as string formatted
dates."

Does this mean that the Java API supports something like this on field
searches:

DateTime fromTime = new DateTime( filterOptions.fromTime() );
DateTime toTime = new DateTime( filterOptions.toTime() );
RangeFacetBuilder sampleRange = FacetBuilders.rangeFacet( "sampleTimeRange"
)
.field( "samples.collected" )
.addRange(fromTime.toString(), toTime.toString() );

Or should I stick to using addRange(long,long) version of the API?

Much thanks for you insight.

Tim Sheridan

--
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.

As far as I remember it, you can write something like:
RangeFacetBuilder sampleRange = FacetBuilders.rangeFacet( "sampleTimeRange" )
.field( "samples.collected" )
.addRange("2013-01-01", "2014" );

That said, if you need only one range, you perhaps don't need facet at all but only use the _count API and apply a RangeFilter.

Does it help?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 22 avr. 2013 à 21:56, Tim Sheridan tim.sheridan@me.com a écrit :

On a field query where my document contains a collection of samples, each with a collection time, I only want to count the number of samples where the collection time is between a pair of dates. The goal is to return an accurate number of collected samples within a time range. Will using a Range Facet do the trick?

The website states:

"The range facet support also providing the range as string formatted dates."

Does this mean that the Java API supports something like this on field searches:

DateTime fromTime = new DateTime( filterOptions.fromTime() );
DateTime toTime = new DateTime( filterOptions.toTime() );
RangeFacetBuilder sampleRange = FacetBuilders.rangeFacet( "sampleTimeRange" )
.field( "samples.collected" )
.addRange(fromTime.toString(), toTime.toString() );

Or should I stick to using addRange(long,long) version of the API?

Much thanks for you insight.

Tim Sheridan

--
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,
"addRange(fromTime.toString(), toTime.toString() )" is ok, but the pattern of Date and Time need to be "yyyy-MM-dd'T'HH:mm:ss" or "yyyy-MM-dd"