10 cls
10 cls

Reputation: 1445

Is it possible to find which elasticsearch shard(s) a document is on?

I'm having trouble debugging a parent child relationship query. I'd like to know ways of debugging the issue, rather than simply posting my mapping, data, query, and asking what's wrong (but I reserve the right to do so eventually!).

To that end, a start would be checking if my children and associated parent are on the same shard. I don't trust my mapping, and I don't want to calculate which shard the documents are theoretically on, using shard = hash(routing) % number_of_primary_shards. I want a query that returns a definite answer.

Upvotes: 10

Views: 6524

Answers (2)

Vineeth Mohan
Vineeth Mohan

Reputation: 19283

In your query , you can enable explain flag and it will tell you where each of the documents are from which shard and node. You can find a sample query as follows -

{
  "explain": true,
  "query": {
    "match_all": {}
  }
}

Along with docID , index name and type name , it will also emit node ID and shard ID.

You can find samples on usage of explain API here.

Upvotes: 16

johno
johno

Reputation: 852

To debug this you don't have to check shard and node identifiers at all.

All you have to do is make sure that _parent and/or _routing fields of the child documents match the id of the parent document. Use /_search?pretty&fields=_parent,_routing&_source=true to show these fields.

To find docs with a specific _routing or _parent id just use /_search?pretty&fields=_parent,_routing&_source=true&q=id:123 OR _routing:123 OR _parent:123 This will find parent docs and child docs.

Upvotes: 1

Related Questions