我正在尝试使用Elasticsearch-dsl-py来索引包含多个字段的jsonl文件中的一些数据。忽略不太通用的部分,代码看起来像这样:
es = Elasticsearch()
for id,line in enumerate(open(jsonlfile)):
jline = json.loads(line)
children = jline.pop('allChildrenOfTypeX')
res = es.index(index="mydocs", doc_type='fatherdoc', id=id, body=jline)
for ch in children:
res = es.index(index="mydocs", doc_type='childx', parent=id, body=ch)尝试运行此命令时会出现以下错误:
RequestError: TransportError(400, u'illegal_argument_exception', u"Can't specify parent if no parent field has been configured")我想我需要提前告诉有父母的es。但是,我不希望只是为了这样做而映射两者的所有字段。
我们非常欢迎您的帮助!
发布于 2016-11-07 19:54:06
创建mydocs索引时,在childx映射类型的定义中,需要使用值fatherdoc指定_parent字段
PUT mydocs
{
"mappings": {
"fatherdoc": {
"properties": {
... parent type fields ...
}
},
"childx": {
"_parent": { <---- add this
"type": "fatherdoc"
},
"properties": {
... parent type fields ...
}
}
}
}https://stackoverflow.com/questions/40464512
复制相似问题