首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在elasticsearch-dsl-py中定义父级

在elasticsearch-dsl-py中定义父级
EN

Stack Overflow用户
提问于 2016-11-07 19:50:34
回答 1查看 411关注 0票数 0

我正在尝试使用Elasticsearch-dsl-py来索引包含多个字段的jsonl文件中的一些数据。忽略不太通用的部分,代码看起来像这样:

代码语言:javascript
复制
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)

尝试运行此命令时会出现以下错误:

代码语言:javascript
复制
RequestError: TransportError(400, u'illegal_argument_exception', u"Can't specify parent if no parent field has been configured")

我想我需要提前告诉有父母的es。但是,我不希望只是为了这样做而映射两者的所有字段。

我们非常欢迎您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2016-11-07 19:54:06

创建mydocs索引时,在childx映射类型的定义中,需要使用值fatherdoc指定_parent字段

代码语言:javascript
复制
PUT mydocs
{
  "mappings": {
    "fatherdoc": {
       "properties": {
          ... parent type fields ...
       }
    },
    "childx": {
      "_parent": {                      <---- add this
        "type": "fatherdoc" 
      },
      "properties": {
          ... parent type fields ...
      }
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40464512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档