Skip to content

Commit 90a50cd

Browse files
committed
Merge pull request #95 from marbleman/patch-1
Update README.md with Parent/Child howto
2 parents 2689591 + c1a3122 commit 90a50cd

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
@@ -324,6 +324,37 @@ or
324324

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

327+
# Handing Parent/Child documents
328+
329+
## Exporting
330+
331+
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:
332+
333+
curl -XPOST 'localhost:9200/myIndex/myParentDocs/_export?path=/tmp/myIndex_myParentDocs.zip'
334+
335+
When exporting the type containing the child documents, include the "_parent" meta field
336+
337+
curl -XPOST 'localhost:9200/myIndex/myChildDocs/_export?path=/tmp/myIndex_myChildDocs.zip'' -d '{
338+
"query" : {
339+
"match_all" : {
340+
}
341+
},
342+
"fields" : [ "_parent", "_source" ]
343+
}'
344+
345+
346+
## Importing Parent/Child documents
347+
348+
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:
349+
350+
curl -XPOST 'localhost:9200/myIndex/myParentDocs/_import?path=/tmp/myIndex_myParentDocs.zip&createIndex=false'
351+
352+
Then import the child documents:
353+
354+
curl -XPOST 'localhost:9200/myIndex/myChildDocs/_import?path=/tmp/myIndex_myChildDocs.zip&createIndex=false'
355+
356+
Repeat this for all your child types.
357+
327358
# Java API
328359

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

0 commit comments

Comments
 (0)