# Grandparents aggregations NullPointer

**URL:** <https://discuss.elastic.co/t/grandparents-aggregations-nullpointer/22624>\
**Category:** Elasticsearch\
**Created:** [March 11, 2015, 8:42pm UTC](https://discuss.elastic.co/t/grandparents-aggregations-nullpointer/22624 "2015-03-11T20:42:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paolociccarese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paolociccarese/32/695_2.png) [@paolociccarese](https://discuss.elastic.co/u/paolociccarese)\
**Post date:** [March 11, 2015, 8:42pm UTC](https://discuss.elastic.co/t/grandparents-aggregations-nullpointer/22624/1 "2015-03-11T20:42:27Z")

</div>

I am using Elasticsearch 1.4.4.

I am defining a parent-child index with three levels (grandparents)  
following the instructions in the document:  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/grandparents.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/grandparents.html)

My structure is  
Continent -\> Country -\> Region

## MAPPING

I create an index with the following mapping:

curl -XPOST 'localhost:9200/geo' -d'  
{  
"mappings": {  
"continent": {},  
"country": {  
"\_parent": {  
"type": "continent"  
}  
},  
"region": {  
"\_parent": {  
"type": "country"  
}  
}  
}  
}'

## INDEXING

I index three entities:

curl -XPOST 'localhost:9200/geo/continent/europe' -d'  
{  
"name":"Europe"  
}'

curl -XPOST 'localhost:9200/geo/country/italy?parent=europe' -d'  
{  
"name":"Italy"  
}'

curl -XPOST  
'localhost:9200/geo/region/lombardy?parent=italy&routing=europe' -d'  
{  
"name":"Lombardia"  
}'

## QUERY THAT WORKS

If I query and aggregate according to the document everything works fine:

curl -XGET 'localhost:9200/geo/continent/\_search?pretty=true' -d '  
{  
"query": {  
"has\_child": {  
"type": "country",  
"query": {  
"has\_child": {  
"type": "region",  
"query": {  
"match": {  
"name": "Lombardia"  
}  
}  
}  
}  
}  
},  
"aggs": {  
"country": {  
"terms": {  
"field": "name"  
},  
"aggs": {  
"countries": {  
"children": {  
"type": "country"  
},  
"aggs": {  
"country\_names" : {  
"terms" : {  
"field" : "country.name"  
}  
}  
}  
}  
}  
}  
}  
}'

## QUERY THAT DOES NOT WORK

However, if I try with multi-level aggregations like in:

curl -XGET 'localhost:9200/geo/continent/\_search?pretty=true' -d '  
{  
"query": {  
"has\_child": {  
"type": "country",  
"query": {  
"has\_child": {  
"type": "region",  
"query": {  
"match": {  
"name": "Lombardia"  
}  
}  
}  
}  
}  
},  
"aggs": {  
"continent\_names": {  
"terms": {  
"field": "name"  
},  
"aggs": {  
"countries": {  
"children": {  
"type": "country"  
},  
"aggs": {  
"regions": {  
"children": {  
"type": "region"  
},  
"aggs": {  
"region\_names" : {  
"terms" : {  
"field" : "region.name"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}'

I get back the following

{

"error" : "SearchPhaseExecutionException[Failed to execute phase [query],  
all shards failed; shardFailures {[b5CbW5byQdSSW-rIwta0rA][geo][0]:  
QueryPhaseExecutionException[[geo][0]:  
query[filtered(child\_filter[country/continent](filtered(child\_filterregion/country)-\>cache(\_type:country)))-\>cache(\_type:continent)],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested: NullPointerException;  
}{[b5CbW5byQdSSW-rIwta0rA][geo][1]: QueryPhaseExecutionException[[geo][1]:  
query[filtered(child\_filter[country/continent](filtered(child\_filterregion/country)-\>cache(\_type:country)))-\>cache(\_type:continent)],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested: NullPointerException;  
}{[b5CbW5byQdSSW-rIwta0rA][geo][2]: QueryPhaseExecutionException[[geo][2]:  
query[filtered(child\_filter[country/continent](filtered(child\_filterregion/country)-\>cache(\_type:country)))-\>cache(\_type:continent)],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested: NullPointerException;  
}{[b5CbW5byQdSSW-rIwta0rA][geo][3]: QueryPhaseExecutionException[[geo][3]:  
query[filtered(child\_filter[country/continent](filtered(child\_filterregion/country)-\>cache(\_type:country)))-\>cache(\_type:continent)],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested: NullPointerException;  
}{[b5CbW5byQdSSW-rIwta0rA][geo][4]: QueryPhaseExecutionException[[geo][4]:  
query[filtered(child\_filter[country/continent](filtered(child\_filterregion/country)-\>cache(\_type:country)))-\>cache(\_type:continent)],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested: NullPointerException;  
}]",

"status" : 500

}

The 'grandparents' document says: "Querying and aggregating across  
generations works, as long as you step through each generation."

How do I get the last query and aggregation to work across all three levels  
of the index?

What am I missing?

Thank you,  
Paolo

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f4426a7b-124e-450e-98c0-cc43cf7f9c6b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4426a7b-124e-450e-98c0-cc43cf7f9c6b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![paolociccarese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paolociccarese/32/695_2.png) [@paolociccarese](https://discuss.elastic.co/u/paolociccarese)\
**Post date:** [March 24, 2015, 2:49pm UTC](https://discuss.elastic.co/t/grandparents-aggregations-nullpointer/22624/2 "2015-03-24T14:49:02Z")

</div>

I've posted the issue here:

> <https://github.com/elastic/elasticsearch/issues/10158>
>
> I am using Elasticsearch 1.4.4.
> I am defining a parent-child index with three le…vels (grandparents) following the instructions in the document: https://www.elastic.co/guide/en/elasticsearch/guide/current/grandparents.html
> My structure is Continent -\> Country -\> Region
> \## MAPPING
> 
> I create an index with the following mapping:
> 
> \`\`\`
> curl -XPOST 'localhost:9200/geo' -d'
> {
> "mappings": {
> "continent": {},
> "country": {
> "\_parent": {
> "type": "continent" 
> }
> },
> "region": {
> "\_parent": {
> "type": "country" 
> }
> }
> }
> }' 
> \`\`\`
> \## INDEXING
> 
> I index three entities:
> 
> \`\`\`
> curl -XPOST 'localhost:9200/geo/continent/europe' -d'
> {
> "name":"Europe"
> }'
> 
> curl -XPOST 'localhost:9200/geo/country/italy?parent=europe' -d'
> {
> "name":"Italy"
> }'
> 
> curl -XPOST 'localhost:9200/geo/region/lombardy?parent=italy&routing=europe' -d'
> {
> "name":"Lombardia"
> }'
> \`\`\`
> \## QUERY THAT WORKS
> 
> If I query and aggregate according to the document everything works fine:
> 
> \`\`\`
> curl -XGET 'localhost:9200/geo/continent/\_search?pretty=true' -d '
> {
> "query": {
> "has\_child": {
> "type": "country",
> "query": {
> "has\_child": {
> "type": "region",
> "query": {
> "match": {
> "name": "Lombardia"
> }
> }
> }
> }
> }
> },
> "aggs": {
> "country": {
> "terms": { 
> "field": "name"
> },
> "aggs": {
> "countries": {
> "children": {
> "type": "country"
> },
> "aggs": {
> "country\_names" : {
> "terms" : {
> "field" : "country.name"
> }
> }                   
> }
> }
> }
> }
> }
> }'
> \`\`\`
> \## QUERY THAT DOES NOT WORK
> 
> However, if I try with multi-level aggregations like in:
> 
> \`\`\`
> curl -XGET 'localhost:9200/geo/continent/\_search?pretty=true' -d '
> {
> "query": {
> "has\_child": {
> "type": "country",
> "query": {
> "has\_child": {
> "type": "region",
> "query": {
> "match": {
> "name": "Lombardia"
> }
> }
> }
> }
> }
> },
> "aggs": {
> "continent\_names": {
> "terms": { 
> "field": "name"
> },
> "aggs": {
> "countries": {
> "children": {
> "type": "country"
> },                  
> "aggs": {
> "regions": {
> "children": {
> "type": "region"
> }, 
> "aggs": {
> "region\_names" : {
> "terms" : {
> "field" : "region.name"
> }
> }
> }
> }
> }
> }
> }
> }
> }
> }'
> \`\`\`
> 
> I get back the following
> {
> 
> "error" : "SearchPhaseExecutionException\[Failed to execute phase \[query\], all shards failed; shardFailures {\[b5CbW5byQdSSW-rIwta0rA\]\[geo\]\[0\]: QueryPhaseExecutionException\[\[geo\]\[0\]: query\[filtered(child\_filter\[country/continent\](filtered%28child\_filter\[region/country\]%28filtered%28name:lombardia%29-\>cache%28\_type:region%29%29%29-\>cache%28\_type:country%29))-\>cache(\_type:continent)\],from\[0\],size\[10\]: Query Failed \[Failed to execute main query\]\]; nested: NullPointerException; }{\[b5CbW5byQdSSW-rIwta0rA\]\[geo\]\[1\]: QueryPhaseExecutionException\[\[geo\]\[1\]: query\[filtered(child\_filter\[country/continent\](filtered%28child\_filter\[region/country\]%28filtered%28name:lombardia%29-\>cache%28\_type:region%29%29%29-\>cache%28\_type:country%29))-\>cache(\_type:continent)\],from\[0\],size\[10\]: Query Failed \[Failed to execute main query\]\]; nested: NullPointerException; }{\[b5CbW5byQdSSW-rIwta0rA\]\[geo\]\[2\]: QueryPhaseExecutionException\[\[geo\]\[2\]: query\[filtered(child\_filter\[country/continent\](filtered%28child\_filter\[region/country\]%28filtered%28name:lombardia%29-\>cache%28\_type:region%29%29%29-\>cache%28\_type:country%29))-\>cache(\_type:continent)\],from\[0\],size\[10\]: Query Failed \[Failed to execute main query\]\]; nested: NullPointerException; }{\[b5CbW5byQdSSW-rIwta0rA\]\[geo\]\[3\]: QueryPhaseExecutionException\[\[geo\]\[3\]: query\[filtered(child\_filter\[country/continent\](filtered%28child\_filter\[region/country\]%28filtered%28name:lombardia%29-\>cache%28\_type:region%29%29%29-\>cache%28\_type:country%29))-\>cache(\_type:continent)\],from\[0\],size\[10\]: Query Failed \[Failed to execute main query\]\]; nested: NullPointerException; }{\[b5CbW5byQdSSW-rIwta0rA\]\[geo\]\[4\]: QueryPhaseExecutionException\[\[geo\]\[4\]: query\[filtered(child\_filter\[country/continent\](filtered%28child\_filter\[region/country\]%28filtered%28name:lombardia%29-\>cache%28\_type:region%29%29%29-\>cache%28\_type:country%29))-\>cache(\_type:continent)\],from\[0\],size\[10\]: Query Failed \[Failed to execute main query\]\]; nested: NullPointerException; }\]",
> 
> "status" : 500
> 
> }
> 
> The 'grandparents' document says: "Querying and aggregating across generations works, as long as you step through each generation."
> 
> How do I get the last query and aggregation to work across all three levels of the index?
> 
> What am I missing?
> 
> Thank you,
> Paolo

On Wednesday, March 11, 2015 at 4:42:27 PM UTC-4, Paolo Ciccarese wrote:

> I am using Elasticsearch 1.4.4.
> 
> I am defining a parent-child index with three levels (grandparents)  
> following the instructions in the document:
> 
> [Grandparents and Grandchildren | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/grandparents.html)
> 
> My structure is  
> Continent -\> Country -\> Region
> 
> ## MAPPING
> 
> I create an index with the following mapping:
> 
> curl -XPOST 'localhost:9200/geo' -d'  
> {  
> "mappings": {  
> "continent": {},  
> "country": {  
> "\_parent": {  
> "type": "continent"  
> }  
> },  
> "region": {  
> "\_parent": {  
> "type": "country"  
> }  
> }  
> }  
> }'
> 
> ## INDEXING
> 
> I index three entities:
> 
> curl -XPOST 'localhost:9200/geo/continent/europe' -d'  
> {  
> "name":"Europe"  
> }'
> 
> curl -XPOST 'localhost:9200/geo/country/italy?parent=europe' -d'  
> {  
> "name":"Italy"  
> }'
> 
> curl -XPOST  
> 'localhost:9200/geo/region/lombardy?parent=italy&routing=europe' -d'  
> {  
> "name":"Lombardia"  
> }'
> 
> ## QUERY THAT WORKS
> 
> If I query and aggregate according to the document everything works fine:
> 
> curl -XGET 'localhost:9200/geo/continent/\_search?pretty=true' -d '  
> {  
> "query": {  
> "has\_child": {  
> "type": "country",  
> "query": {  
> "has\_child": {  
> "type": "region",  
> "query": {  
> "match": {  
> "name": "Lombardia"  
> }  
> }  
> }  
> }  
> }  
> },  
> "aggs": {  
> "country": {  
> "terms": {  
> "field": "name"  
> },  
> "aggs": {  
> "countries": {  
> "children": {  
> "type": "country"  
> },  
> "aggs": {  
> "country\_names" : {  
> "terms" : {  
> "field" : "country.name"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> ## QUERY THAT DOES NOT WORK
> 
> However, if I try with multi-level aggregations like in:
> 
> curl -XGET 'localhost:9200/geo/continent/\_search?pretty=true' -d '  
> {  
> "query": {  
> "has\_child": {  
> "type": "country",  
> "query": {  
> "has\_child": {  
> "type": "region",  
> "query": {  
> "match": {  
> "name": "Lombardia"  
> }  
> }  
> }  
> }  
> }  
> },  
> "aggs": {  
> "continent\_names": {  
> "terms": {  
> "field": "name"  
> },  
> "aggs": {  
> "countries": {  
> "children": {  
> "type": "country"  
> },  
> "aggs": {  
> "regions": {  
> "children": {  
> "type": "region"  
> },  
> "aggs": {  
> "region\_names" : {  
> "terms" : {  
> "field" : "region.name"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> I get back the following
> 
> {
> 
> "error" : "SearchPhaseExecutionException[Failed to execute phase  
> [query], all shards failed; shardFailures  
> {[b5CbW5byQdSSW-rIwta0rA][geo][0]: QueryPhaseExecutionException[[geo][0]:  
> query[filtered(child\_filtercountry/continent)-\>cache(\_type:continent)],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> }{[b5CbW5byQdSSW-rIwta0rA][geo][1]: QueryPhaseExecutionException[[geo][1]:  
> query[filtered(child\_filtercountry/continent)-\>cache(\_type:continent)],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> }{[b5CbW5byQdSSW-rIwta0rA][geo][2]: QueryPhaseExecutionException[[geo][2]:  
> query[filtered(child\_filtercountry/continent)-\>cache(\_type:continent)],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> }{[b5CbW5byQdSSW-rIwta0rA][geo][3]: QueryPhaseExecutionException[[geo][3]:  
> query[filtered(child\_filtercountry/continent)-\>cache(\_type:continent)],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> }{[b5CbW5byQdSSW-rIwta0rA][geo][4]: QueryPhaseExecutionException[[geo][4]:  
> query[filtered(child\_filtercountry/continent)-\>cache(\_type:continent)],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> }]",
> 
> "status" : 500
> 
> }
> 
> The 'grandparents' document says: "Querying and aggregating across  
> generations works, as long as you step through each generation."
> 
> How do I get the last query and aggregation to work across all three  
> levels of the index?
> 
> What am I missing?
> 
> Thank you,  
> Paolo

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0cbdfb5e-ad20-4820-aac9-48c837976fd0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0cbdfb5e-ad20-4820-aac9-48c837976fd0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:24am UTC](https://discuss.elastic.co/t/grandparents-aggregations-nullpointer/22624/3 "2017-07-06T00:24:28Z")

</div>


