0

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 を事前に伝える必要があると思います。ただし、私が望んでいないのは、両方のすべてのフィールドをマップすることです。

どんな助けでも大歓迎です!

4

1 に答える 1

0

インデックスを作成するときmydocsは、マッピング タイプの定義で、フィールドに値childxを指定する必要があります。_parentfatherdoc

PUT mydocs
{
  "mappings": {
    "fatherdoc": {
       "properties": {
          ... parent type fields ...
       }
    },
    "childx": {
      "_parent": {                      <---- add this
        "type": "fatherdoc" 
      },
      "properties": {
          ... parent type fields ...
      }
    }
  }
}
于 2016-11-07T11:54:05.717 に答える