简体   繁体   中英

How to insert nested data in solr using data import handler and schema

My data import handler document is below:

<document>
    <entity name="product" query="SELECT
            id,
            sku,
            name,
            image FROM products">
        <field column="id" name="id" />
        <field column="sku" name="sku" />
        <field column="name" name="name" />
        <field column="image" name="image" />
        <entity name="rates" child="true" query="select start_date, end_date, price from product_rates where product_id='${product.id}'">
            <field name="start_date" column="start_date" />
            <field name="end_date" column="end_date" />
            <field name="price" column="price" />
        </entity>
    </entity>
</document>

When I set child=true documents with child data not inserting to solr. Am I need any change in schema or solrconfig to insert child doc. I am using solr 6.3 and my schema.xml is below:

<schema name="product" version="1.5">
        <field name="_version_" type="long" indexed="true" stored="true"/>
        <field name="_root_" type="string" indexed="true" stored="false"/>

        <!--PARENT DOC-->
        <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
        <field name="sku" type="string" indexed="true" stored="true" required="true" multiValued="false" />
        <field name="name" type="text_general" indexed="false" stored="true" multiValued="false" />
        <field name="image" type="text_general" indexed="false" stored="true" multiValued="false" />

        <!--CHILD DOC-->
        <field name="start_date" type="date" indexed="false" stored="true" multiValued="false" />
        <field name="end_date" type="date" indexed="true" stored="true" multiValued="false" />
        <field name="price" type="tdouble" indexed="true" stored="true" multiValued="false" />

        <uniqueKey>id</uniqueKey>
        <defaultSearchField>id</defaultSearchField>

        <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
        <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
        <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
        <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
        <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
        <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>

        <fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />
</schema>

By adding a "child=true" parameter to the Entity processor.

Enables indexing document blocks aka Nested Child Documents for searching with Block Join Query Parsers. It can be only specified on under another root entity. It switches from default behavior (merging field values) to nesting documents as children documents. Note: parent should add a field which is used as a parent filter in query time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM