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