You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Pranaya Behera <pr...@igp.com> on 2016/01/07 08:46:02 UTC

Parent Child Schema Design

Hi,
      I have read yonik.com/solr-nested-objects/ which states that there 
is no need for additional schema changes other than having a _root_ 
which is already present in the schema.xml. But it never specified on 
for the child elements what would the schema look like. And the post 
actually uses curl with json to index data to solr. I am using python 
client to index data to solr.

I have products as the core. This is one document but it has more 
interlinked child documents. As of now it is a single flat structure 
schema. But if I would like to use the parent-child relationship how 
would I go about it. Sample current schema:

<field name="id" type="string" indexed="true" stored="true" 
required="true" multiValued="false" />
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>
<field name="_text_" type="text_general" indexed="true" stored="false" 
multiValued="true"/>
<field name="name" type="text_general" indexed="true" stored="true" 
required="false" multiValued="false" />
<field name="url" type="string" indexed="false" stored="false" 
required="false" />

Now I would like to add child document to it. Lets say I would like to 
add another field named steps which will contain id, product_id, name, 
description. This steps would be a multivalued as per product we have 
multiple steps.

Can someone help me figure out how to go about this ?

-- 
Thanks & Regards
Pranaya Behera


Re: Parent Child Schema Design

Posted by Yonik Seeley <ys...@gmail.com>.
On Thu, Jan 7, 2016 at 1:50 PM, Steven White <sw...@gmail.com> wrote:
> How nested can a parent / child document be?  And how many child documents
> can be in a parent node?

No real limit (other than the normal ones... you can't have more than
2B docs in a single segment)... probably just a practical limit based
on memory (they are all indexed atomically at the same time)

-Yonik

Re: Parent Child Schema Design

Posted by Steven White <sw...@gmail.com>.
How nested can a parent / child document be?  And how many child documents
can be in a parent node?

To be more specific, how deep can this tree be:

  Parent
    Child
      Child
        Child

And how many children in a Parent can be:

  Parent
    Child-1
    Child-2
    Child-N
    Child
      Child-1
      Child-2
      Child-3

Thanks

Steve


On Thu, Jan 7, 2016 at 1:35 PM, Binoy Dalal <bi...@gmail.com> wrote:

> To clarify, what I meant was any field that you wish to use either  in your
> child or parent document has to already be defined in the schema.
> You need to define these fields normally, meaning no you are not required
> to make any special changes to the field definition for use in either
> parent or child docs.
> Once done, you can use these fields in the parent as well as child docs.
>
> I suggest you first try out the example given in yoniks blog. It's fairly
> simple and will give you a good idea of the concepts and the steps
> involved. Once you're confident in your understanding of the concepts,
> you'll be able to implement your own setup easily.
>
> On Thu, 7 Jan 2016, 21:37 Tom Evans <te...@googlemail.com> wrote:
>
> > On Thu, Jan 7, 2016 at 3:53 PM, Pranaya Behera <pr...@igp.com>
> > wrote:
> > > Can you give an example ? I have already mentioned what I want to do in
> > my
> > > first email ? Confused in this part where you said provided fields are
> > > already defined.
> >
> > Solr collections are homogeneous, so child documents have the same
> > schema as parent documents. If you need to have different fields in
> > the parents/children, you will need to define all the disjoint fields
> > as required="false".
> >
> > Cheers
> >
> > Tom
> >
> --
> Regards,
> Binoy Dalal
>

Re: Parent Child Schema Design

Posted by Binoy Dalal <bi...@gmail.com>.
To clarify, what I meant was any field that you wish to use either  in your
child or parent document has to already be defined in the schema.
You need to define these fields normally, meaning no you are not required
to make any special changes to the field definition for use in either
parent or child docs.
Once done, you can use these fields in the parent as well as child docs.

I suggest you first try out the example given in yoniks blog. It's fairly
simple and will give you a good idea of the concepts and the steps
involved. Once you're confident in your understanding of the concepts,
you'll be able to implement your own setup easily.

