How do I exclude a bunch of nodes from being indexed by Solr? I want to remove unused nodes from indexing in solr and also I need to make sure that they are not indexed again. I will fetch the list of the unused node IDs using a query.

If any of the nodes is getting updated, then I need to index that node again.

How can I achieve this?
For d7 you are looking for the hook: hook_apachesolr_exclude

Example from the apachesolr.api.php

/**
 * This is the place to look for the replacement to hook_apachesolr_node_exclude
 * You should define a replacement for the status callback and return
 * FALSE for entities which you do not want to appear in the index and TRUE for
 * those that you want to include
 */

/**
 * This is invoked for each entity that is being inspected to be added to the
 * index. if any module returns TRUE, the entity is skipped for indexing.
 *
 * @param integer $entity_id
 * @param string $entity_type
 * @param integer $row
 *   A complete set of data from the indexing table.
 * @param string $env_id
 * @return boolean
 */
function hook_apachesolr_exclude($entity_id, $entity_type, $row, $env_id) {
  // Never index media entities to core_1
  if ($entity_type == 'media' &amp;&amp; $env_id == 'core_1') {
    return TRUE;
  }
  return FALSE;
}


See here: http://drupalcontrib.org/api/drupal/contributions%21apachesolr%21apachesolr.api.php/7

UPDATE

For deleting certain nodes (entities) you can use apachesolr_remove_entity.