schellingerht
schellingerht

Reputation: 5806

Elasticsearch: parent/child missing 85% of indexed relationships

For my index, I use parent/child in Elasticsearch

So I've the following:

My mapping is as follows:

PUT /esi
{
    "mappings": {
        "relation": {},
        "classification": {
            "_parent": {
                "type": "relation" 
            }
        },
        "inspection":
        {
            "_parent": {
                "type": "classification" 
            } 
        }
    }
}

I index all data: relations, classifications and inspections. I index each inspection as follows:

PUT /esi/inspection/i20862?parent=c12277
{
    "date": "2015-06-06"
}

I check my index with Sense and yes, all types are filled with the right number of documents. Now the strange thing:

I've indexed 10581 inspections. Each of them has a parent: I indexed each inspection with an parent like above. And the parents exist.

Now, I check with the following command:

POST /esi/inspection/_search
{
    "query":
    {
        "has_parent":
        {
            "parent_type": "classification",
            "query":
            {
                "match_all":
                {
                }
            }
        }
    }
}

Result: 1556 instead of 10581

When I check inspections type separately, I get a result of 10581 (right). But 1556 are matched with its parent.

I can't figure out why there is no match with the parent after indexing, while the given parent exists.

Upvotes: 2

Views: 176

Answers (1)

schellingerht
schellingerht

Reputation: 5806

I had to add the routing parameter to the grandchildren, so:

PUT /esi/inspection/i20862?parent=c12277&routing=r595
{
    "date": "2015-06-06"
}

This ensures that the grandchildren parent/childs/grandchildren are stored at the same shard.

With parent/child only, parent/child always stored at the same shard. When the child is parent, the shard can be different. That's why you need then the routing parameter.

Documentation: https://www.elastic.co/guide/en/elasticsearch/guide/current/grandparents.html

Upvotes: 2

Related Questions