Elasticsearch: {'error': "BadRequestError(400, 'illegal_argument_exception', '操作/元数据行 [1] 包含未知参数 [_type]')

问题描述 投票:0回答:1

我正在尝试将 csv 文件(有 10 条记录和 8 个参数)中的记录插入到 Elasticsearch 索引中。我收到错误

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

我在下面获得的错误中发现了一个名为“_type”的字段,但不知道如何解决它。

我正在使用 Bulk Helper 进行插入。 此代码会生成错误。

enter image description here

我的 CSV 数据文件 head() 输出:

enter image description here

我的 ELasticSearch 实例信息:

enter image description here

我的实际代码:

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'}}])
    
python elasticsearch elastic-stack elasticsearch-dsl
1个回答
0
投票
您的 ES 版本不再支持

_type
8.12.0
,请在此处查看更多内容。

尝试将其从您的请求中删除:

'_type':'_doc'
© www.soinside.com 2019 - 2024. All rights reserved.