This seems broken in 0.19.*. I had a working parent/child solution even
before the new has_child/has_parent filters were implemented (see:
http://stackoverflow.com/questions/7431889/how-can-i-retrieve-matching-children-only)
and now it doesn't work anymore.
I thought that maybe my indexes went awry, but deleting them and creating
from scratch is not a problem for me, so I did that... And it did not help.
Suprised by the outcome I tried to run the queries with authors and books
from this blog post -
http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/- just to try something very simple. So I have a dynamic (auto) mapping for
the author, a manual mapping for the book (which specifies that author is
the parent) and then added those two authors and three books. Then tried
running the query to retrieve all books by an author, I tried both
has_child and has_parent and they return 0 results. There is no error of
any kind, just 0 results. Always. And in my old solution it started
complaining about not being able to parse parent or _parent.
Could somebody take a look and run the same queries against your
ElasticSearch and tell me if parent/child queries work for you? I'll copy
the steps below:
curl -XPUT localhost:9200/authors/bare_author/1 -d'{ "name": "Multi G. Enre"
}' curl -XPUT localhost:9200/authors/bare_author/2 -d'{ "name": "Alastair
Reynolds" }'
curl -XPOST localhost:9200/authors/book/_mapping -d '{ "book":{ "_parent": {
"type": "bare_author"} } }'
curl -XPOST localhost:9200/authors/book/1?parent=2 -d '{ "name": "Revelation
Space", "genre": "scifi", "publisher": "penguin" }' curl -XPOST localhost:
9200/authors/book/2?parent=1 -d '{ "name": "Guns and lasers", "genre":
"scifi", "publisher": "orbit" }' curl -XPOST localhost:9200/authors/book/3
?parent=1 -d '{ "name": "Dead in the night", "genre": "thriller",
"publisher": "penguin" }'
curl -XPOST localhost:9200/authors/bare_author/_search -d '{ "query": {
"has_child": { "type": "book", "query" : { "filtered": { "query": {
"match_all": {}}, "filter" : { "and": [ {"term": {"publisher": "penguin"}},
{"term": {"genre": "scifi"}} ] } } } } } }'
The last query should return all science fiction books published by
Penguin. It doesn't return anything. The query below should find all books
written by Multi G. Enre, again - it returns nothing (0 results):
curl -XGET localhost:9200/authors/book/_search -d '{
"query": "has_parent": "parent_type": "bare_author", "query": "term":
"name": "Multi G. Enre" } } } } }'
What's going on?
--