我试图使用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")
我想我需要事先告诉我有父母的事。但是,我不想要的是将两者的所有字段都映射起来。
非常欢迎任何帮助!
答案 0 :(得分:0)
创建mydocs
索引时,在childx
映射类型的定义中,您需要指定值为_parent
的{{1}}字段:
fatherdoc