One problem of dynamic mapping "parent-child"

Hi;

The situation here is that I was trying to map some types into "parent-child" relationship.

When I use this command below, it works fine::slight_smile:

curl -XPOST 'http://localhost:9200/grandchildren' -d '{
              "mappings" : {
                "parent" : {
                  "properties" : {
                    "parent-name" : {
                      "type" : "string"
                    }
                  }
                },
                "child" : {
                  "_parent" : {
                    "type" : "parent"
                  },
                  "_routing" : {
                    "required" : true
                  },
                  "properties" : {
                    "child-name" : {
                      "type" : "string"
                    }
                  }
                },
                "child2" : {
                  "_parent" : {
                    "type" : "parent"
                  },
                  "_routing" : {
                    "required" : true
                  },
                  "properties" : {
                    "child2-name" : {
                      "type" : "string"
                    }
                  }
                }
              }
            }'

However, when I build the "parent" first, and then the "child", this cannot be done::disappointed:

curl -XPUT 'http://localhost:9200/grandchildren/parent/_mapping' -d '{
       "parent" : {
          "properties" : {
            "parent-name" : {
              "type" : "string"
            }
          }
        }
    }'
curl -XPUT 'http://localhost:9200/grandchildren/child/_mapping' -d '{
      "child": {
        "_parent": {
          "type": "parent"
        },
        "_routing": {
          "required": true
        },
        "properties": {
          "child-name": {
            "type": "string"
          }
        }
      }
    }'

curl -XPUT 'http://localhost:9200/grandchildren/child2/_mapping' -d '{
  "child2": {
    "_parent": {
      "type": "parent"
    },
    "_routing": {
      "required": true
    },
    "properties": {
      "child2-name": {
        "type": "string"
      }
    }
  }
}'

Cause I believe that in some situations there would be a need of adding a "child" type after I set up a "parent-child" relationship of some types.

Of course I saw that in ES guide it said "Parent and child documents must be indexed on the same shard.", which means they should first appear in the mapping sentence all together. But I searched on the internet, knowing some company can add new "child" after the "parent-child" is already build. I don't know if they are bluffing.:dizzy_face:.I guess the best way to find out is to ask question on ES forum.

**_

Hi, guys, when I create an index with only one shard, the "parent" and "child" can be created independently, half successful. But the data is huge, the efficiency of "one shard" index is quite low. Is there a way to sovle this problem?

_**

It would be great if someone can help me out!

Cheers,

Feiran

I find some information may help you:
Parent-child restrictionsedit
The parent and child types must be different — parent-child relationships cannot be established between documents of the same type.
The _parent.type setting can only point to a type that doesn’t exist yet. This means that a type cannot become a parent type after it is has been created.
Parent and child documents must be indexed on the same shard. The parent ID is used as the routing value for the child, to ensure that the child is indexed on the same shard as the parent. This means that the same parent value needs to be provided when getting, deleting, or updating a child document.

https://www.elastic.co/guide/en/elasticsearch/reference/2.3/mapping-parent-field.html

Thank you very much, do you mean the “parent” type contain all the value in "child", so ES cannot add a new "child" since the "parent" does not have the value of new "child"?

oh, I'm a beginner.it's my first time to learn about the parent-child.

I see you set the same type within parent and child but the information say 'no'.
Also, the parent type can only point to a type that doesn't exist yet.
may be the 'type' setting? May be someone else can find the answer...

I am a beginner as well, so much to learn.
My "parent" and "child" are different types for sure.
In the text, ES said a type cannot become a "parent" after it is created, I guess it means after you created it not as a "parent", but in my case, I created the "parent" as a "parent".