Problem/Motivation

When I first setup Elasticsearch using this module, I ran into an error while indexing. When I checked the log, all I saw was this:

Drupal\search_api\SearchApiException while trying to index items on index Paragraphs Index: An error occurred during indexing. Check your watchdog for more information. in Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend->indexItems() (line 508 of /app/web/modules/contrib/elasticsearch_connector/src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php)

I didn't see any other, more specific information about the error in the log, which this error seems to elude to. Enabling the debugger, and dropping a breakpoint in the spot of the thrown exception allowed me to see what was happening. The error I was receiving:

status: 403
type: cluster_block_exception
reasion: blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];

However, the error itself is not logged unless the code == '400':

$item['index']['status'] == '400'

So these 403 errors don't get logged, because '400' != 403. Obviously there is some misconfiguration in my local Elasticsearch server. But the motivation for this issue is to provide more helpful debugging information up front.

I will also point out that this status code value appears to be an integer, and not a string as it's compared to.

Proposed resolution

I suggest we cast the status code to a string, and compare whether the status code is within the 400 (or 500?) range.

Comments

bburg created an issue. See original summary.

bburg’s picture

Status: Active » Needs review
StatusFileSize
new968 bytes

Starting with head, 8.x-7.x branch patch.

8.x-6.x patch coming.

bburg’s picture

bburg’s picture

For some reason, these patch files aren't lining up with the versions I thought they were for...

Nevermind, I was trying to patch an already patched file. Should be good to go.

sokru’s picture

Version: 8.x-6.0-alpha3 » 8.x-7.x-dev
Status: Needs review » Reviewed & tested by the community

Will add this to next release.

sokru’s picture

I'll add '%caused_by' => $item['index']['error']['caused_by']['reason'] ?? '', on commit stage.

  • sokru committed f105c56d on 8.x-7.x authored by bburg
    Issue #3176523 by bburg, sokru: Response errors with codes other than "...
sokru’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @bburg, not sure how come I was not able to commit to 8.x-6.x branch, and I have no intentions to maintain deprecated version. But if I are willing to open a merge request for 8.x-6.x I'm happy to merge it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.