Solr: Indexing nested Documents via DIH

2019-04-16 08:15发布

问题:

I want to index my document from MySql to Solr via DIH. I have a table structure like this

  • Table User

    id
    1
    2
    3
    name
    Jay
    Chakra
    Rabbit

  • Address

    id
    1
    2
    3
    number
    1111111111
    2222222222
    3333333333
    email
    test@email.com
    test123@test.co
    unique@email.com

and other associations.

I want to index this in a nested document structure but unable to find any resource via which it can be done using DIH.

Resources refered:

  • http://yonik.com/solr-nested-objects/
  • https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index+Handlers

Please suggest a way to index it through DIH

回答1:

This feature has been implemented by SOLR-5147 and should be available for Solr 5.1+

Here is a sample configuration taken from the original Jira ticket.

<dataConfig>
  <dataSource type="JdbcDataSource" />
  <document>
    <entity name="PARENT" query="select * from PARENT">
      <field column="id" />
      <field column="desc" />
      <field column="type_s" />
      <entity child="true" name="CHILD" query="select * from CHILD where parent_id='${PARENT.id}'">
        <field column="id" />
        <field column="desc" />
        <field column="type_s" />
      </entity>
    </entity>
  </document>
</dataConfig>

note the child="true" is required for child entities.