http://stackoverflow.com/questions/20233837/importing-multi-valued-field-into-solr-from-mysql-using-solr-data-import-handler

Q:

We have the following two tables in our mySQL:

mysql> describe comment;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| blogpost_id | int(11) | YES | | NULL | |
| comment_text | varchar(256) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+ mysql> describe comment_tags;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| comment_id | int(11) | YES | | NULL | |
| tag | varchar(80) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+

Where each comment can have multiple tags. We can import the entire comment into Solr using the Data Import Handler. However I am not sure how to import the tags for each comment into a multivalued field defined the schema.xml for each comment document.

A:

You can also use GROUP_CONCAT with a Seperator(e.g " , ") and then try something like this :

<dataConfig>
<!-- dataSource is just an example. Included just for completeness. -->
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/db" user="root" password="root"/>
<document>
<entity name="comment" pk="id" query="SELECT *, group_concat(tags) as comment_tags FROM comment" transformer="RegexTransformer">
<field column="blogpost_id" name="blogpost_id"/>
<field column="comment_text" name="comment_text" />
<field column="tag" name="comment_tags" splitBy = "," />
</entity>
</document>
</dataConfig>

It'll increase the Performance and also will remove the Dependency of another query.

------------------

solr在DIH中常见的场景:

表A一条记录对应表B多条记录(明细)。

Importing multi-valued field into Solr from mySQL using Solr Data Import Handler的更多相关文章

  1. Solr 4.3.0 配置Data import handler时出错

    启动solr的时候,居然出现了如下的错误: org.apache.solr.common.SolrException: RequestHandler init failure        at or ...

  2. Importing/Indexing database (MySQL or SQL Server) in Solr using Data Import Handler--转载

    原文地址:https://gist.github.com/maxivak/3e3ee1fca32f3949f052 Install Solr download and install Solr fro ...

  3. sorl6.0+jetty+mysql搭建solr服务

    1.下载solr 官网:http://lucene.apache.org/solr/ 2.目录结构如下 3.启动solr(默认使用jetty部署) 在path路径下将 bin文件夹对应的目录加入,然后 ...

  4. Solr系列四:Solr(solrj 、索引API 、 结构化数据导入)

    一.SolrJ介绍 1. SolrJ是什么? Solr提供的用于JAVA应用中访问solr服务API的客户端jar.在我们的应用中引入solrj: <dependency> <gro ...

  5. Solr与MySQL查询性能对比

    本文简单对比下Solr与MySQL的查询性能速度. 测试数据量:10407608     Num Docs: 10407608 这里对MySQL的查询时间都包含了从MySQL Server获取数据的时 ...

  6. 使用Solr索引MySQL数据

    环境搭建 1.到apache下载solr,地址:http://mirrors.hust.edu.cn/apache/lucene/solr/ 2.解压到某个目录 3.cd into D:\Solr\s ...

  7. Solr导入MySql中的数据

    1.参照 http://www.cnblogs.com/luxh/p/5016894.html 部署好solr的环境 2.在solr_home下建立一个core_item目录 [root@iZ23ex ...

  8. solr导入mysql数据库

    感谢ITeye的博主viskyzz分享的经验,笔者基本参考ta的方法.然而,解决中间出现的问题时也融入了自己的经验. 查看ta的原文请戳: http://tbwuming.iteye.com/blog ...

  9. Solr与Mysql简单集成

    Solr与Mysql数据库的集成,实现全量索引.增量索引的创建. 基本原理很简单:在Solr项目中注册solr的DataImportHandler并配置Mysql数据源以及数据查询sql语句.当我们通 ...

随机推荐

  1. Unity 3D与Android Studio安卓交互之-导出jar包

    u3d与安卓 jar 包交互 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享 ...

  2. FTP 文件传输协议的两种模式:主动模式和被动模式

    https://www.cnblogs.com/i-shu/articles/4905266.html FTP支持两种模式,一种方式叫做Standard (也就是 PORT方式,主动方式),一种是 P ...

  3. day 016 面向对象---类与类的关系

    ---恢复内容开始--- 一  依赖关系(最轻的一种关系,在方法中引入另一个类的对象) class Elephant: def __init__(self,name): self.name=name ...

  4. iostat iotop 查看硬盘的读写、 free 查看内存的命令 、netstat 命令查看网络、tcpdump 命令

    iostat 命令 查看硬盘的使用情况: iostat iostat -x iotop 命令: 若没安装先安装: yum install iotop -y free 命令,用于查看内存的使用量: fr ...

  5. acm 2044

    ////////////////////////////////////////////////////////////////////////////////#include<iostream ...

  6. 进入网站自动加自己为QQ好友代码

    <meta http-equiv="refresh" content="0; url=tencent://AddContact/?fromId=50&fro ...

  7. SQL Server 并发死锁解决案例备忘

    SET @sql = ' SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; SET DEADLOCK_PRIORITY 10 BEGIN TRAN DE ...

  8. linux运维注意事项

    防火墙和selinux一定要注意 服务器或应用出现错误是一定要查看服务器运行状态是否正确,及其相关运行日志 不管什么时候,能不要特殊字符就不要用特殊字符,避免不必要的错误 在看部署文档的时候一定要认真 ...

  9. linux(kali,centos)安装vm及其提示缺少c头文件解决方法

    我电脑系统是kali最新版 首先去官网下一个vm安装包,给个直达网址 http://www.vmware.com/cn/products/workstation/workstation-evaluat ...

  10. 侃侃Thinking In Java

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/yqj2065/article/details/37074503 对于大学生,yqj2065不推荐Th ...