1. Get required libraries
Download following .jar files:
- solr-mongo-importer-1.0.0.jar (
https://github.com/downloads/james75/SolrMongoImporter/solr-mongo-importer-1.0.0.jar)
- mongo-2.10.1.jar (http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.10.1/mongo-java-driver-2.10.1.jar)
save these files into
solr/contrib/dataimporthandler/lib/
2. Configure solrconfig.xml
<lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-dataimporthandler-.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
3. Configure data-config.xml
<?xml version="1.0"?>
<dataConfig>
<dataSource name="mymongodb" type="MongoDataSource" database="MongodbDatabaseName" />
<document name="data">
<!-- if query="" then it imports everything -->
<entity name="users"
processor="MongoEntityProcessor"
query=""
collection="users"
datasource="mymongodb"
transformer="MongoMapperTransformer">
<field column="id" name="id" mongoField="_id" />
<!--<field column="_id" name="id" />-->
<entity name="company"
processor="MongoEntityProcessor"
query="{'_id':'${users.id}'}"
collection="company"
datasource="mymongodb"
transformer="MongoMapperTransformer">
<field column="company" name="company" mongoField="company"/>
</entity>
<entity name="biodata"
processor="MongoEntityProcessor"
query="{'_id':'${users.id}'}"
collection="users"
datasource="mymongodb"
transformer="script:biodataTransformer">
</entity>
</entity>
</document>
<script><![CDATA[
function biodataTransformer(row){
if(row.get('biodata') !== null){
var biodata = row.get('biodata')
if(biodata.get("age") !== null){
row.put("biodata_age", biodata.get("age").toString());
}
if(biodata.get("height") !== null){
row.put("biodata_height", biodata.get("height").toString());
}
}
return row;
}
]]></script>
</dataConfig>
4. Configure schema.xml
Define the fields you want to index in schema.xml
5. Import mongodb data into solr with outer join
Fire up solr and go to dataimport tab and execute data import.