Index multiple tables using SOLR

There are various ways to do it and it depends on your table schema. Some simple ones would be like:

  • If you have 2-3 different tables and they are kind of unrelated then in that case you need to have an extensive Solr schema and just index each table separately. You would perform this only when you desire to use Solr for just search on documents present in dissimilar tables.
  • It’s like you have a table STUDENT (id,name,roll) and TEACHER (id,name,subject,qualification), you need to have these fields in your solr schema (id,name,roll,subject,qualification).
  • Now index the two tables either by solrj or use Data Import Handler.
  • If you have different tables and have relations between them then you need to write SQL queries which perform joins between them and get the columns that you would like to index into solr.

Indexing either of the two tables (and not both the tables):

DB-config.xml

<dataConfig>
<dataSource driver="com.metamatrix.jdbc.MMDriver" url="jdbc:....." />
<document name="doc">
<entity name="table1"
query="select * from table1">
<field column="ID" name="ElementID" />
<field column="Name" name="ElementName" />
<field column="ElementType" name="ElementType" />
<field column="RepId" name="ElementRepId" />
</entity>

<entity name="table2"
query="select * from table2">
<field column="id" name="ElementPropertyID" />
<field column="Name" name="ElementPropertyName" />
<field column="DataType" name="ElementPropertyDataType" />
<field column="RepId" name="ElementPropertyRepId" />

</entity>
</document>
</dataConfig>

Schema.xml

<fields>

<field name="ElementID" type="string" indexed="true"
stored="true" />
<field name="ElementName" type="string" indexed="true"
stored="true" />
<field name="ElementType" type="string" indexed="true"
stored="true" />
<field name="ElementRepId" type="string" indexed="true"
stored="true" />

<field name="ElementPropertyID" type="string" indexed="true"
stored="true" />
<field name="ElementPropertyName" type="string" indexed="true"
stored="true" />
<field name="ElementPropertyDataType" type="string"
indexed="true" stored="true" />
<field name="ElementPropertyRepId" type="string" indexed="true"
stored="true" />


<dynamicField name="*" type="ignored" />
</fields>
<uniqueKey>ElementPropertyID</uniqueKey>

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,