The apachesolr module's drush command for deleting entities from the index is buggy.
Its documentation states the following commands are valid:

'drush solr-delete-index node' => 'Delete all node content from the index.',
'drush solr-delete-index node:article' => 'Delete all content of the article content type from the index.',
'drush solr-delete-index node:article node:blog' => 'Delete all content of the article and blog content types from the index.',

When the drush command is called with the syntax of the first example it calls

$success = apachesolr_index_delete_index($env_id, $type);

which calls

function apachesolr_index_delete_index($env_id, $entity_type = NULL, $bundle = NULL) {
  if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) {
    watchdog('Apache Solr', 'Trying to update the Solr index while the environment %env_id is read-only in function %function', array('%function' => __FUNCTION__, '%env_id' => $env_id), WATCHDOG_WARNING);
    return FALSE;
  }
  // Instantiate a new Solr object.
  try {
    $solr = apachesolr_get_solr($env_id);
    $query = '*:*';

    if (!empty($entity_type) && !empty($bundle)) {
      $query = "(bundle:$bundle AND entity_type:$entity_type) OR sm_parent_entity_bundle:{$entity_type}-{$bundle}";
    }
    elseif (!empty($bundle)) {
      $query = "(bundle:$bundle)";
    }

    // Allow other modules to modify the delete query.
    // For example, use the site hash so that you only delete this site's
    // content:  $query = 'hash:' . apachesolr_site_hash()
    drupal_alter('apachesolr_delete_by_query', $query);
    $solr->deleteByQuery($query);
    $solr->commit();
<SNIP>

The query isn't altered if only 'entity_type' is provided, causing the whole index to drop.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jon Nunan created an issue. See original summary.

Jon Nunan’s picture

Just adding another condition should do it.

Jon Nunan’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: delete-by-entity-type-2635244-1.patch, failed testing.

Jon Nunan’s picture

Status: Needs work » Needs review

  • Jon Nunan authored 515e596 on 7.x-1.x
    Issue #2635244 by Jon Nunan: Deleting an entity type from the index will...
janusman’s picture

Status: Needs review » Fixed

Fixed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.