在elasticsearch-dsl-py

时间:2016-11-07 11:50:34

标签: python elasticsearch parent-child jsonlines

我试图使用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")

我想我需要事先告诉我有父母的事。但是,我不想要的是将两者的所有字段都映射起来。

非常欢迎任何帮助!

1 个答案:

答案 0 :(得分:0)

创建mydocs索引时,在childx映射类型的定义中,您需要指定值为_parent的{​​{1}}字段:

fatherdoc