On Thu, 7 Jan 2016, 21:37 Tom Evans <te...@googlemail.com> wrote:

> On Thu, Jan 7, 2016 at 3:53 PM, Pranaya Behera <pr...@igp.com>
> wrote:
> > Can you give an example ? I have already mentioned what I want to do in
> my
> > first email ? Confused in this part where you said provided fields are
> > already defined.
>
> Solr collections are homogeneous, so child documents have the same
> schema as parent documents. If you need to have different fields in
> the parents/children, you will need to define all the disjoint fields
> as required="false".
>
> Cheers
>
> Tom
>
-- 
Regards,
Binoy Dalal

Re: Parent Child Schema Design

Posted by Tom Evans <te...@googlemail.com>.
On Thu, Jan 7, 2016 at 3:53 PM, Pranaya Behera <pr...@igp.com> wrote:
> Can you give an example ? I have already mentioned what I want to do in my
> first email ? Confused in this part where you said provided fields are
> already defined.

Solr collections are homogeneous, so child documents have the same
schema as parent documents. If you need to have different fields in
the parents/children, you will need to define all the disjoint fields
as required="false".

Cheers

Tom

Re: Parent Child Schema Design

Posted by Pranaya Behera <pr...@igp.com>.
Can you give an example ? I have already mentioned what I want to do in 
my first email ? Confused in this part where you said provided fields 
are already defined.

On Thursday 07 January 2016 06:44 PM, Binoy Dalal wrote:
> Yes. Provided your fields are already defined.
>
> On Thu, 7 Jan 2016, 17:52 Pranaya Behera <pr...@igp.com> wrote:
>
>> Hi Binay,
>>                 Are you saying there is no need to add anything to the
>> existing schema that I have ? While indexing all I have to provide is a
>> _childDocuments_ key and the key => value pair as per I want without
>> needing to specify it in the schema.xml ?
>>
>> On Thursday 07 January 2016 01:47 PM, Binoy Dalal wrote:
>>> How to index such documents is also given in the same blog under Indexing
>>> Nested Documents.
>>> You just need to add a json key _childDocuments_ to the doc and specify
>> the
>>> child doc as the value for this key.
>>> There was a similar question on the mailing list earlier. You can find
>> that
>>> here:
>>> https://mail-archives.apache.org/mod_mbox/lucene-solr-user/201512.mbox/
>>> <CABd%2B1eLgwJf02EbkdN53EsJr76JqDadYri-zf3HpQGTvKOAguA%40mail.gmail.com>
>>>
>>> On Thu, 7 Jan 2016, 13:16 Pranaya Behera <pr...@igp.com> wrote:
>>>
>>>> Hi,
>>>>         I have read yonik.com/solr-nested-objects/ which states that
>> there
>>>> is no need for additional schema changes other than having a _root_
>>>> which is already present in the schema.xml. But it never specified on
>>>> for the child elements what would the schema look like. And the post
>>>> actually uses curl with json to index data to solr. I am using python
>>>> client to index data to solr.
>>>>
>>>> I have products as the core. This is one document but it has more
>>>> interlinked child documents. As of now it is a single flat structure
>>>> schema. But if I would like to use the parent-child relationship how
>>>> would I go about it. Sample current schema:
>>>>
>>>> <field name="id" type="string" indexed="true" stored="true"
>>>> required="true" multiValued="false" />
>>>> <field name="_version_" type="long" indexed="true" stored="true"/>
>>>> <field name="_root_" type="string" indexed="true" stored="false"/>
>>>> <field name="_text_" type="text_general" indexed="true" stored="false"
>>>> multiValued="true"/>
>>>> <field name="name" type="text_general" indexed="true" stored="true"
>>>> required="false" multiValued="false" />
>>>> <field name="url" type="string" indexed="false" stored="false"
>>>> required="false" />
>>>>
>>>> Now I would like to add child document to it. Lets say I would like to
>>>> add another field named steps which will contain id, product_id, name,
>>>> description. This steps would be a multivalued as per product we have
>>>> multiple steps.
>>>>
>>>> Can someone help me figure out how to go about this ?
>>>>
>>>> --
>>>> Thanks & Regards
>>>> Pranaya Behera
>>>>
>>>> --
>>> Regards,
>>> Binoy Dalal
>>>
>> --
>> Thanks & Regards
>> Pranaya Behera
>>
>> --
> Regards,
> Binoy Dalal
>

