All stories
Java

Index MySQL datadase table in Solr

H
hemant-kumar

February 25, 2015


Prerequisites

Download the following jars.

Data Configuration File

Create a data-config.xml file in conf folder & add following content to it.

<dataConfig>

    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://<host>:<port>/<database name>" user="<user>" password="<password>" batchSize="1" />

    <document name="userdoc">

        <entity name="userentity" query="select ID, FIRST_NAME, LAST_NAME from users">

            <field column="id" name="ID"/>

            <field column="first_name" name="FIRST_NAME" />

            <field column="last_name" name="LAST_NAME" />

        </entity>

    </document>

</dataConfig>

Solr Configuration File

Add following content to solr-config.xml

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">

    <lst name="defaults">

        <str name="config">data-config.xml</str>

    </lst>

</requestHandler>

Schema File

Add following fields to schema.xml

<field name="first_name" type="string" indexed="true" />

<field name="last_name" type="string" indexed="true" />

Final Steps

Following steps are to be performed for starting the import.

1. Create lib folder in instance folder & copy downloaded jars in it.

2. Restart solr server.

3. Select target core.

4. Goto Data Import option.

5. Select Full Import.

6. Check Commit.

7. Click Execute.

Cheers!!
Java

0

If you found this helpful, give it some claps!

SHARE THIS ARTICLE

Share on X
LinkedIn

Responses0

Sign in to join the conversation

Sign in