# Date range with multiple values?

**URL:** <https://discuss.elastic.co/t/date-range-with-multiple-values/5847>\
**Category:** Elasticsearch\
**Created:** [November 11, 2011, 5:46pm UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847 "2011-11-11T17:46:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [November 11, 2011, 5:46pm UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847/1 "2011-11-11T17:46:11Z")

</div>

I'd like to offer a date range feature where I have an index of forum  
threads with one or more reply posts. Each post has dateCreated field  
that I'd like to use in the date range.

Thread A  
|- reply post 1  
|- reply post 2  
...

What's the best way to accomplish doing a date range with multiple  
dates defined for each index document? I'm using the Java API.

Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 13, 2011, 8:15am UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847/2 "2011-11-13T08:15:28Z")

</div>

The document that you index includes a thread, and then several posts? In  
this case, you can simply do the range check on the _single_ dataCreated  
field. Multiple values in a document for a field can become tricky when  
wanting to execute a complex query, against several multiple fields, but  
have those constraints only match per "array element" (in which case,  
nested docs can help).

On Fri, Nov 11, 2011 at 7:46 PM, Shane Witbeck [shane@digitalsanctum.com](mailto:shane@digitalsanctum.com)wrote:

> I'd like to offer a date range feature where I have an index of forum  
> threads with one or more reply posts. Each post has dateCreated field  
> that I'd like to use in the date range.
> 
> Thread A  
> |- reply post 1  
> |- reply post 2  
> ...
> 
> What's the best way to accomplish doing a date range with multiple  
> dates defined for each index document? I'm using the Java API.
> 
> Thanks.

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [November 14, 2011, 7:16pm UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847/3 "2011-11-14T19:16:02Z")

</div>

Correct. Each indexed document is a Thread with denormalized fields  
about the thread and reply posts. As a solution I was able to add a  
field "postDates" which is a collection of java.util.Date objects and  
perform a range query on that field.

On Nov 13, 3:15 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> The document that you index includes a thread, and then several posts? In  
> this case, you can simply do the range check on the _single_ dataCreated  
> field. Multiple values in a document for a field can become tricky when  
> wanting to execute a complex query, against several multiple fields, but  
> have those constraints only match per "array element" (in which case,  
> nested docs can help).
> 
> On Fri, Nov 11, 2011 at 7:46 PM, Shane Witbeck [sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)wrote:
> 
> > I'd like to offer a date range feature where I have an index of forum  
> > threads with one or more reply posts. Each post has dateCreated field  
> > that I'd like to use in the date range.
> 
> > Thread A  
> > |- reply post 1  
> > |- reply post 2  
> > ...
> 
> > What's the best way to accomplish doing a date range with multiple  
> > dates defined for each index document? I'm using the Java API.
> 
> > Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 15, 2011, 1:49pm UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847/4 "2011-11-15T13:49:38Z")

</div>

I don't understand your solution..., a single field with multiple values or  
a field repeating itself several times is the same when it comes to  
elasticsearch...

On Mon, Nov 14, 2011 at 9:16 PM, Shane Witbeck [shane@digitalsanctum.com](mailto:shane@digitalsanctum.com)wrote:

> Correct. Each indexed document is a Thread with denormalized fields  
> about the thread and reply posts. As a solution I was able to add a  
> field "postDates" which is a collection of java.util.Date objects and  
> perform a range query on that field.
> 
> On Nov 13, 3:15 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > The document that you index includes a thread, and then several posts? In  
> > this case, you can simply do the range check on the _single_ dataCreated  
> > field. Multiple values in a document for a field can become tricky when  
> > wanting to execute a complex query, against several multiple fields, but  
> > have those constraints only match per "array element" (in which case,  
> > nested docs can help).
> > 
> > On Fri, Nov 11, 2011 at 7:46 PM, Shane Witbeck \<[sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)  
> > wrote:
> > 
> > > I'd like to offer a date range feature where I have an index of forum  
> > > threads with one or more reply posts. Each post has dateCreated field  
> > > that I'd like to use in the date range.
> > 
> > > Thread A  
> > > |- reply post 1  
> > > |- reply post 2  
> > > ...
> > 
> > > What's the best way to accomplish doing a date range with multiple  
> > > dates defined for each index document? I'm using the Java API.
> > 
> > > Thanks.

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [November 15, 2011, 3:07pm UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847/5 "2011-11-15T15:07:15Z")