-- 
Thanks & Regards
Pranaya Behera


Re: Parent Child Schema Design

Posted by Binoy Dalal <bi...@gmail.com>.
Yes. Provided your fields are already defined.

On Thu, 7 Jan 2016, 17:52 Pranaya Behera <pr...@igp.com> wrote:

> Hi Binay,
>                Are you saying there is no need to add anything to the
> existing schema that I have ? While indexing all I have to provide is a
> _childDocuments_ key and the key => value pair as per I want without
> needing to specify it in the schema.xml ?
>
> On Thursday 07 January 2016 01:47 PM, Binoy Dalal wrote:
> > How to index such documents is also given in the same blog under Indexing
> > Nested Documents.
> > You just need to add a json key _childDocuments_ to the doc and specify
> the
> > child doc as the value for this key.
> > There was a similar question on the mailing list earlier. You can find
> that
> > here:
> > https://mail-archives.apache.org/mod_mbox/lucene-solr-user/201512.mbox/
> > <CABd%2B1eLgwJf02EbkdN53EsJr76JqDadYri-zf3HpQGTvKOAguA%40mail.gmail.com>
> >
> > On Thu, 7 Jan 2016, 13:16 Pranaya Behera <pr...@igp.com> wrote:
> >
> >> Hi,
> >>        I have read yonik.com/solr-nested-objects/ which states that
> there
> >> is no need for additional schema changes other than having a _root_
> >> which is already present in the schema.xml. But it never specified on
> >> for the child elements what would the schema look like. And the post
> >> actually uses curl with json to index data to solr. I am using python
> >> client to index data to solr.
> >>
> >> I have products as the core. This is one document but it has more
> >> interlinked child documents. As of now it is a single flat structure
> >> schema. But if I would like to use the parent-child relationship how
> >> would I go about it. Sample current schema:
> >>
> >> <field name="id" type="string" indexed="true" stored="true"
> >> required="true" multiValued="false" />
> >> <field name="_version_" type="long" indexed="true" stored="true"/>
> >> <field name="_root_" type="string" indexed="true" stored="false"/>
> >> <field name="_text_" type="text_general" indexed="true" stored="false"
> >> multiValued="true"/>
> >> <field name="name" type="text_general" indexed="true" stored="true"
> >> required="false" multiValued="false" />
> >> <field name="url" type="string" indexed="false" stored="false"
> >> required="false" />
> >>
> >> Now I would like to add child document to it. Lets say I would like to
> >> add another field named steps which will contain id, product_id, name,
> >> description. This steps would be a multivalued as per product we have
> >> multiple steps.
> >>
> >> Can someone help me figure out how to go about this ?
> >>
> >> --
> >> Thanks & Regards
> >> Pranaya Behera
> >>
> >> --
> > Regards,
> > Binoy Dalal
> >
>
> --
> Thanks & Regards
> Pranaya Behera
>
> --
Regards,
Binoy Dalal

Re: Parent Child Schema Design

Posted by Pranaya Behera <pr...@igp.com>.
Hi Binay,
               Are you saying there is no need to add anything to the 
existing schema that I have ? While indexing all I have to provide is a 
_childDocuments_ key and the key => value pair as per I want without 
needing to specify it in the schema.xml ?

