# Getting Elasticsearch exception while indexing using Python script

**URL:** <https://discuss.elastic.co/t/getting-elasticsearch-exception-while-indexing-using-python-script/276299>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 17, 2021, 6:17pm UTC](https://discuss.elastic.co/t/getting-elasticsearch-exception-while-indexing-using-python-script/276299 "2021-06-17T18:17:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravi-shanker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravi-shanker/32/87347_2.png) [@ravi-shanker](https://discuss.elastic.co/u/ravi-shanker)\
**Post date:** [June 17, 2021, 6:17pm UTC](https://discuss.elastic.co/t/getting-elasticsearch-exception-while-indexing-using-python-script/276299/1 "2021-06-17T18:17:42Z")

</div>

Hello All

I am trying read, parse and index a html file using the below python script.

```auto
from elasticsearch import Elasticsearch 
from bs4 import BeautifulSoup
import glob

es=Elasticsearch([{'host':'ip-address','port':9200}])

def remove_tags(html):

        # parse html content
        soup = BeautifulSoup(html, "html.parser")

        for data in soup(['style', 'script']):
                # Remove tags
                data.decompose()

        # return data by retrieving the tag content
        return ' '.join(soup.stripped_strings)

path = 'path_of_html_file'
files=glob.glob(path)
for file in files:
   fname = open(file, 'r')
   e1 = remove_tags(fname)
   res = es.index(index='ep1',doc_type='employee',id=1,body=e1)

```

While executing the above script on my linux ec2, i am getting below error.

```auto
/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py:208: ElasticsearchWarning: the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template
  warnings.warn(message, category=ElasticsearchWarning)
Traceback (most recent call last):
  File "readMount_Parse_Index.py", line 25, in <module>
    res = es.index(index='ep1',doc_type='emp',id=1,body=e1)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 168, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/ __init__.py", line 411, in index
    body=body,
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 415, in perform_request
    raise e
elasticsearch.exceptions.RequestError: RequestError(400, u'mapper_parsing_exception', u'not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes')

```

Can somebody help me out on this if faced the same issue before.

Thanks!

---

<div class="post-metadata">

**Author:** ![ravi-shanker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravi-shanker/32/87347_2.png) [@ravi-shanker](https://discuss.elastic.co/u/ravi-shanker)\
**Post date:** [June 21, 2021, 7:19am UTC](https://discuss.elastic.co/t/getting-elasticsearch-exception-while-indexing-using-python-script/276299/2 "2021-06-21T07:19:40Z")

</div>

@Badger Hello Badger could you please help me on this issue.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 21, 2021, 8:35am UTC](https://discuss.elastic.co/t/getting-elasticsearch-exception-while-indexing-using-python-script/276299/3 "2021-06-21T08:35:20Z")

</div>

please refrain from pinging people directly (and then also over the weekend). This is a community forum and folks will chime in to help if there is a good reproducible use-case 🙂

It looks to me as if you are not creating a JSON object to be indexed into Elasticsearch but try to send raw text data. You need to send JSON to Elasticsearch.

---

<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:** [July 19, 2021, 8:35am UTC](https://discuss.elastic.co/t/getting-elasticsearch-exception-while-indexing-using-python-script/276299/4 "2021-07-19T08:35:28Z")

</div>

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