How to get user all order_items from different orders by entityQuery
Unfortunately, what you want to do isn't possible with an entity query, because that API does not support the appropriate joins. While you can simulate a join between a base entity and field value tables with field conditions, you cannot query against field values of referenced entities. If all you needed were order items referencing the order ID and specific purchasable entity ID, you'd be fine to write a single entity query against the order item table, but once you need to filter by order status (or support multiple purchasable entity types), you need to use \Drupal::database()-&gt;select().
To build a select query for this, I'd use the following:
$uid = 1;
$entity_id = 1;
$state = 'completed';

$query = \Drupal::database()-&gt;select('commerce_order', 'co');
$query-&gt;leftjoin('commerce_order_item', 'coi', 'co.order_id = coi.order_id');
$query-&gt;fields('co', ['order_id']);
$query-&gt;condition('co.state', $state);
$query-&gt;condition('co.uid', $uid);
$query-&gt;condition('coi.purchased_entity', $entity_id);
$result = $query-&gt;distinct()-&gt;countQuery()-&gt;execute()-&gt;fetchField();

The main change between your query and this code is that I'm fetching a count of the distinct number of orders. If you're trying to get the order IDs, remove the countQuery() and replace the fetchField() call with fetchAllKeyed(0, 0). If you really just want to search for a non zero count, you can remove the distinct() for faster query performance.