Date range with multiple values?


(Shane Witbeck) #1

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.


(Shay Banon) #2

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

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.


(Shane Witbeck) #3

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

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.


(Shay Banon) #4

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

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


(Shane Witbeck) #5

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

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


(Shay Banon) #6

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

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

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.


(system) #7