ES 5.0父子类型索引重索引至ES 6.2 Join类型时子文档报错求助
Hey there! Let’s tackle this reindexing issue from ES 5.0 parent-child document types to ES 6.2’s join field. I’ve run into this exact problem before, so let’s break down what’s going wrong and how to fix it.
Common Causes for the Mapper Parsing Error
Your parent documents are indexing fine, which means your join mapping is set up correctly for parents. The issue with child documents almost always boils down to one of these two things:
- Incorrect structure for the join field in child documents
- Missing or mismatched routing (child docs must live on the same shard as their parent)
Step 1: Double-Check Your Join Mapping
First, confirm your new index (index_two) has a valid join mapping. It should look something like this (replace parent_type and child_type with your actual 5.x parent/child type names):
PUT /index_two { "mappings": { "_doc": { "properties": { "my_join_field": { "type": "join", "relations": { "parent_type": "child_type" } } // Add your other document fields here } } } }
Step 2: Fix the Reindex Request for Child Documents
The core problem is that your child documents from ES 5.x don’t have the required join field structure, and they might not be using the correct routing. Use the _reindex API with a script to fix both issues:
POST _reindex { "source": { "index": "your_old_5x_index", "type": "child_type" // Match your original 5.x child document type }, "dest": { "index": "index_two", "routing": "{{_source.parent}}" // Critical: Ensures child lives on the same shard as parent }, "script": { "source": """ // Add the join field with child relation and parent ID ctx._source.my_join_field = { "name": "child_type", "parent": ctx._source.parent // Use ctx._parent if your 5.x child docs used the _parent meta-field }; // Optional: Remove the old parent field if you don't need it anymore // ctx._source.remove("parent"); """ } }
Key Notes for This Request:
- Routing: The
routingparameter in thedestsection must be set to the parent document’s ID. This guarantees the child document lands on the same shard as its parent (a requirement for join fields). - Join Field Structure: Child documents need explicit
name(the child relation) andparent(the parent document’s ID) in the join field. This replaces the separate type structure from ES 5.x.
Step 3: Test with a Manual Child Document
If the reindex still fails, test with a manual child document to rule out mapping issues:
PUT /index_two/_doc/test_child_id?routing=test_parent_id { "my_join_field": { "name": "child_type", "parent": "test_parent_id" }, "your_field": "test content" }
If this works, your mapping is correct—go back to check your reindex script for typos (like mismatched relation names or parent ID references).
Troubleshooting Further
If you still get errors, look at the full caused_by section of the error response. Common specific issues include:
parent id [XXX] not found: The parent document hasn’t been indexed yet, or you used the wrong parent ID.routing is required for join field: You forgot to set the routing parameter in the reindex request.
内容的提问来源于stack exchange,提问作者shivg

