Sort by weight using \Drupal::entityQuery() I want to get all taxonomy term in $lang language, following snippet works correctly and return all terms of $lang code.

    $query = \Drupal::entityQuery('taxonomy_term');
    $query-&gt;condition('vid', "news_category");
    $query-&gt;condition('langcode', $lang);
    $tids = $query-&gt;execute();
    //$terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids);
    return new JsonResponse($tids);


Then I want get results in order that in the taxonomy list they are, try to sort them with $query-&gt;sort('weight','ASC'); but with following snippet the results are  the same before adding sort.

    $query = \Drupal::entityQuery('taxonomy_term');
    $query-&gt;condition('vid', "news_category");
    $query-&gt;condition('langcode', $lang);
    $query-&gt;sort('weight','ASC');
    $tids = $query-&gt;execute();
    //$terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids);
    return new JsonResponse($tids);


Does anybody know where the problem is? How can I get terms in order they are in  taxonomy list?
Taxonomy overview list uses something like:

  -&gt;sort('weight', 'ASC')
  -&gt;sort('name', 'ASC')


If that doesn't work for you, take a look at \Drupal\taxonomy\TermStorage::loadTree