Elasticsearch-php: Throw an exception on unsuccessful bulk operations

Created on 30 Mar 2021  路  2Comments  路  Source: elastic/elasticsearch-php

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"
                  }
               }
            }
         }
      }
   ]
}
enhancement

Most helpful comment

@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.

All 2 comments

@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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kabudu picture kabudu  路  4Comments

amorphine picture amorphine  路  6Comments

ezimuel picture ezimuel  路  6Comments

thinkspill picture thinkspill  路  3Comments

paulhuisman picture paulhuisman  路  6Comments