title: ElasticSearch: How to check which node/replica does the document comes from/goes to?
body: <p>Let say I have 5 data nodes. Then I save a <code>Person</code> document. Now how couple of questions:</p>
  
  <ol>
  <li><p>How can I find which node is the saved document saved to?</p></li>
  <li><p>After saving one <code>Person</code> document to a node with two replicas how can I query for this <code>Person</code> and get info which replica/node does the resulting answer comes from?</p></li>
  <li><p>How can I check how fast the document is available in two replicas of a node?</p></li>
  </ol>
  
  <p><strong>EDIT</strong></p>
  
  <p><strong>The use case is as follows:</strong>
  In general how to assure consistency in case when a primary shard have new data written but the data has not yet been synchronised with a replica. At the same time the replica is being queried for the new data that is present only at the primary shard at the time of querying the replica. Pretty much I wonder about <strong>DETAILS</strong> of consistency in situation as described in last paragraph <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/distrib-read.html" rel="nofollow">of the distributed read documentation</a>  ===> <strong>but</strong> on the other hand <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_query_phase.html" rel="nofollow">here the doc says about query phase</a> that each primary and replica are queried and build <em>priority queues</em> that are later merged, thus the result form primary shard would be included in merged queue based at the globally sorted result set build out of all priority queues at the coordinating node. </p>
  
  <ul>
  <li><strong>Question X</strong> So is the exclusive doc from primary shard returned at search or not in case it is not being replicated to remaining replicas?</li>
  </ul>
  
  <hr>
  
  <p>In other words.
  I want to assure data consistency across my distributed ES cluster. Now I want to test if the following situation can take place. Lets say I have one cluster with 5 nodes and the data are put only to one node (e.g. <code>node2</code> with primary shard). Before the data have time to replicate to remaining replicas I got query for this new data towards <code>node3</code> which in theory should have the replica of the data, but didn't get it yet after the <code>node2</code> got changed. So in this case query committed towards the <code>node3</code> requesting the new data would have not return the new data even though they have been put to 'node2'. </p>
  
  <ul>
  <li>Question A) If this might happen how can I control the replication
  phases/state so that I can tell if the replication is complete?</li>
  <li>Question B) How can I tell if the replica is consistent with the primary shard or not, and in what state it is (replica's data is consistent or incosistent with primary shard)?</li>
  <li>Question C) If I can't control this replication flow and data
  consistency how can I eliminate potential inconsistencies for query
  committed toward <code>node3</code>?</li>
  <li>Question D) How can I observe the behaviour of adding a doc to primary shard, and not having it stored at the replica shard (e.g. can I slow down / customize the time of replication or can I test this behaviour some other way)? </li>
  </ul>