Example How to use node entity queries conditions by reference fields in Drupal 8.
$results = \Drupal::entityQuery('node')
->condition('type', 'event')
->condition('field_location.entity:node.field_venue_type', 'test')
->execute();
Example 2 :
$results = \Drupal::entityQuery('node')
->condition('type', 'event')
->condition('field_location.entity:node.field_tags.entity:taxonomy_term.name', 'sailboat')
->execute();