Relative date range skipping weekends (saturdays and sundays)

Hi,

Is it possible to write a query such as "created:[now-2d TO now]" where
now-2d will skip weekends. So if it is Monday then "now-2d" should also
yield results for Tuesday and Friday.

Is this possible in some way?

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

It definitely is not. If this is something you want to do, then you can add
a flag to your documents isCreatedOnWeekend: Boolean at index time, and
set it to true if the document was created on a weekend. Then at query time
you can and together your date range with a boolean filter on the
isCreatedOnWeekend.

Also, if you’re going to do range filters, it’s a good practice, if
possible, to do something like created: [DateMidnight() - Period.days(2) TO DateMidnight()]. This way the filter will be the same all day long, and
it can be effectively cached which can make queries a lot faster. The way
you have it written, each filter will cover a slightly different time span,
and you’ll never get a cache hit.

-Jon

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

An alternative approach would be to use a range filter (for your date
range) and use it together with a script filter inside a not filter.
The script filter would contain the following script:
"doc['created'].date.dayOfWeek == 6 || doc['created'].date.dayOfWeek == 7"

Because the script filter is put in a not filter it would exclude all docs
with create date in the weekend. I think it is beneficial the cache the not
filter. You can do this setting the _cache field to true on the not
filter.

On 19 February 2013 16:52, Jon Shea jonshea@foursquare.com wrote:

It definitely is not. If this is something you want to do, then you can
add a flag to your documents isCreatedOnWeekend: Boolean at index time,
and set it to true if the document was created on a weekend. Then at query
time you can and together your date range with a boolean filter on the
isCreatedOnWeekend.

Also, if you’re going to do range filters, it’s a good practice, if
possible, to do something like created: [DateMidnight() - Period.days(2) TO DateMidnight()]. This way the filter will be the same all day long, and
it can be effectively cached which can make queries a lot faster. The way
you have it written, each filter will cover a slightly different time span,
and you’ll never get a cache hit.

-Jon

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

--
Met vriendelijke groet,

Martijn van Groningen

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

1 Like

I guess we will have to do it in our application then. I was kinda hoping
there was some kind of neat option that I had missed.

Thanks for the recommendation on caching best practice though.

On Tue, Feb 19, 2013 at 5:42 PM, Martijn v Groningen <
martijn.v.groningen@gmail.com> wrote:

An alternative approach would be to use a range filter (for your date
range) and use it together with a script filter inside a not filter.
The script filter would contain the following script:
"doc['created'].date.dayOfWeek == 6 || doc['created'].date.dayOfWeek == 7"

Because the script filter is put in a not filter it would exclude all docs
with create date in the weekend. I think it is beneficial the cache the not
filter. You can do this setting the _cache field to true on the not
filter.

On 19 February 2013 16:52, Jon Shea jonshea@foursquare.com wrote:

It definitely is not. If this is something you want to do, then you can
add a flag to your documents isCreatedOnWeekend: Boolean at index time,
and set it to true if the document was created on a weekend. Then at query
time you can and together your date range with a boolean filter on the
isCreatedOnWeekend.

Also, if you’re going to do range filters, it’s a good practice, if
possible, to do something like created: [DateMidnight() - Period.days(2) TO DateMidnight()]. This way the filter will be the same all day long, and
it can be effectively cached which can make queries a lot faster. The way
you have it written, each filter will cover a slightly different time span,
and you’ll never get a cache hit.

-Jon

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

--
Met vriendelijke groet,

Martijn van Groningen

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

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