Home > Back-end >  Can't create document with doc_type Elasticsearch - Python
Can't create document with doc_type Elasticsearch - Python

Time:10-14

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:

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 )

CodePudding user response:

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.

  • Related