I am trying to insert records from a csv file(having 10 records and 8 parameters) into an elasticsearch index. I am getting the error

'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]'

I found a field named "_type" in the The Error obtained below, but don't have an IDEA of how to resolve it.

I am using Bulk Helper for inserting. This code generates the error.

enter image description here

My CSV dataFile head() output:

enter image description here

My ELasticSearch Instance info:

enter image description here

My actual Code:

from elasticsearch import Elasticsearch 
from elasticsearch_dsl import Search

ssl_assert_fingerprint_b =""
api_id = 'for_python'
api_key = '=='

client = Elasticsearch(
    "https://192.168.XXX.XXX:9200",
    ssl_assert_fingerprint =ssl_assert_fingerprint_b,
    #ca_certs="/home/albus/elastic/elasticsearch-8.12.0/config/certshttp_ca.crt",
    basic_auth=("elastic", ""),
    #verify_certs=False
)

client.info()
client.ping()

# ### Index test data

import pandas as pd
test_data = pd.read_csv("test_SIP.csv")


test_data.head()
len(test_data)
df2 = test_data.to_dict('records')

df2
len(df2)

def generator(df2):
    for c, line in enumerate(df2):
        yield {
            '_index':'sip3_test',
            '_type':'_doc',
            '_id':line.get('S.No'),
            '_source':{
                'First Name':line.get('First Name',None),
                'Middle Name':line.get('Middle Name',None),
                'Last Name':line.get('Last Name',None),
                'Branch':line.get('Branch',None),
                'Job Title':line.get('Job Title',None),
                'Mobile Number':line.get('Mobile Number',None),
                'SIP Ext Number':line.get('SIP Ext Number',None)
            }
        }

mycustom=generator(df2)
mycustom
next(mycustom)
my = client.indices.create(index='sip3_test',ignore=[400,404])
my

# #### BULK UPLOAD 

from elasticsearch import helpers

try:
    ret = helpers.bulk(client, generator(df2),ignore_status = [400,404])
    print("Working...")
    print("Response: ", ret)
except Exception as e:
    print(e)
    pass


ret

(0,
 [{'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Abhishek',
     'Middle Name': nan,
     'Last Name': 'Poudel',
     'Branch': 'Kailash Mansarovar',
     'Job Title': 'CBS',
     'Mobile Number': 9849725029,
     'SIP Ext Number': 6114},
    '_id': 1,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Rabin',
     'Middle Name': nan,
     'Last Name': 'Subedi',
     'Branch': 'Annapurna Base Camp',
     'Job Title': 'IT',
     'Mobile Number': 9849725030,
     'SIP Ext Number': 6115},
    '_id': 2,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Devendra',
     'Middle Name': nan,
     'Last Name': 'Shrestha',
     'Branch': 'Langtang',
     'Job Title': 'DB',
     'Mobile Number': 9849725031,
     'SIP Ext Number': 6116},
    '_id': 3,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Amogh',
     'Middle Name': 'Ratna',
     'Last Name': 'Manandhar',
     'Branch': 'Shey Phoksundo',
     'Job Title': 'SYSTEM',
     'Mobile Number': 9849725032,
     'SIP Ext Number': 6117},
    '_id': 4,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Pradip',
     'Middle Name': nan,
     'Last Name': 'Dhamala',
     'Branch': 'RARA',
     'Job Title': 'NETWORK',
     'Mobile Number': 9849725033,
     'SIP Ext Number': 6118},
    '_id': 5,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Mohan ',
     'Middle Name': 'Lal',
     'Last Name': 'Guro',
     'Branch': 'Gokyo',
     'Job Title': 'DEVELOPMENT',
     'Mobile Number': 9849725034,
     'SIP Ext Number': 6119},
    '_id': 6,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Madhukar',
     'Middle Name': nan,
     'Last Name': 'Panta',
     'Branch': 'Manasalu',
     'Job Title': 'CARD',
     'Mobile Number': 9849725035,
     'SIP Ext Number': 6120},
    '_id': 7,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Bibek',
     'Middle Name': nan,
     'Last Name': 'Shrestha',
     'Branch': 'Tilicho',
     'Job Title': 'SECURITY',
     'Mobile Number': 9849725036,
     'SIP Ext Number': 6121},
    '_id': 8,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Prajwol',
     'Middle Name': nan,
     'Last Name': 'Maharjan',
     'Branch': 'Dolpa',
     'Job Title': 'RISK MANAGEMENT',
     'Mobile Number': 9849725037,
     'SIP Ext Number': 6122},
    '_id': 9,
    '_index': 'sip3_test',
    '_type': '_doc'}},
  {'index': {'error': "BadRequestError(400, 'illegal_argument_exception', 'Action/metadata line [1] contains an unknown parameter [_type]')",
    'status': 400,
    'exception': BadRequestError('illegal_argument_exception', meta=ApiResponseMeta(status=400, http_version='1.1', headers={'X-elastic-product': 'Elasticsearch', 'content-type': 'application/vnd.elasticsearch+json;compatible-with=8', 'content-length': '261'}, duration=0.0029926300048828125, node=NodeConfig(scheme='https', host='192.168.29.60', port=9200, path_prefix='', headers={'user-agent': 'elasticsearch-py/8.11.1 (Python/3.11.5; elastic-transport/8.11.0)'}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint='1d3901571610be6c109c196ab316843ddefd55eea2bf4756ef176916709c9c3d', ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={})), body={'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}], 'type': 'illegal_argument_exception', 'reason': 'Action/metadata line [1] contains an unknown parameter [_type]'}, 'status': 400}),
    'data': {'First Name': 'Likesh',
     'Middle Name': nan,
     'Last Name': 'Shrestha',
     'Branch': 'Kanchanjunga',
     'Job Title': 'CAOU',
     'Mobile Number': 9849725038,
     'SIP Ext Number': 6123},
    '_id': 10,
    '_index': 'sip3_test',
    '_type': '_doc'}}])
    
1

There are 1 best solutions below

0
D.T On

_type is no longer supported for your version of ES 8.12.0, check it out more here.

Try to remove it from your request:

'_type':'_doc'