More error information is needed when using pandas_to_eland()
- Dominant language
- Python
- Stars
- 693
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
When uploading a `pandas.DataFrame()` that contains values of different types to elastic with `eland.pandas_to_eland()`, it returns a BulkIndexError without specifying why and where.
**Reproduction:**
1. Install requirements:
```pip install elasticsearch eland pandas ```
2. Imports:
```
from elasticsearch import Elasticsearch
import eland as ed
import pandas as pd
```
3. Connect to Elasticsearch:
```
client = Elasticsearch(HOST, timeout=120)
```
4. Create vector dataframes:
```
pd_df = pd.DataFrame([[True, 'foo'], ['bar', 'baz']], columns=['A', 'B'])
```
- Note that column A will contain two different types: a boolean `True` and a text `bar`.
5. Upload dataframe:
```
ed.pandas_to_eland(
pd_df=pd_df,
es_client=client,
es_dest_index='test',
es_if_exists="replace",
es_refresh=True,
es_type_overrides={
"A": {
"type": "boolean"
},
"B": {
"type": "text"
}
},
)
```
6. Error:
```
---------------------------------------------------------------------------
BulkIndexError Traceback (most recent call last)
[](https://localhost:8080/#) in ()
1 # upload to elasticsearch
----> 2 statista_updated = ed.pandas_to_eland(
3 pd_df=to_upload,
4 es_client=client,
5 es_dest_index='test-statistics',
6 frames
[/usr/local/lib/python3.10/dist-packages/elasticsearch/helpers/actions.py](https://localhost:8080/#) in _process_bulk_chunk_success(resp, bulk_data, ignore_status, raise_on_error)
272
273 if errors:
--> 274 raise BulkIndexError(f"{len(errors)} document(s) failed to index.", errors)
275
276
BulkIndexError: 1 document(s) failed to index.
```
- The error `BulkIndexError: 1 document(s) failed to index.` lacks description of which documents failed to index and why. In datasets with many rows and columns (100k+), it is difficult to pinpoint the issue in order to fix it.
**Possible Cause:**
[Dequeue is currently used](https://github.com/elastic/eland/blob/aaec995b1bee3b74ef5e287253b71fd4ec457197/eland/etl.py#L215-L225) to perform bulk upload, which is preventing it from collecting error information on fails. [To retrieve error information](https://elasticsearch-py.readthedocs.io/en/stable/helpers.html), `for success, info in parallel_bulk(...):` is beneficial.
**Further Benefits:**
By enabling description on errors, all other errors that are not type mismatches will be displayed too. This will help users understand what the problem is and where it is coming from.
Contributor guide
Research direction
Start in eland/etl.py at lines 215-225, then read the Elasticsearch helpers documentation for parallel_bulk and compare it with the current dequeue-based upload. Reproduce the mixed-type DataFrame failure and verify that pandas_to_eland reports which documents failed and why, including the example type mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elasticsearch, pandas, python
- Domain
- data-engineering, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100