问题:批量索引抛出错误:[classIds]的对象映射尝试将field [null]解析为对象,但找到了具体值
这是我试图发布的JSON:
[{'_type': 'nodelookup', '_id': '248', '_source': {'modifiedOn': datetime.datetime(2013, 8, 28, 2, 44, 5), 'name': u'Big Words for Little People', 'sourceId': '', 'createdOn': datetime.datetime(2011, 8, 26, 16, 0, 49), 'classIds': [463, 10597], 'source': '', 'wikiInfo': {'wikiText': None, 'wikiLink': None}, 'notableInfo': {'source': u'NOTABLE_FOR', 'value': u'Book'}, 'relevance': 113L, 'urlFriendlyName': u'big-words-for-little-people', 'properties': [{'classId': 463, 'properties': [{'name': u'First Published', 'value': u'2008-09-08', 'id': 1411L}, {'name': u'Author', 'value': u'Jamie Lee Curtis', 'id': 1415L}]}, {'classId': 10597}], 'ontologyId': '248'}, '_index': 'nodes_a0f37542-3d66-4c2c-ad8c-5e59d9cdfa97'}]
忽略json中与python相关的额外字符/方法,例如 datetime.datetime(),None etc
尝试发布文档时出现错误响应:
Traceback (most recent call last):
File "node_bulk_import_es.py", line 73, in <module>
helpers.bulk(es, data)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/helpers/__init__.py", line 188, in bulk
for ok, item in streaming_bulk(client, actions, **kwargs):
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/helpers/__init__.py", line 160, in streaming_bulk
for result in _process_bulk_chunk(client, bulk_actions, raise_on_exception, raise_on_error, **kwargs):
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/helpers/__init__.py", line 132, in _process_bulk_chunk
raise BulkIndexError('%i document(s) failed to index.' % len(errors), errors)
elasticsearch.helpers.BulkIndexError: (u'1 document(s) failed to index.', [{u'index': {u'status': 400, u'_type': u'nodelookup', u'_id': u'248', u'error': {u'reason': u'object mapping for [classIds] tried to parse field [null] as object, but found a concrete value', u'type': u'mapper_parsing_exception'}, u'_index': u'nodes_a0f37542-3d66-4c2c-ad8c-5e59d9cdfa97'}}])
我有这个索引的预定义映射,这是我的映射:
{
"nodes_e37a1e17-962d-40fb-bae2-ff20759ab1c6": {
"mappings": {
"nodelookup": {
"properties": {
"classIds": {
"type": "nested"
},
"createdOn": {
"type": "date",
"index": "analyzed",
"format": "strict_date_optional_time||epoch_millis"
},
"modifiedOn": {
"type": "date",
"index": "analyzed",
"format": "strict_date_optional_time||epoch_millis"
},
"name": {
"type": "string",
"index": "not_analyzed",
"fields": {
"nameSimple": {
"type": "string",
"analyzer": "simple"
},
"nameStandard": {
"type": "string",
"analyzer": "standard"
}
}
},
"notableInfo": {
"properties": {
"source": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"ontologyId": {
"type": "integer"
},
"properties": {
"type": "nested"
},
"relevance": {
"type": "integer",
"index": "analyzed"
},
"source": {
"type": "string"
},
"sourceId": {
"type": "string"
},
"urlFriendlyName": {
"type": "string"
},
"wikiInfo": {
"properties": {
"wikiLink": {
"type": "string",
"index": "not_analyzed"
},
"wikiText": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
不确定这里有什么问题,我上周试用时代码运行正常,现在它失败了,请帮我解决问题。
提前致谢!
答案 0 :(得分:0)
classIds
的字段类型应为Integer
,而不是Nested
。
在代码中:
@Field(type = FieldType.Integer)
private List<Integer> classIds;
在ES中:
"classIds": {
"type": "integer"
}
这是因为FieldType
是指List中包含的包含类型。
顺便说一下,我正在使用Java。