elastic / elastic/elasticsearch-php
Throw an exception on unsuccessful bulk operations
- Dominant language
- PHP
- Stars
- 5.3k
- Forks
- 963
- PR merge metrics
- No merged PRs in 30d
Description
### 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html#bulk-api-response-body).
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:
```json
{
"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"
}
}
}
}
}
]
}
```
Contributor guide
Assessment
This issue has not been assessed yet.