I found the answer on exploring the apache solr module,
STEP 1
Select the nodes from the node table alone or by joining the apachesolr index entities table,
// Check for unpublished content that wasn't deleted from the index. $table = apachesolr_get_indexer_table('node'); // Select the nids from the node table $query = db_select($table, 'aien') ->fields('aien', array('entity_id')) ->condition('n.nid', 0); $query->leftJoin('node', 'n', 'n.nid = aien.entity_id'); $nodes = $query->execute()->fetchAllAssoc('nid');
STEP 2
Chunk it to some limit and call the apachesolr_index_nodeapi_mass_delete function
$node_lists = array_chunk($nodes, '100', TRUE); foreach ($node_lists as $nodes) { watchdog('Apache Solr', 'On cron running apachesolr_nodeapi_mass_delete() on nids @nids', array('@nids' => implode(',', array_keys($nodes))), WATCHDOG_WARNING); if (!apachesolr_index_nodeapi_mass_delete($nodes, $table)) { // Solr query failed - so stop trying. break; } }