Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't create document with doc_type Elasticsearch – Python

I’m new to Elastic search
So im trying to create a document with specific ‘doc_type’, but when I pass in doc_type argument, I got this error:

elasticsearch.exceptions.RequestError: RequestError(400, ‘no handler found for uri [/employees/teacher/1] and method [PUT]’, ‘no handler found for uri [/employees/teacher/1] and method [PUT]’)

Does anyone know what is wrong?
My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

es = Elasticsearch(
    ["localhost"], 
    port=9200, 
    connection_class=RequestsHttpConnection, 
    http_auth=("elastic", "elastic"), 
    use_ssl=True, 
    verify_certs=False
)

body = {
    'name': 'John',
    'age': 21
}

# es.indices.create(index = 'employees')

# This line works fine
es.index(index='employees', id = 1, body = body, refresh = 'true' )

# This line caused the error
es.index(index='employees', doc_type='teacher', id = 1, body = body )

>Solution :

Mapping types (aka doc_type) have been deprecated and you should simply use _doc instead or not specify the doc_type parameter at all like you did in the first es.index() statement.

As of release 8.0.0, doc_type has even been removed from the available parameters.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading