Range search on nested object

Hi,

I have an object that looks like thishttps://gist.github.com/getsometoast/5206743and I'm trying to do a range query on the source ->date property. At the
moment, my query looks like thishttps://gist.github.com/getsometoast/5206826but it's not returning any results. I can confirm that in my index I have
documents that should be returned by the query - so I'm guessing it's the
syntax of the query that's wrong. Any ideas?

Regards,
James

--

This email, including attachments, is private and confidential. If you have
received this email in error please notify the sender and delete it from
your system. Emails are not secure and may contain viruses. No liability
can be accepted for viruses that might be transferred by this email or any
attachment. Any unauthorised copying of this message or unauthorised
distribution and publication of the information contained herein are
prohibited. 7digital Limited. Registered office: Unit F, Lower Ground
Floor, 5-25 Scrutton Street, Zetland House London EC2A 4HJ. Registered in
England and Wales. Registered No. 04843573.

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

On Wed, 2013-03-20 at 10:50 -0700, james.lewis@7digital.com wrote:

Hi,

I have an object that looks like this and I'm trying to do a range
query on the source ->date property. At the moment, my query looks
like this but it's not returning any results. I can confirm that in
my index I have documents that should be returned by the query - so
I'm guessing it's the syntax of the query that's wrong. Any ideas?

Partial gists seldom provide enough info :slight_smile:

You're using a nested query, but you don't specify whether "source" is
{type: "nested"} or {type: "object"}

If you haven't set it to "nested" specifically, then it is "object", in
which case don't use a "nested" query.

Also, we're not sure that your "date" field is actually mapped as a
date.

clint

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

Interesting... especially the date bit...

I haven't set the mappings up explicitly so "source" will be an object as
you pointed out. I think I'm using the term nested incorrectly here - I
chose the nested query not because I thought "date" was part of a nested
type, but because I thought date was nested within "source" (if that
makes sense?!)

OK let me rephrase my question. Given that I'm using a default dynamic
mapping and that I've indexed a bunch of documents as per my
gisthttps://gist.github.com/getsometoast/5206743and assuming the
date were mapped as a date, how would you write a range
query that matched any documents where the source.date field is between
from {some-date} and to {some-date}.

Regards,
James

On Thu, Mar 21, 2013 at 11:58 AM, Clinton Gormley clint@traveljury.comwrote:

On Wed, 2013-03-20 at 10:50 -0700, james.lewis@7digital.com wrote:

Hi,

I have an object that looks like this and I'm trying to do a range
query on the source ->date property. At the moment, my query looks
like this but it's not returning any results. I can confirm that in
my index I have documents that should be returned by the query - so
I'm guessing it's the syntax of the query that's wrong. Any ideas?

Partial gists seldom provide enough info :slight_smile:

You're using a nested query, but you don't specify whether "source" is
{type: "nested"} or {type: "object"}

If you haven't set it to "nested" specifically, then it is "object", in
which case don't use a "nested" query.

Also, we're not sure that your "date" field is actually mapped as a
date.

clint

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/6mfLJZeRrsI/unsubscribe?hl=en-US
.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--

This email, including attachments, is private and confidential. If you have
received this email in error please notify the sender and delete it from
your system. Emails are not secure and may contain viruses. No liability
can be accepted for viruses that might be transferred by this email or any
attachment. Any unauthorised copying of this message or unauthorised
distribution and publication of the information contained herein are
prohibited. 7digital Limited. Registered office: Unit F, Lower Ground
Floor, 5-25 Scrutton Street, Zetland House London EC2A 4HJ. Registered in
England and Wales. Registered No. 04843573.

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

I haven't set the mappings up explicitly so "source" will be an object
as you pointed out. I think I'm using the term nested incorrectly
here - I chose the nested query not because I thought "date" was part
of a nested type, but because I thought date was nested within
"source" (if that makes sense?!)

OK let me rephrase my question. Given that I'm using a default
dynamic mapping and that I've indexed a bunch of documents as per my
gist and assuming the date were mapped as a date, how would you write
a range query that matched any documents where the source.date field
is between from {some-date} and to {some-date}.

Just remove the nested query, leaving:

{
"query" : {
"range" : {
"date" : {
"to" : "2013-01-02T00:00:00+00:00",
"from" : "2013-01-01T00:00:00+00:00"
}
}
}
}

Or, if you want to use a range filter instead, perhaps in combination
with some other query clause:

{
"query" : {
"query" : {
"match_all" : {}
},
"filtered" : {
"filter" : {
"range" : {
"date" : {
"to" : "2013-01-02T00:00:00+00:00",
"from" : "2013-01-01T00:00:00+00:00"
}
}
}
}
}
}

And if you want to find out if your date field has been recognised as a
date field, just check the mapping:

curl -XGET 'http://127.0.0.1:9200/_all/_mapping?pretty=1'

clint

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