Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding additional child types referring to the same parent #17956

Closed
martijnvg opened this issue Apr 25, 2016 · 7 comments
Closed

Allow adding additional child types referring to the same parent #17956

martijnvg opened this issue Apr 25, 2016 · 7 comments
Labels
:Search/Search Search-related issues that do not fall into other categories

Comments

@martijnvg
Copy link
Member

Originates from: https://discuss.elastic.co/t/how-to-create-a-child-type-when-its-parent-type-is-already-exist-in-elasticsearch-2-x

In cases when a parent type already has child mappings we can potentially relax the constraint that forbids adding more child type.

The constraint as is today was designed to avoid the following scenario:

PUT /index
{
  "mappings": {
    "parent" : {
    }
  }
}

// some time later:

PUT /index/child1/_mapping
{
  "child1" : {
    "_parent": {
        "type": "parent"
      }  
  }
}

The put mapping call fails with: can't add a _parent field that points to an already existing type
The reason we can't allow is this, is that otherwise for already existing parent docs the ids wouldn't be stored in the doc values join field (which the _paren field controls)

However this constraint also prevents adding additional child types:

PUT /index
{
  "mappings": {
    "parent" : {
    },
    "child1" : {
      "_parent": {
        "type": "parent"
      }
    }
  }
}

PUT /index/child2/_mapping
{
  "child2" : {
    "_parent": {
        "type": "parent"
      }  
  }
}

In this case adding the second child type fails. This is too strict and we can allow this, because for the parent type we already store the ids in the doc values join field.

@navyliu
Copy link

navyliu commented Apr 26, 2016

We real hope this feature can role back to the normal logic of v1.x . In most situation, parent are main object of domain, and children can add relation to parent at anytime .
And this is the biggest obstacle for our updating from v1.6 to v2.3 .

@nishantsaini
Copy link

The parent-child relationship and flexibility of adding child at a later stage was one the key feature for using elasticsearch. This restriction has taken away the advantage as in many cases it is not possible to identify all the possible child types in advance. Hope the restriction is relaxed and allow to add new child type if one child type already exists as explained by @martijnvg

@martijnvg martijnvg removed the discuss label May 19, 2016
martijnvg added a commit that referenced this issue May 19, 2016
…isting parent type

From 2.0 adding child types to existing types was forbidden because the`_parent` field stores the join between parent and child at index time.
This is to protect from the fact that types that weren't a parent before become a parent while previously indexed documents would not have a join field.
 This would break the parent/child queries.

The restriction was a bit too strict in the sense that also if a type was a parent type the restriction would forbid adding child types that point to a parent type (so child points already point to it).
This change make sure that the restriction only applies if that type isn't a parent type already.

Closes #17956
@turp1twin
Copy link

What release will this change be available in? Any chance it will be backported to the 2.3.x branch? Thanks!

@martijnvg
Copy link
Member Author

@turp1twin This will be available in 2.4.0 once it is released. (no scheduled date for this yet). The 2.3 branch is mainly meant for bug fixes and this is a change in behavior, so that is why this won't be back ported to the 2.3 branch.

@turp1twin
Copy link

Thanks @martijnvg! 2.4.0 will work just fine... Ship It! :-)

@turp1twin
Copy link

Any updates on a potential ship date for 2.4.0? Thanks!

@AliCharper
Copy link

AliCharper commented Nov 15, 2017

Hi,

I really need to write a query for a scenario like this to have all the data in the parent and child with just a single query. It seems writing a query when we have more than one child under a single parent is not that easy or possible.

POST /test/grandparent/_search?pretty
{
  "query": 
  {
    "has_child": 
    {
      "type": "parent",
      "query": 
      {
        "has_child": 
        {
          "type": "child",
          "query": 
          {            
            "match_all": {}
          },
           "inner_hits": {}
        }
      },
           "inner_hits": {}
    }
  }
}

if I had a secondchild type, I can not add it beside the child in the query. I have written the whole mapping below.

PUT /test
{
  "mappings": {
    "grandparent": {},
    "parent": {
      "_parent": {
        "type": "grandparent" 
      }
    },
    "child": {
      "_parent": {
        "type": "parent" 
      }
    }
    ,
    "secondchild": {
      "_parent": {
        "type": "parent" 
      }
  }
  }
}

@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Parent/Child labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

No branches or pull requests

6 participants