On Thursday 07 January 2016 01:47 PM, Binoy Dalal wrote:
> How to index such documents is also given in the same blog under Indexing
> Nested Documents.
> You just need to add a json key _childDocuments_ to the doc and specify the
> child doc as the value for this key.
> There was a similar question on the mailing list earlier. You can find that
> here:
> https://mail-archives.apache.org/mod_mbox/lucene-solr-user/201512.mbox/
> <CABd%2B1eLgwJf02EbkdN53EsJr76JqDadYri-zf3HpQGTvKOAguA%40mail.gmail.com>
>
> On Thu, 7 Jan 2016, 13:16 Pranaya Behera <pr...@igp.com> wrote:
>
>> Hi,
>>        I have read yonik.com/solr-nested-objects/ which states that there
>> is no need for additional schema changes other than having a _root_
>> which is already present in the schema.xml. But it never specified on
>> for the child elements what would the schema look like. And the post
>> actually uses curl with json to index data to solr. I am using python
>> client to index data to solr.
>>
>> I have products as the core. This is one document but it has more
>> interlinked child documents. As of now it is a single flat structure
>> schema. But if I would like to use the parent-child relationship how
>> would I go about it. Sample current schema:
>>
>> <field name="id" type="string" indexed="true" stored="true"
>> required="true" multiValued="false" />
>> <field name="_version_" type="long" indexed="true" stored="true"/>
>> <field name="_root_" type="string" indexed="true" stored="false"/>
>> <field name="_text_" type="text_general" indexed="true" stored="false"
>> multiValued="true"/>
>> <field name="name" type="text_general" indexed="true" stored="true"
>> required="false" multiValued="false" />
>> <field name="url" type="string" indexed="false" stored="false"
>> required="false" />
>>
>> Now I would like to add child document to it. Lets say I would like to
>> add another field named steps which will contain id, product_id, name,
>> description. This steps would be a multivalued as per product we have
>> multiple steps.
>>
>> Can someone help me figure out how to go about this ?
>>
>> --
>> Thanks & Regards
>> Pranaya Behera
>>
>> --
> Regards,
> Binoy Dalal
>

-- 
Thanks & Regards
Pranaya Behera


Re: Parent Child Schema Design

Posted by Binoy Dalal <bi...@gmail.com>.
How to index such documents is also given in the same blog under Indexing
Nested Documents.
You just need to add a json key _childDocuments_ to the doc and specify the
child doc as the value for this key.
There was a similar question on the mailing list earlier. You can find that
here:
https://mail-archives.apache.org/mod_mbox/lucene-solr-user/201512.mbox/
<CABd%2B1eLgwJf02EbkdN53EsJr76JqDadYri-zf3HpQGTvKOAguA%40mail.gmail.com>

On Thu, 7 Jan 2016, 13:16 Pranaya Behera <pr...@igp.com> wrote:

> Hi,
>       I have read yonik.com/solr-nested-objects/ which states that there
> is no need for additional schema changes other than having a _root_
> which is already present in the schema.xml. But it never specified on
> for the child elements what would the schema look like. And the post
> actually uses curl with json to index data to solr. I am using python
> client to index data to solr.
>
> I have products as the core. This is one document but it has more
> interlinked child documents. As of now it is a single flat structure
> schema. But if I would like to use the parent-child relationship how
> would I go about it. Sample current schema:
>
> <field name="id" type="string" indexed="true" stored="true"
> required="true" multiValued="false" />
> <field name="_version_" type="long" indexed="true" stored="true"/>
> <field name="_root_" type="string" indexed="true" stored="false"/>
> <field name="_text_" type="text_general" indexed="true" stored="false"
> multiValued="true"/>
> <field name="name" type="text_general" indexed="true" stored="true"
> required="false" multiValued="false" />
> <field name="url" type="string" indexed="false" stored="false"
> required="false" />
>
> Now I would like to add child document to it. Lets say I would like to
> add another field named steps which will contain id, product_id, name,
> description. This steps would be a multivalued as per product we have
> multiple steps.
>
> Can someone help me figure out how to go about this ?
>
> --
> Thanks & Regards
> Pranaya Behera
>
> --
Regards,
Binoy Dalal