0

I'm experiencing some unexpected behavior of cron. I have used search_api module, that should index all nodes. Automatic cron is set to 1 hour. So after every hour, cron will run automatically.

So, the issue is, I created node, and search its content, it is not searchable.

I ran cron, then searched again, still its not searchable.

After 2-3 times hitting cron manually, the content becomes searchable.

Although, for 1-2 content types, content will become searchable after hitting cron for the first time.

I have total 4 content types, and 100 nodes in my whole site.

Forcefully running cron after 3-4 times, make nodes content searchable, else my nodes are not searchable.

Is it the known issue of Drupal core or what would be the problem, I'm not able to figure out as why nodes are not getting indexed automatically? Even after cron run for Ist time, nodes not get indexed.

Any help is really appreciated.

Module used: Search_api (version = 8.x-1.5)

Note: I can't used updated version of search_api as of now, because my current version of Drupal is 8.3.6, and latest release of search_api module is not compatible with this older Drupal version.

EDIT I have written a custom cron too, to run cron after node gets created, but this is also not solving this late cron run issue.

function mymodule_cron() {
  $nids = \Drupal::entityQuery('node')
    ->condition('created', array(time()-3600, time()), 'BETWEEN')
    ->execute();
  // Load all the nodes.
  $nodes = Node::loadMultiple($nids);
  foreach ($nodes as $node) {
    $node->save();
  }
}

enter image description here

8
  • Have you got delayed indexing turned on on search api? Commented Jul 30, 2018 at 9:42
  • yes, even manual hitting of cron does not index nodes. There are only 100 nodes, seems like cron gets broken in between and only some nodes get indexed after forcefully running cron. Commented Jul 30, 2018 at 9:45
  • You should not be indexing all nodes in cron, only those that have been updated since the last index run. What type of search api index is this? Database or Solr? Commented Jul 30, 2018 at 9:52
  • database search index Commented Jul 30, 2018 at 9:54
  • In that case there's no reason not to index immediately rather than have delayed indexing. As regards your cron issue there might be some other module causing the problem. If you install Elysia Cron you can invoke cron hooks individually and that might help understand the issue. Commented Jul 30, 2018 at 10:00

1 Answer 1

0

To turn off delayed indexing, navigate to the /admin/config/search/search-api page then click on the 'edit' button for the index.

On that page, at the very bottom, just above the Save button, there is a collapsed panel titled 'INDEX OPTIONS'. Open the panel and it should look like this.

index options panel

This is where you can control whether indexing is immediate and the cron batch size.

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.