I want to be able to do some scripting in a numeric range of dates within a
filtered query. So I though I would show you what I have done and ask you
for your advice as I'm left with the suspicion that I could have done
things differently or more elegantly!
I'm starting with something simple like this numeric_range filter
The main differences are that the value of a date is in milliseconds, and I
am passing in unix/epoch timestamps in seconds, hence the divide by 1000
Now, my actual use for this is for a script filter where "start_range" also
stored in the doc and represents the number of days:
"script": "(doc['start_date].value / 1000 )+ (doc['start_range'].value *
86400) <= param1 "
So, it works, and performs fine. My questions are: does this make sense?
Could I have done it easier or cleaner? Is my solution worse for
performance / caching than the numeric_range? Have I missed something
glaringly obvious? Perhaps mvel and elasticsearch expose some date values
that I could use?
On Wednesday, May 15, 2013 10:59:41 PM UTC+2, Tim Waters wrote:
Hi folks,
I want to be able to do some scripting in a numeric range of dates within
a filtered query. So I though I would show you what I have done and ask
you for your advice as I'm left with the suspicion that I could have done
things differently or more elegantly!
I'm starting with something simple like this numeric_range filter
The main differences are that the value of a date is in milliseconds, and
I am passing in unix/epoch timestamps in seconds, hence the divide by 1000
Now, my actual use for this is for a script filter where "start_range"
also stored in the doc and represents the number of days:
"script": "(doc['start_date].value / 1000 )+ (doc['start_range'].value *
86400) <= param1 "
So, it works, and performs fine. My questions are: does this make sense?
Could I have done it easier or cleaner? Is my solution worse for
performance / caching than the numeric_range? Have I missed something
glaringly obvious? Perhaps mvel and elasticsearch expose some date values
that I could use?
the numeric range is actually executed on the inverted index and has very
low memory requirements while is still fast. you can also index the
timestamp in seconds if you want as a long and use numeric ranges on that
so you get kind of 'best of both worlds'. The script is likely to be way
slower if you match lots of docs and it needs to represent all dates in
memory so that is 64bit per document heapspace.
On Wednesday, May 15, 2013 10:59:41 PM UTC+2, Tim Waters wrote:
Hi folks,
I want to be able to do some scripting in a numeric range of dates within
a filtered query. So I though I would show you what I have done and ask
you for your advice as I'm left with the suspicion that I could have
done things differently or more elegantly!
I'm starting with something simple like this numeric_range filter
The main differences are that the value of a date is in milliseconds, and
I am passing in unix/epoch timestamps in seconds, hence the divide by 1000
Now, my actual use for this is for a script filter where "start_range"
also stored in the doc and represents the number of days:
"script": "(doc['start_date].value / 1000 )+ (doc['start_range'].value *
86400) <= param1 "
So, it works, and performs fine. My questions are: does this make sense?
Could I have done it easier or cleaner? Is my solution worse for
performance / caching than the numeric_range? Have I missed something
glaringly obvious? Perhaps mvel and elasticsearch expose some date values
that I could use?
the numeric range is actually executed on the inverted index and has very
low memory requirements while is still fast. you can also index the
timestamp in seconds if you want as a long and use numeric ranges on that
so you get kind of 'best of both worlds'. The script is likely to be way
slower if you match lots of docs and it needs to represent all dates in
memory so that is 64bit per document heapspace.
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.