Hi Rukshan
Very nicely laid out question. Thanks for providing all of the steps.
I agree that it doesn't work and (at least according to the docs) it
should, so I've opened an issue here:
opened 10:28AM - 12 Mar 14 UTC
closed 12:19PM - 21 Jan 16 UTC
>bug
discuss
:Search/Search
With a Parent > Child > Grandchild relationship, you can use a `term` query on t… he `_parent` field to find children with a particular `$parent`, but not grandchildren with parent `$Child`:
```
DELETE /myindx
PUT /myindex
{
"mappings": {
"Parent": {
"properties": {
"name": {
"type": "string",
"index": "analyzed"
}
}
},
"Child": {
"_parent": {
"type": "Parent"
},
"properties": {
"name": {
"type": "string",
"index": "analyzed"
}
}
},
"GrandChild": {
"_parent": {
"type": "Child"
},
"properties": {
"name": {
"type": "string",
"index": "analyzed"
}
}
}
}
}
POST /_bulk
{ "index" : { "_index" : "myindex", "_type" : "Parent", "_id" : "alice" } }
{ "name" : "Alice" }
{ "index" : { "_index" : "myindex", "_type" : "Child", "_id" : "bob", "parent" : "alice" } }
{ "name" : "Bob"}
{ "index" : { "_index" : "myindex", "_type" : "GrandChild", "_id" : "gc1", "parent" : "bob", "routing" : "alice" } }
{ "name" : "grand child 1" }
{ "index" : { "_index" : "myindex", "_type" : "GrandChild", "_id" : "gc2", "parent" : "bob", "routing" : "alice" } }
{ "name" : "grand child 2"}
GET /_search?fields=_parent,_routing
```
This query works:
```
POST /myindex/Child/_search
{
"query": {
"term": {
"_parent": "alice"
}
}
}
```
This query doesn't:
```
POST /myindex/GrandChild/_search
{
"query": {
"term": {
"_parent": "bob"
}
}
}
```
But performing the same lookup with `has_parent` does work:
```
POST /myindex/GrandChild/_search
{
"query": {
"has_parent": {
"parent_type": "Child",
"query": {
"filtered": {
"filter": {
"term": {
"_id": "bob"
}
}
}
}
}
}
}
```
Curiously, performing the same lookup using a has_parent
query does work:
POST /myindex/GrandChild/_search
{
"query": {
"has_parent": {
"parent_type": "Child",
"query": {
"filtered": {
"filter": {
"term": {
"_id": "bob"
}
}
}
}
}
}
}
Clint
On 11 March 2014 20:20, Rukshan Perera rukshanperera@gmail.com wrote:
Hello,
I have uploaded curl scripts to gist
Term query to get children using parent id · GitHub .
I have a three level parent/child types as shown in the following mappings
{ "Parent" :
{
"properties" : {
"name" : {
"type" :"string",
"index":"analyzed"
}
}
}
}
{
"Child" :{
"_parent": {
"type": "Parent"
},
"properties" : {
"name" : {
"type" :"string",
"index":"analyzed"
}
}
}
}
{
"GrandChild" :{
"_parent": {
"type": "Child"
},
"properties" : {
"name" : {
"type" :"string",
"index":"analyzed"
}
}
}
}
I want to search for *GrandChild *documents based on its parent id (which
is the id of a Child in this example). I used the following query but it
does not return any hits. ( "bob" - id of *Child *document. "alice" - id
of *Parent *document)
curl -s -XPOST "http://localhost:9200/myindex/GrandChild/_search?routing=alice " -d '
{
"query" : {
"term" : { "_parent" : "bob" }
}
}'
However, I was able to get *Child *documents based on *Parent *id using
the following ( "alice" - id of *Parent *document)
curl -s -XPOST "http://localhost:9200/myindex/Child/_search?routing=alice " -d '
{
"query" : {
"term" : { "_parent" : "alice" }
}
}
Can someone please help me to get the first query working?
Thanks,
Rukshan
--
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 .
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/5619eff7-b267-429b-afc3-e4c41aedc76b%40googlegroups.com https://groups.google.com/d/msgid/elasticsearch/5619eff7-b267-429b-afc3-e4c41aedc76b%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout .
--
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 .
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPt3XKQ5uOmhddsLBr%3D7hb%2BbMKGMtGng-FiyGUW3ps3%2B0UCtBA%40mail.gmail.com .
For more options, visit https://groups.google.com/d/optout .