Community Articles

Find and share helpful community-sourced technical articles.
Labels (1)
avatar
Super Collaborator

Solr indexing the MySQL database table on HDP 2.5 Tech Preview:

Solr version used: solr 4.9.0

Step1: Downloaded the solr 4.9.0.zip from

https://archive.apache.org/dist/lucene/solr/4.9.0/

Step2: Extract the file:

6742-picture1.png

Step3: modify the solrconfig.xml, schema.xml and add the db-data-config.xml at

6743-picture2.png

Step4: add the jar at this location

6744-picture3.png

  • a.vi solrconfig.xml: add these lines in between the config tags.

<lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />

<lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />

<lib dir="../../../lib/" regex="mysql-connector-java-5.0.8-bin.jar" />

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

<lst name="defaults">

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

</lst>

</requestHandler>

6745-picture4.png

  • b.vi schema.xml add the below line:

<dynamicField name="*_name" type="text_general" multiValued="false" indexed="true" stored="true" />

6746-picture5.png

  • c.Create a file called db-data-config.xml at the same path later in this session I would create a database employee in mysql server add these

<dataConfig>

<dataSource type="JdbcDataSource"

driver="com.mysql.jdbc.Driver"

url="jdbc:mysql://localhost:3306/employees"

user="root"

password="hadoop" />

<document>

<entity name="id" query="select emp_no as 'id', first_name, last_name from employees limit 1000;" />

</document>

</dataConfig>

After this is complete run the below command (d) to start solr and check if solr is up and running at url below: 8983 is the default port of solr

d.java –jar start.jar

http://localhost:8983/solr/#/

  • 6749-picture7.png
  • 6748-picture6.png

  • e.select the core selector as collection1.
  • 6750-picture8.png

  • f.Click on Data Import, expand configuration and check if its pointing to our db-data-config.xml file we created.
  • g.After the completion of Step5 below click on execute on the page.

Step5:

Setting up database:

Import an already available database into Mysql:

Step6: With this our indexing is complete using Solr.

6751-picture9.png

To do:

I will try indexing the tables in Mysql using latest version of Solr.

Reference: http://blog.comperiosearch.com/blog/2014/08/28/indexing-database-using-solr/

Hope this helps….

Thanks,

Sujitha

5,226 Views