# How to define content type

**URL:** <https://discuss.elastic.co/t/how-to-define-content-type/111897>\
**Category:** Elasticsearch\
**Created:** [December 15, 2017, 3:57am UTC](https://discuss.elastic.co/t/how-to-define-content-type/111897 "2017-12-15T03:57:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rokshirs](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rokshirs](https://discuss.elastic.co/u/rokshirs)\
**Post date:** [December 15, 2017, 3:57am UTC](https://discuss.elastic.co/t/how-to-define-content-type/111897/1 "2017-12-15T03:57:33Z")

</div>

Hello !  
Greetings !

We are newbies in the Elasticsearch and we are currently fumbling over the following issue.

Objective : We are trying to fetch the json formatted files from a particular website and then use Elasticsearch to store and later search these files. These files will be dynamically generated with a fixed frequency. We have a Python script to call the files from the desired web site.

Issue: as we need the called files in the json files , we are trying to define the content Type in the python script but we are unable to do so.  
Following is the code in Pythn , could you please give us some feedback on how to define the content type here ?

import elasticsearch  
import simplejson as json  
import requests  
from elasticsearch import helpers  
from bs4 import BeautifulSoup  
import pandas as pd  
from stringify import stringify\_py

es = elasticsearch.Elasticsearch([{'host':'127.0.0.1', 'port':9200}])  
res = requests.get('[http://127.0.0.1:9200](http://127.0.0.1:9200)')  
print(res.content)

r = requests.get("[https://coinmarketcap.com/currencies/ripple/#markets](https://coinmarketcap.com/currencies/ripple/#markets)")

soup = BeautifulSoup(r.content, "lxml")  
table = soup.find\_all('table')[0]  
df = pd.read\_html(str(table))  
data = df[0].to\_json(orient = 'records')

es.index(index='test', doc\_type='people', id=1, body=data)

Thanks ,  
Rohit

---

<div class="post-metadata">

**Author:** ![mujtabahussain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mujtabahussain/32/17514_2.png) [@mujtabahussain](https://discuss.elastic.co/u/mujtabahussain)\
**Post date:** [December 15, 2017, 5:27am UTC](https://discuss.elastic.co/t/how-to-define-content-type/111897/2 "2017-12-15T05:27:26Z")

</div>

> [@](#):
>
> define the content type here ?

Do you mean when you call the remote website for the JSON files or when you index said JSON into ES? For the former, you will have to look up the docs for `requests` module I assume.

For the latter, what does the ES python SDK doc tell you?

---

<div class="post-metadata">

**Author:** ![rokshirs](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rokshirs](https://discuss.elastic.co/u/rokshirs)\
**Post date:** [December 22, 2017, 3:15am UTC](https://discuss.elastic.co/t/how-to-define-content-type/111897/3 "2017-12-22T03:15:55Z")

</div>

Hello,  
Thank you for the response.

I would like to elaborate the exact error we are getting , this is occurring while indexing the JSON file.  
Please refer the following which has a error message.

It would be a great help to us , if you can provide input here.

Error

b'{\n "name" : "b9as1yU",\n "cluster\_name" : "elasticsearch",\n "cluster\_uuid" : "5KaX8y0NSAKKUrukl4PF0w",\n "version" : {\n "number" : "6.0.1",\n "build\_hash" : "601be4a",\n "build\_date" : "2017-12-04T09:29:09.525Z",\n "build\_snapshot" : false,\n "lucene\_version" : "7.0.1",\n "minimum\_wire\_compatibility\_version" : "5.6.0",\n "minimum\_index\_compatibility\_version" : "5.0.0"\n },\n "tagline" : "You Know, for Search"\n}\n'

PUT /test/people/1 [status:406 request:0.013s]  
Traceback (most recent call last):  
File "C:\Users\吳倫彰\Desktop\BlockChain Partners internship\Project 2\EStest.py", line 73, in   
es.index(index='test', doc\_type='people', id=1, body=data)  
File "C:\Users\吳倫彰\AppData\Local\Programs\Python\Python36-32\lib\site-packages\elasticsearch\client\utils.py", line 69, in _wrapped  
return func(\*args, params=params, \*\*kwargs)  
File "C:\Users\吳倫彰\AppData\Local\Programs\Python\Python36-32\lib\site-packages\elasticsearch\client\_init_.py", line 263, in index  
\_make\_path(index, doc\_type, id), params=params, body=body)  
File "C:\Users\吳倫彰\AppData\Local\Programs\Python\Python36-32\lib\site-packages\elasticsearch\transport.py", line 307, in perform\_request  
status, headers, data = connection.perform\_request(method, url, params, body, ignore=ignore, timeout=timeout)  
File "C:\Users\吳倫彰\AppData\Local\Programs\Python\Python36-32\lib\site-packages\elasticsearch\connection\http\_urllib3.py", line 93, in perform\_request  
self.\_raise\_error(response.status, raw\_data)  
File "C:\Users\吳倫彰\AppData\Local\Programs\Python\Python36-32\lib\site-packages\elasticsearch\connection\base.py", line 105, in \_raise\_error  
raise HTTP\_EXCEPTIONS.get(status\_code, TransportError)(status\_code, error\_message, additional\_info)  
elasticsearch.exceptions.TransportError: TransportError(406, 'Content-Type header is not supported')

> > >

---

<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 19, 2018, 3:16am UTC](https://discuss.elastic.co/t/how-to-define-content-type/111897/4 "2018-01-19T03:16:06Z")

</div>

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