Solution on how to force re-index your Search API index application

The following codes below will just force to queue the node to your Search API index application batch process. But the actual index execution will not run yet and this depends on how often your cron runs.

  
// Clear field cache for the node.
cache_clear_all('field:node:' . $node->nid, 'cache_field');

// Reindex the node.
search_api_track_item_change('node', array($node->nid));
  

If you need to force index your Search API index application, you can use the codes below:

  
// Load the index application
$index = search_api_index_load('machine_name_of_your_index_application');

// Re-index now.
search_api_index_items($index);
  

Note: the "machine_name_of_your_index_application" can be found by going to the "View" tab of your index application and its URL should contain this (Eg. if the URL is http://www.yoursite.com/admin/config/search/search_api/index/myapp_index, the machine name of your index application is myapp_index.)

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.