![](/img/trans.png)
[英]Can we use mysql and cassandra both in PrestoDB via connector?
[英]How can we use solr with both MongoDB and MySQL?
我想将Solr
与MongoDB
和MySQL
一起使用,并且需要组合成单核。
例如,我有一个 MongoDB 集合,它依赖于 MySQL 的一张表,
我尝试使用单独的 Solr 内核,它工作正常,但我希望它在单核中,我不知道它是否可能,如果可能,那么我们如何使用?
这是我的 DIH:(数据导入处理程序)
- Solr 与 MySQL
<dataConfig>
<dataSource
name="MySQl"
type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test"
user="root" password="root"
batchSize="-1"/>
<document>
<entity
query="select * from master_table"
name="master">
</entity>
</document>
</dataConfig>
- Solr 与 MongoDB
<dataConfig>
<dataSource
name="MyMongo"
type="MongoDataSource"
database="test" />
<document>
<entity
processor="MongoEntityProcessor"
query=""
collection="MarketCity"
datasource="MyMongo"
transformer="MongoMapperTransformer"
name="sample_entity">
<field column="_id" name="id" mongoField="_id" />
<field column="keyName" name="keyName" mongoField="keyName"/>
</entity>
</document>
</dataConfig>
所以我想做单核。
您可以从 Mysql 和 MongoDB 读取数据。 将这条记录合并到单个记录中,并将索引相同的索引合并到 solr 中。
要从 MySql 获取数据,请使用任何编程语言并获取数据。 例如,您可以使用 Java 并从 mysql 获取数据。 对 MongoDB 应用相同的逻辑。 使用 Java 从 mongoDB 获取所有需要的记录。
现在通过使用 SolrJ apis 创建 solrDocument。 在此处阅读有关 SolrDOcument 和其他 api 的更多信息
创建 SolrDocument 实例后,然后使用以下方法将您从 Mysql 和 MongoDB 获取的数据添加到其中。
addField(String name, Object value)
这将在文档中添加一个字段。
您可以像这样准备文档。
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "123456");
document.addField("name", "Kevin Ross");
document.addField("price", "100.00");
solr.add(document);
solr.commit();
获取 HttpSolrClient 的HttpSolrClient
实例。 SolrDocument 准备就绪后,将其索引到 solr。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.