Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an exception on unsuccessful bulk operations #1123

Open
babenkoivan opened this issue Mar 30, 2021 · 3 comments
Open

Throw an exception on unsuccessful bulk operations #1123

babenkoivan opened this issue Mar 30, 2021 · 3 comments

Comments

@babenkoivan
Copy link

Summary of problem or feature request

Bulk API returns 200 status code even in case some operations have failed, but the response body contains a flag (errors=false), which can be used to identify the overall request result. See more details in the official ES documentation.

This is very inconvenient to parse the response in every project and check if there were errors or not. It would be really nice to get some generic exception when one or more operations did not complete successfully. It can be configurable if this matters.

Code snippet of problem

Here is an example of unsuccessful bulk indexing:

{
   "took":1,
   "errors":true,
   "items":[
      {
         "index":{
            "_index":"books",
            "_type":"_doc",
            "_id":"2",
            "status":400,
            "error":{
               "type":"mapper_parsing_exception",
               "reason":"failed to parse field [published] of type [date] in document with id '2'. Preview of field's value: '2020'",
               "caused_by":{
                  "type":"illegal_argument_exception",
                  "reason":"failed to parse date field [2020] with format [yyyy-MM-dd]",
                  "caused_by":{
                     "type":"date_time_parse_exception",
                     "reason":"Text '2020' could not be parsed at index 4"
                  }
               }
            }
         }
      }
   ]
}
@ezimuel
Copy link
Contributor

ezimuel commented Apr 13, 2021

@babenkoivan Thanks for your feedback. I think this is a good idea but I need to find a nice way to prevent BC break. Maybe, as you suggested this can be an option, disabled by default.

@patriziotomato
Copy link

Hope this is fixed soon as not throwing an error results in a debugging hell. Thanks!

@dkarlovi
Copy link

Something like

namespace Elasticsearch\Next;

/**
 * @deprecated To be removed in 8.0
 */
class Client extends \Elasticsearch\Client
{
    public function bulk($body) {
        $response = parent::bulk($body);

        if ($response['errors']) {
            throw BulkException::fromResponse($response);
        }

        return $response;
    }
}

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

No branches or pull requests

4 participants