Skip to content

Conversation

@vincent-gao
Copy link
Contributor

@vincent-gao vincent-gao commented Dec 9, 2025

Jira

https://digital-vic.atlassian.net/browse/SD-1448

Problem/Motivation

Currently, the indexItems() method operates on an "all-or-nothing" basis. If a single document in a batch fails, the module throws a generic SearchApiException.

  • This causes two significant issues in our projects.
    • The entire batch fails.
    • The thrown exception message is generic ("An error occurred during indexing"). The actual error details returned by the Elasticsearch bulk API (reason, type, caused_by) are not logged, making it difficult to identify the problematic entity.

Fix

Refactor indexItems() to handle the Elasticsearch bulk response more gracefully.

Test and Screenshots

use a hook_search_api_index_items_alter to alter the data, to break the search.

/**
 * Implements hook_search_api_index_items_alter().
 */
function reference_sdp_core_search_api_index_items_alter(\Drupal\search_api\IndexInterface $index, array &$items,) {
  foreach ($items as $item_id => $item) {
    error_log($item_id);
    /** @var \Drupal\search_api\Item\ItemInterface $item */
    if (strpos($item_id, 'node/175:') !== false) {
      if ($field = $item->getField('created')) {
        $field->setValues(['I am not a timestamp, I will break the search.']);
      }
    }
  }
}

check the log
CleanShot 2025-12-09 at 16 43 12

@vincent-gao vincent-gao changed the title [SD-1448] indexing and error logging improvement [SD-1448] Support partial indexing success and improve bulk error logging Dec 9, 2025
@vincent-gao vincent-gao self-assigned this Dec 9, 2025
Copy link
Contributor

@MdNadimHossain MdNadimHossain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful. It will not stop when it finds a error, awesome. Lets test it though before merging it.

Copy link
Contributor

@anthony-malkoun anthony-malkoun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yo @vincent-gao completely fine with this approach. Is it also worth submitting an issue and patching https://git.drupalcode.org/project/elasticsearch_connector/-/blob/8.0.x/src/SearchAPI/BackendClient.php#L99

@vincent-gao
Copy link
Contributor Author

vincent-gao commented Dec 22, 2025

Yo @vincent-gao completely fine with this approach. Is it also worth submitting an issue and patching https://git.drupalcode.org/project/elasticsearch_connector/-/blob/8.0.x/src/SearchAPI/BackendClient.php#L99

hi @anthony-malkoun ! I will submit a patch to Drupalcore and see what their feedback is!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants