You are here

public function SearchApiElasticsearchIndex::deleteAllItems in Search API Elasticsearch 7.2

Delete all documents in an Elasticsearch index.

File

includes/SearchApiElasticsearchIndex.inc, line 120

Class

SearchApiElasticsearchIndex

Code

public function deleteAllItems() {
  $names = $this->search_api_service
    ->getClient()
    ->getCluster()
    ->getNodeNames();
  $name = reset($names);
  $node = new Node($name, $this->search_api_service
    ->getClient());
  $info = new Info($node);
  if ($info
    ->hasPlugin('delete-by-query')) {
    $match_all = new MatchAll();
    $index = $this
      ->getRealIndex();
    $index
      ->deleteByQuery($match_all);
  }
  else {
    $this
      ->replaceIndex($this->search_api_index, $this
      ->getRealIndex());
  }
}