</div>

This is obvious to me now but it didn't occur to me before that  
multiple values for a single field would work with a range query. Like  
I said this works fine for me. Thanks for the help.

On Nov 15, 8:49 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> I don't understand your solution..., a single field with multiple values or  
> a field repeating itself several times is the same when it comes to  
> elasticsearch...
> 
> On Mon, Nov 14, 2011 at 9:16 PM, Shane Witbeck [sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)wrote:
> 
> > Correct. Each indexed document is a Thread with denormalized fields  
> > about the thread and reply posts. As a solution I was able to add a  
> > field "postDates" which is a collection of java.util.Date objects and  
> > perform a range query on that field.
> 
> > On Nov 13, 3:15 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > The document that you index includes a thread, and then several posts? In  
> > > this case, you can simply do the range check on the _single_ dataCreated  
> > > field. Multiple values in a document for a field can become tricky when  
> > > wanting to execute a complex query, against several multiple fields, but  
> > > have those constraints only match per "array element" (in which case,  
> > > nested docs can help).
> 
> > > On Fri, Nov 11, 2011 at 7:46 PM, Shane Witbeck \<[sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)  
> > > wrote:
> 
> > > > I'd like to offer a date range feature where I have an index of forum  
> > > > threads with one or more reply posts. Each post has dateCreated field  
> > > > that I'd like to use in the date range.
> 
> > > > Thread A  
> > > > |- reply post 1  
> > > > |- reply post 2  
> > > > ...
> 
> > > > What's the best way to accomplish doing a date range with multiple  
> > > > dates defined for each index document? I'm using the Java API.
> 
> > > > Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 15, 2011, 7:09pm UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847/6 "2011-11-15T19:09:04Z")

</div>

Cool!, just wanted to verify that you did not change your json just to try  
and solve it where it did not matter.

On Tue, Nov 15, 2011 at 5:07 PM, Shane Witbeck [shane@digitalsanctum.com](mailto:shane@digitalsanctum.com)wrote:

> This is obvious to me now but it didn't occur to me before that  
> multiple values for a single field would work with a range query. Like  
> I said this works fine for me. Thanks for the help.
> 
> On Nov 15, 8:49 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > I don't understand your solution..., a single field with multiple values  
> > or  
> > a field repeating itself several times is the same when it comes to  
> > elasticsearch...
> > 
> > On Mon, Nov 14, 2011 at 9:16 PM, Shane Witbeck \<[sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)  
> > wrote:
> > 
> > > Correct. Each indexed document is a Thread with denormalized fields  
> > > about the thread and reply posts. As a solution I was able to add a  
> > > field "postDates" which is a collection of java.util.Date objects and  
> > > perform a range query on that field.
> > 
> > > On Nov 13, 3:15 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > 
> > > > The document that you index includes a thread, and then several  
> > > > posts? In  
> > > > this case, you can simply do the range check on the _single_  
> > > > dataCreated  
> > > > field. Multiple values in a document for a field can become tricky  
> > > > when  
> > > > wanting to execute a complex query, against several multiple fields,  
> > > > but  
> > > > have those constraints only match per "array element" (in which case,  
> > > > nested docs can help).
> > 
> > > > On Fri, Nov 11, 2011 at 7:46 PM, Shane Witbeck \<  
> > > > [sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)  
> > > > wrote:
> > 
> > > > > I'd like to offer a date range feature where I have an index of  
> > > > > forum  
> > > > > threads with one or more reply posts. Each post has dateCreated  
> > > > > field  
> > > > > that I'd like to use in the date range.
> > 
> > > > > Thread A  
> > > > > |- reply post 1  
> > > > > |- reply post 2  
> > > > > ...
> > 
> > > > > What's the best way to accomplish doing a date range with multiple  
> > > > > dates defined for each index document? I'm using the Java API.
> > 
> > > > > Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:48am UTC](https://discuss.elastic.co/t/date-range-with-multiple-values/5847/7 "2017-07-06T03:48:31Z")

</div>


