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