# Raise bulkindexerror

**URL:** https://discuss.elastic.co/t/raise-bulkindexerror/291546
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [December 12, 2021, 2:19pm UTC](https://discuss.elastic.co/t/raise-bulkindexerror/291546 "2021-12-12T14:19:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![FUNZAR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/funzar/32/98772_2.png) [@FUNZAR](https://discuss.elastic.co/u/FUNZAR)
#### Post date: [December 12, 2021, 2:19pm UTC](https://discuss.elastic.co/t/raise-bulkindexerror/291546/1 "2021-12-12T14:19:44Z")

</div>

Hello everyone!

Need a help here. Here is my code:

```auto
import json
import os

from elasticsearch import Elasticsearch, RequestError
from elasticsearch.helpers import bulk

def create_index(es_client, index_name, settings):
   try:
      es_client.indices.create(index_name, body=settings)
      print("Index created")
      return True
   except Exception as err:
      if err.args[1] == "resource_already_exists_exception":
         print("Index already exists")
         return True

   return False

def upload(index_name, data):
   for i, item in enumerate( data,1):
      print(f"item {i} from {len(data)} in process...")
      yield {
         "_index": index_name,
         "_source": item
      }

if __name__ == ' __main__':
   folder = "Python"
   ALL_DATA = []
   for file in os.listdir(folder):
      filepath = os.path.join(folder,file)
      if filepath.endswith(".json"):
         with open(filepath, "r", encoding="utf-8") as f_in:
            data = json.load(f_in)
            ALL_DATA += data

   es = Elasticsearch()

   with open("mapping.json", "r", encoding="utf-8") as f_in:
      settings = json.load(f_in)

   index_name = "data_test"
   if create_index (es, index_name, settings):
      bulk(es, upload(index_name, data))

```

This code seems to run into a trouble. It gives me "raise bulkindexerror( i document(s) failed to index. len(errors) errors)" error, and it won't upload more than 6 documents. What should I fix in this code for it to work?

 ![1](https://us1.discourse-cdn.com/elastic/original/3X/2/e/2e29ad0b5a73e6113951c42e3e0e43da13714326.png)

---

<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: [January 9, 2022, 2:19pm UTC](https://discuss.elastic.co/t/raise-bulkindexerror/291546/2 "2022-01-09T14:19:52Z")

</div>

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