# Failed to index dataframe

**URL:** <https://discuss.elastic.co/t/failed-to-index-dataframe/324944>\
**Category:** Elasticsearch\
**Created:** [February 7, 2023, 11:25pm UTC](https://discuss.elastic.co/t/failed-to-index-dataframe/324944 "2023-02-07T23:25:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OnTheRoad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ontheroad/32/116933_2.png) [@OnTheRoad](https://discuss.elastic.co/u/OnTheRoad)\
**Post date:** [February 7, 2023, 11:25pm UTC](https://discuss.elastic.co/t/failed-to-index-dataframe/324944/1 "2023-02-07T23:25:10Z")

</div>

Hello everyone,

I'm starting using ES and I'm really having trouble to index a dataframe.

dataframe looks like :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/3/537ada4fd1a915937db46335bc171b9a04f7de91.png)

So far I wrote the following code :

`es_client = Elasticsearch(hosts = "http://xxx.xxx.xxx.xxx:9200", basic_auth=("user", "pass") ,request_timeout=60)`

```auto
def create_bulked_data(df, index_name):
    bulk_data = []
    for r, row in df.iterrows():
        try:
            data_dict = {
                '_index': index_name,
                '_id': row['_id'],
                '_source': row
            }
            bulk_data.append(data_dict)
        except Exception as e:
            print(e)
    return bulk_data

def push_data(client,bulk,index_name):
    helpers.bulk(client=client, actions=bulk)
    client.indices.refresh()
    client.count(index=index_name)

```

So when I try this:

`data_to_push = create_bulked_data(df,"test_indexing")`

`push_data(es_client,data_to_push,"test_indexing")`

I have the following error message:

```auto
>>> data_to_push = create_bulked_data(df,"test_indexing")
>>> push_data(es_client,data_to_push,"test_indexing")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in push_data
  File "C:\[user]\AppData\Local\Programs\Python\Python39\lib\site-packages\elasticsearch\helpers\actions.py", line 524, in bulk
    for ok, item in streaming_bulk(
  File "C:\[user]\AppData\Local\Programs\Python\Python39\lib\site-packages\elasticsearch\helpers\actions.py", line 438, in streaming_bulk
    for data, (ok, info) in zip(
  File "C:\[user]\AppData\Local\Programs\Python\Python39\lib\site-packages\elasticsearch\helpers\actions.py", line 355, in _process_bulk_chunk
    yield from gen
  File "C:[user]\AppData\Local\Programs\Python\Python39\lib\site-packages\elasticsearch\helpers\actions.py", line 274, in _process_bulk_chunk_success
    raise BulkIndexError(f"{len(errors)} document(s) failed to index.", errors)
elasticsearch.helpers.BulkIndexError: 10 document(s) failed to index.

```

data\_to\_push looks like:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b28c7b84fef5b74c1b61c5dced47f64041ebeba3.png)

Anyone can help please ?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 7, 2023, 11:29pm UTC](https://discuss.elastic.co/t/failed-to-index-dataframe/324944/2 "2023-02-07T23:29:25Z")

</div>

Welcome to our community! 😃

Please don't post pictures of text, logs or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 7, 2023, 11:29pm UTC](https://discuss.elastic.co/t/failed-to-index-dataframe/324944/3 "2023-03-07T23:29:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
