You are here

public function SearchApiElasticsearchConnector::deleteItems in Elasticsearch Connector 7

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

Overrides deleteItems().

Overrides SearchApiServiceInterface::deleteItems

File

modules/elasticsearch_connector_search_api/service.inc, line 479
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') {
    $site_id = $this
      ->getSiteHash();
    $params = $this
      ->getIndexParam($index, TRUE);
    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
    $version = $this
      ->getClusterVersion();
    if (version_compare($version, '1.0.0', '<')) {
      $params['body'] = $params['body']['query'];
    }
    $this->elasticsearchClient
      ->deleteByQuery($params);
  }
  else {
    $this
      ->deleteItemsIds($ids, $index);
  }
}