Skip to content

Commit d5a6105

Browse files
committed
2 parents 719db9f + 90a50cd commit d5a6105

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,37 @@ or
325325

326326
curl -XPOST 'localhost:9200/_import/abort'
327327

328+
# Handing Parent/Child documents
329+
330+
## Exporting
331+
332+
Handling dependant documents is bit tricky since indexing a child document requires the presence of its parent document. A simple approach is to export the documents into seperate archives by using a query. In case your child documents are located in the same type as the parent documents, define the appropriate filter in the query. If you have stored the child documents in a seperate type, you can export the type containing the parent documents like this:
333+
334+
curl -XPOST 'localhost:9200/myIndex/myParentDocs/_export?path=/tmp/myIndex_myParentDocs.zip'
335+
336+
When exporting the type containing the child documents, include the "_parent" meta field
337+
338+
curl -XPOST 'localhost:9200/myIndex/myChildDocs/_export?path=/tmp/myIndex_myChildDocs.zip'' -d '{
339+
"query" : {
340+
"match_all" : {
341+
}
342+
},
343+
"fields" : [ "_parent", "_source" ]
344+
}'
345+
346+
347+
## Importing Parent/Child documents
348+
349+
Before you import the parent documents, you have to create the index manually first: Each type export only contains the mapping of that spedific type and you cannot add a dependant mapping in a second step later. All dependant mappings must be created at the same time otherwise you'll get an error like "java.lang.IllegalArgumentException: Can't specify parent if no parent field has been configured". After creating the index, import the parent documents:
350+
351+
curl -XPOST 'localhost:9200/myIndex/myParentDocs/_import?path=/tmp/myIndex_myParentDocs.zip&createIndex=false'
352+
353+
Then import the child documents:
354+
355+
curl -XPOST 'localhost:9200/myIndex/myChildDocs/_import?path=/tmp/myIndex_myChildDocs.zip&createIndex=false'
356+
357+
Repeat this for all your child types.
358+
328359
# Java API
329360

330361
Knapsack implements all actions as Java transport actions in ELasticsearch.

0 commit comments

Comments
 (0)