Fixed problem of search index stucked with EntityMalformedException

Drupal 7 comes with internal search function to list out all content based on keywords or phrase out of the box. Drupal will conduct a frequent indexing of words in body content during cron running.

However this process maybe or have tendency to stuck at certain percentage due to migration from major Drupal version, slow or interruption of connection during posting new content or database corrupted.

Usually error found in Logs:

Notice: Trying to get property of non-object in _node_index_node() (line 2632 of /home/public_html/modules/node/node.module).

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7405 of /home/public_html/includes/

Notice: Undefined property: stdClass::$type in _node_extract_type() (line 370 of /home/public_html/modules/node/node.module).

The root of cause you will getting EntityMalformedException is because in Drupal 7 all content must have at least one node revision. To check either the data in search index was corrupted or not, just run these script in your phpMyAdmin.

SELECT n.nid FROM node n LEFT JOIN search_dataset d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC LIMIT 0,1;

Result return as nid number, which either you need to recheck for that node or just delete it.

Sometimes only one node which cause this search index halted. Or you can just run these SQL to detect either all nodes has revision ID.

SELECT nid FROM node WHERE nid NOT IN (SELECT nid FROM node_revision);

If results shows multiple nid, means a lot of "bad" node that need to be clean up. It can be re-edit each one of nodes or either you can directly delete all of them through database.

After that, run cron and check either there is an increase percentage of search index progress.

However, please make sure you do a backup before doing anything to database structure.