![]() |
VOOZH | about |
The Apache Solr platform is a popular, blazing-fast, open source enterprise search solution built on Apache Lucene.
Apache Solr is equipped with the Data Import Handler (DIH), which can import data from databases and, XML, CSV, and JSON files. When paired with the CData JDBC Driver for MongoDB, you can easily import MongoDB data to Apache Solr. In this article, we show step-by-step how to use CData JDBC Driver in Apache Solr Data Import Handler and import MongoDB data for use in enterprise search.
Accessing and integrating live data from MongoDB has never been easier with CData. Customers rely on CData connectivity to:
MongoDB's flexibility means that it can be used as a transactional, operational, or analytical database. That means CData customers use our solutions to integrate their business data with MongoDB or integrate their MongoDB data with their data warehouse (or both). Customers also leverage our live connectivity options to analyze and report on MongoDB directly from their preferred tools, like Power BI and Tableau.
For more details on MongoDB use case and how CData enhances your MongoDB experience, check out our blog post: The Top 10 Real-World MongoDB Use Cases You Should Know in 2024.
> solr create -c CDataCoreFor this article, Solr is running as a standalone instance in the local environment and you can access the core at this URL: http://localhost:8983/solr/#/CDataCore/core-overview
MongoDBUniqueKeyπ Define schema in Solr for MongoDB data.
Now we are ready to use MongoDB data in Solr.
In this section, we walk through configuring the Data Import Handler.
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">solr-data-config.xml</str>
</lst>
</requestHandler>
<dataConfig>
<dataSource driver="cdata.jdbc.mongodb.MongoDBDriver" url="jdbc:mongodb:Server=MyServer;Port=27017;Database=test;User=test;Password=Password;">
</dataSource>
<document>
<entity name="restaurants"
query="SELECT Id,MongoDBColumn1,MongoDBColumn2,MongoDBColumn3,MongoDBColumn4,MongoDBColumn5,MongoDBColumn6,MongoDBColumn7,LastModifiedDate FROM restaurants"
deltaQuery="SELECT Id FROM restaurants where LastModifiedDate >= '${dataimporter.last_index_time}'"
deltaImportQuery="SELECT Id,MongoDBColumn1,MongoDBColumn2,MongoDBColumn3,MongoDBColumn4,MongoDBColumn5,MongoDBColumn6,MongoDBColumn7,LastModifiedDate FROM restaurants where Id=${dataimporter.delta.Id}">
<field column="Id" name="Id" ></field>
<field column="MongoDBColumn1" name="MongoDBColumn1" ></field>
<field column="MongoDBColumn2" name="MongoDBColumn2" ></field>
<field column="MongoDBColumn3" name="MongoDBColumn3" ></field>
<field column="MongoDBColumn4" name="MongoDBColumn4" ></field>
<field column="MongoDBColumn5" name="MongoDBColumn5" ></field>
<field column="MongoDBColumn6" name="MongoDBColumn6" ></field>
<field column="MongoDBColumn7" name="MongoDBColumn7" ></field>
<field column="LastModifiedDate" name="LastModifiedDate" ></field>
</entity>
</document>
</dataConfig>> solr stop -all > solr start
Using the CData JDBC Driver for MongoDB you are able to create an automated import of MongoDB data into Apache Solr. Download a free, 30 day trial of any of the hundreds of CData JDBC Drivers and get started today.
Download a free trial of the MongoDB Driver to get started:
Download NowLearn more:
π MongoDB IconRapidly create and deploy powerful Java applications that integrate with MongoDB document databases.