"Cannot invoke "java.util.List.get(int)" because "nestedParsedSource" is null" when using nested properties + has_parent + inner_hits

Hello everyone,

I've been banging my head against this for a while and it seems I've reached a dead end. I've tried to simplify the code as much as possible.

Problem:
I'm using the child/parent relationships and nested type property (on the parent) in my mapping also with the explicit type field as in documentation.

My query is to fetch documents of certain type (event in the example), which have a parent and use inner_hits on the has_parent query to fetch also the information about the parent using _source.

This all works until the parent document has at least 1 nested field indexed, in that case the query fails with the exception:

"Cannot invoke "java.util.List.get(int)" because "nestedParsedSource" is null"

My index & mapping:

DELETE /test
PUT /test
{
    "mappings": {
        "dynamic": false,
        "_meta": { "version": "0073_00" },
        "properties": {
            "id": { "type": "keyword" },
            "role": {
                "type": "join",
                "eager_global_ordinals": true,
                "relations": {
                    "user": ["event"]
                }
            },
            "type": { "type": "keyword" },
            "username": { "type": "text" },
            "title": { "type": "text" },
            "fields": {
                "dynamic": false,
                "type": "nested",
                "properties": {
                    "value": { "type": "keyword" },
                    "key": { "type": "keyword" }
                }
            }
        }
    }
}

Indexing a User and one Event, notice User has nested data:

POST /test/_doc/u-1?refresh
{
    "id": "u-1",
    "username": "User1",
    "role": "user",
    "type": "user",
    "fields": [
        {"key": "GMC", "value": "111111"}
    ]
}
POST /test/_doc/e-1?routing=u-1&refresh
{
    "id": "e-1",
    "title": "Event 1",
    "type": "event",
    "role": {
        "name": "event",
        "parent": "u-1"
    }
}

Query I use, notice '_source:true' which fails with the above exception.

GET /test/_search
{
    "_source": false,
    "fields": [ "title" ],
    "query": {
        "bool": {
            "must": [
                { "term": { "type": "event" } },
                {
                    "has_parent": {
                        "query": { "match_all": {} },
                        "inner_hits": { "_source":true },
                        "parent_type": "user"
                    }
                }
            ]
        }
    }
}

If I change the '_source:false' on the 'inner_hits' in the query, it returns results but the inner_hits includes the nested property in the 'inner_hits' which I have no idea why.

"inner_hits": {
    "user": {
        "hits": {
            "total": {
                "value": 2,
                "relation": "eq"
            },
            "max_score": 1,
            "hits": [
                {
                    "_index": "test",
                    "_type": "_doc",
                    "_id": "e-1",
                    "_nested": {
                        "field": "fields",
                        "offset": 0
                    },
                    "_score": 1
                },
                {
                    "_index": "test",
                    "_type": "_doc",
                    "_id": "u-1",
                    "_score": 1
                }
            ]
        }
    }
}

Finally if I change the query to fetch a specific parent ID, the query returns valid result

GET /test/_search
{
    "_source": false,
    "fields": [ "title" ],
    "query": {
        "bool": {
            "must": [
                { "term": { "type": "event" } },
                {
                    "has_parent": {
                        "query": { "term": {"id": "u-1"} },
                        "inner_hits": { "_source": true },
                        "parent_type": "user"
                    }
                }
            ]
        }
    }
}
...
"inner_hits": {
    "user": {
        "hits": {
            "total": {
                "value": 1,
                "relation": "eq"
            },
            "max_score": 0.6931471,
            "hits": [
                {
                    "_index": "test",
                    "_type": "_doc",
                    "_id": "u-1",
                    "_score": 0.6931471,
                    "_source": {
                        "id": "u-1",
                        "username": "User1",
                        "role": "user",
                        "type": "user",
                        "fields": [
                            {
                                "key": "GMC",
                                "value": "111111"
                            }
                        ]
                    }
                }
            ]
        }
    }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.