Filtering a date field by month

Hi everyone,

I'm not find a way to retrieve all documents that have a release date
(a field indexed like a date) where its month is one specific.

I'm only find range queries or gt, lt, filters

Thanks in advance

On Feb 23, 6:56 am, Paco Guzmán pacoguzm...@gmail.com wrote:

I'm not find a way to retrieve all documents that have a release date
(a field indexed like a date) where its month is one specific.

I'm only find range queries or gt, lt, filters

Being able to query directly using year/month/week/day/hour/minute
intervals would indeed be useful. But you can build a range query like
so (using the Joda-Time API):

buildQuery("timestamp", YearMonth.parse("2012-02"),
DateTimeZone.UTC);

public QueryBuilder buildQuery(String field, YearMonth month,
DateTimeZone tz) {
Interval interval = forMonth(month, tz);
return QueryBuilders.rangeQuery(field)
.gte(interval.getStart().toString()) // assuming
ISODateTimeFormat
.lt(interval.getEnd().toString());
}

private Interval forMonth(YearMonth month, DateTimeZone tz) {
return new Interval(toDateTime(month, tz),
toDateTime(month.plusMonths(1), tz));
}

private DateTime toDateTime(YearMonth month, DateTimeZone tz) {
return new DateTime(month.getYear(), month.getMonthOfYear(), 1, 0,
0, tz);
}

Do you mean give me all documents where the month is "June", regardless of the year?

On Thursday, February 23, 2012 at 4:56 PM, Paco Guzmán wrote:

Hi everyone,

I'm not find a way to retrieve all documents that have a release date
(a field indexed like a date) where its month is one specific.

I'm only find range queries or gt, lt, filters

Thanks in advance

Yes, we would like to filter all rows where month is June . We have a single column with date field type having 10 years of data

Was this ever resolved? I am having this exact issue.

1 Like

Do we solution for this.