Nested Array Document Query (similar to @tsolakp's problem)

I imagine tsolakp and I are having the same problem, but I did get a nested query to run on a nested field that's a simple Hash. However, I'm having problem querying a nested document that contains an array of hashes (exactly like obj1 here: http://www.elasticsearch.org/guide/reference/mapping/nested-type.html).

Here's the mapping I've got.

{
"tweet" : {
"properties" : {
"name" : {
"type" : "string"
},
"comments" : {
"properties" : {
"text" : {
"type" : "string"
},
"username" : {
"type" : "string"
},
},
"type" : "nested"
}
}
}
}

and I indexed this document

{
"name" : "Jane",
"comments" : [
{"text" : "this is text", "username" : "Jane"},
{"text" : "this is more text", "username" : "Jack"}
]
}

I'm trying to search the comments section by username and I've issued the following query:

{
"query" : {
"nested" : {
"path" : "comments",
"query" : {
"bool" : {
"must" : [
{
"text" : {
"comments.username" : "Jane"
}
}
]
}
}
}
}
}

However I'm not getting any hits....

I basically followed the documentation exactly and am not sure why this is happening. Any ideas?

---UPDATE

turns out this query works, but the text query does not still looking into it....

'{
"query" : {
"nested" : {
"path" : "comments",
"query" : {
"query_string" : {
"default_field" : "comments.text",
"query" : "this is more text"}}}}}'

--UPDATE2
I tried a simple text query on comments.text and it returned no hits. I must be missing something about how the text query works...

Both your mapping and your query are not valid jsons (use jsonlint for
example to test that: http://jsonlint.com/). Here is a gist of the valid
ones: gist:1108683 · GitHub.

A note to users posting on the list, it will be much simpler to help you
with gisted curl recreations, and not pasting random bits and pieces into
the mail.

On Mon, Jul 25, 2011 at 11:06 PM, kikster <
christopherdavidolivares@gmail.com> wrote:

I imagine tsolakp and I are having the same problem, but I did get a nested
query to run on a nested field that's a simple Hash. However, I'm having
problem querying a nested document that contains an array of hashes
(exactly
like obj1 here:
Elasticsearch Platform — Find real-time answers at scale | Elastic).

Here's the mapping I've got.

{
"tweet" : {
"properties" : {
"name" : {
"type" : "string"
},
"comments" : {
"properties" : {
"text" : {
"type" : "string"
},
"username" : {
"type" : "string"
},
},
"type" : "nested"
}
}
}
}

and I indexed this document

{
"name" : "Jane",
"comments" : [
{"text" : "this is text", "username" : "Jane"},
{"text" : "this is more text", "username" : "Jack"}
]
}

I'm trying to search the comments section by username and I've issued the
following query:

{
"query" : {
"nested" : {
"path" : "comments",
"query" : {
"bool" : {
"must" : [
"text" : {
"comments.text" : "this"
}
]
}
}
}
}
}

However I'm getting a parsing error like this:
Parse Failure [Failed to parse source [{"query" : {"nested" ..........

I basically followed the documentation exactly (after help from @favre) but
am not sure why I'm still getting an error. Any ideas?

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Nested-Array-Doc-Query-similar-to-tsolakp-problem-tp3198558p3198558.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.