Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining Grandparents aggregations, getting a NullPointer #10158

Closed
paolociccarese opened this issue Mar 19, 2015 · 2 comments

Comments

@paolociccarese
Copy link

commented Mar 19, 2015

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

@javanna

This comment has been minimized.

Copy link
Member

commented Mar 25, 2015

this seems like a bug, @martijnvg can you have a look please?

@martijnvg

This comment has been minimized.

Copy link
Member

commented Mar 25, 2015

@paolociccarese @javanna Sorry, I missed this! I opened PR #10263 for this bug.

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Mar 28, 2015
1) multiple nested children aggs result in a NPE
2) fixed a counting bug where the same readers where post collected twice

Closes elastic#10158
martijnvg added a commit that referenced this issue Mar 28, 2015
1) multiple nested children aggs result in a NPE
2) fixed a counting bug where the same readers where post collected twice

Closes #10158
@martijnvg martijnvg closed this in 16d8f3c Mar 28, 2015
martijnvg added a commit that referenced this issue Mar 28, 2015
1) multiple nested children aggs result in a NPE
2) fixed a counting bug where the same readers where post collected twice

Closes #10158
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
1) multiple nested children aggs result in a NPE
2) fixed a counting bug where the same readers where post collected twice

Closes elastic#10158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.