We are importing large number of data into our drupal website with custom script and we are using Search api and Search api solr module into our website to index and search large number of data.

When we import data using custom script, Search api solr is not fetching this data and new nodes are not indexing into Solr,

If we update the node, its indexing successfully into solr.

I am trying to adding node programatically into solr but its did not work for us.

search_api_track_item_change($type, array($id));

Can anyone suggest me?

3 Answers 3


Two things first. These two items are purely a suggestion and have no impact on the code samples bellow:

  • You should post the code that saves your nodes. The Solr API module should automatically pick up nodes when you save and update them (the search_api module code runs when you call "node_save"). It is odd that it doesn't for you.
  • You should think about running your solr re-indexing operation after you import all of your data. This will speed up your bulk imports and you can schedule the solr re-index via cron or run it via drush.

The following information comes straight from the search_api module.

These are the pre-conditions for the code examples bellow:

  • You need to run these after you call the node_save function.
  • The $type variable refers to the entity type (node, user, term, etc..). In your case it sounds like $type='node'
  • the $entity variable refers to the node object you're saving. You would pass this object to the node_save($entity) function during the bulk import operation.

If you're inserting nodes:

  list($id) = entity_extract_ids($type, $entity);
  if (isset($id)) {
    search_api_track_item_insert($type, array($id));
    $combined_id = $type . '/' . $id;
    search_api_track_item_insert('multiple', array($combined_id));

If you're updating nodes:

list($id) = entity_extract_ids($type, $entity);
if (isset($id)) {
    search_api_track_item_change($type, array($id));
    $combined_id = $type . '/' . $id;
    search_api_track_item_change('multiple', array($combined_id));

To simply index a single node, you can:

$index = search_api_index_load('default_node_index');
search_api_index_specific_items($index, [$node_nid]);

Find the name of your index by opening Search API index in admin. In my example : /admin/config/search/search_api/index/default_node_index

Keep in mind there's still probably a delay while Solr processes the submission. Then, depending on what you're doing within Drupal, there may be cache flushes required on the Drupal side in order for you to see the results there.

As mentioned in other answers, this could be a pretty intensive operation (after all that's why it's normally done via cron), so use sparingly, possibly in a PHP shutdown function.


I had a similar symptom, even on node update events and solved it by adding this code after your track item change request to Search API

search_api_track_item_change('node', array($node->nid));
$index = search_api_index_load('product');

The ID you have to give as an argument to search_api_index_load can be found by opening your Search API index in admin. In my example : admin/config/search/search_api/index/product

To index new nodes, you might need to add this line in between :


This will pickup all items to reindex, so keep in mind that the reindexing will take more time to complete, and preferably done in batch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.