# Elasticsearch Python

**URL:** <https://discuss.elastic.co/t/elasticsearch-python/296356>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 5, 2022, 8:42am UTC](https://discuss.elastic.co/t/elasticsearch-python/296356 "2022-02-05T08:42:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harsh19](https://avatars.discourse-cdn.com/v4/letter/h/ed655f/32.png) [@harsh19](https://discuss.elastic.co/u/harsh19)\
**Post date:** [February 5, 2022, 8:42am UTC](https://discuss.elastic.co/t/elasticsearch-python/296356/1 "2022-02-05T08:42:02Z")

</div>

Here is my code,

```auto
from datetime import datetime 
from elasticsearch import Elasticsearch, helpers
from pprint import pprint
import json 
import time 

es = Elasticsearch(['http://localhost:9200'], http_auth=('elastic', 'elastic'))

f = open("json/data.json", "r")
data = json.loads(f.read())
pprint(data)

# Closing file 
f.close()

response = helpers.bulk(
    es,
    data,
    index = "newChannel",
    doc_type = "_doc"
)

print(response)

```

When i Run this code it's give me an error like this --

```auto
le "/home/harsh/.local/lib/python3.6/site-packages/elasticsearch/helpers/actions.py", line 187, in _process_bulk_chunk_success
    raise BulkIndexError("%i document(s) failed to index." % len(errors), errors)
elasticsearch.helpers.errors.BulkIndexError: ('4 document(s) failed to index.', [{'index': {'_index': 'newchannel', '_type': '_doc', '_id': 'nhELyX4BvsLZtjn4MKrv', 'status': 400, 'error': {'type': 'mapper_parsing_exception', 'reason': 'failed to parse', 'caused_by': {'type': 'not_x_content_exception', 'reason': 'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes'}}, 'data': 'took'}}, {'index': {'_index': 'newchannel', '_type': '_doc', '_id': 'nxELyX4BvsLZtjn4MKrv', 'status': 400, 'error': {'type': 'mapper_parsing_exception', 'reason': 'failed to parse', 'caused_by': {'type': 'not_x_content_exception', 'reason': 'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes'}}, 'data': 'timed_out'}}, {'index': {'_index': 'newchannel', '_type': '_doc', '_id': 'oBELyX4BvsLZtjn4MKrv', 'status': 400, 'error': {'type': 'mapper_parsing_exception', 'reason': 'failed to parse', 'caused_by': {'type': 'not_x_content_exception', 'reason': 'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes'}}, 'data': '_shards'}}, {'index': {'_index': 'newchannel', '_type': '_doc', '_id': 'oRELyX4BvsLZtjn4MKrv', 'status': 400, 'error': {'type': 'mapper_parsing_exception', 'reason': 'failed to parse', 'caused_by': {'type': 'not_x_content_exception', 'reason': 'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes'}}, 'data': 'hits'}}])

```

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [February 5, 2022, 10:40am UTC](https://discuss.elastic.co/t/elasticsearch-python/296356/2 "2022-02-05T10:40:26Z")

</div>

The error was caused by that `data` was not formatted appropriately. What does `data` look like?

---

<div class="post-metadata">

**Author:** ![harsh19](https://avatars.discourse-cdn.com/v4/letter/h/ed655f/32.png) [@harsh19](https://discuss.elastic.co/u/harsh19)\
**Post date:** [February 7, 2022, 10:39am UTC](https://discuss.elastic.co/t/elasticsearch-python/296356/3 "2022-02-07T10:39:36Z")

</div>

ok got it @Tomo_M

Data is not in proper form it's Done Now

---

<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, 2022, 10:40am UTC](https://discuss.elastic.co/t/elasticsearch-python/296356/4 "2022-03-07T10:40:02Z")

</div>

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