You are here

public function SearchApiElasticsearchConnector::deleteItems in Elasticsearch Connector 7.2

Same name and namespace in other branches
  1. 7.5 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::deleteItems()
  2. 7 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::deleteItems()

Overrides deleteItems().

Overrides SearchApiServiceInterface::deleteItems

File

modules/elasticsearch_connector_search_api/service.inc, line 516
Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.

Class

SearchApiElasticsearchConnector
Search service class.

Code

public function deleteItems($ids = 'all', SearchApiIndex $index = NULL) {
  if (empty($index)) {
    foreach ($this
      ->getIndexes() as $index) {
      $this
        ->deleteItems('all', $index);
    }
  }
  elseif ($ids === 'all') {
    if ($this
      ->versionIs2x()) {
      $settings = $this
        ->getElasticsearchIndexSettings($index);
      $index->force_create['number_of_shards'] = $settings['index']['number_of_shards'];
      $index->force_create['number_of_replicas'] = $settings['index']['number_of_replicas'];
      $this
        ->removeIndex($index);
      $this
        ->addIndex($index);
    }
    else {
      $version = $this
        ->getClusterVersion();
      $params = $this
        ->getIndexParam($index, TRUE);
      $site_id = $this
        ->getSiteHash();
      if ($site_id) {
        $params['body'] = array(
          'query' => array(
            'match' => array(
              'search_api_site_hash' => $site_id,
            ),
          ),
        );
      }
      else {
        $params['body'] = array(
          'query' => array(
            'match_all' => array(),
          ),
        );
      }

      // The 'delete by query' API request changed in version 1.0.0RC1.
      // @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
      if (version_compare($version, '1.0.0', '<')) {
        $params['body'] = $params['body']['query'];
      }
      $this->elasticsearchClient
        ->deleteByQuery($params);
    }
  }
  else {
    $this
      ->deleteItemsIds($ids, $index);
  }
}