Importing multi-valued field into Solr from mySQL using Solr Data Import Handler
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的更多相关文章
- Solr 4.3.0 配置Data import handler时出错
启动solr的时候,居然出现了如下的错误: org.apache.solr.common.SolrException: RequestHandler init failure at or ...
- 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 ...
- sorl6.0+jetty+mysql搭建solr服务
1.下载solr 官网:http://lucene.apache.org/solr/ 2.目录结构如下 3.启动solr(默认使用jetty部署) 在path路径下将 bin文件夹对应的目录加入,然后 ...
- Solr系列四:Solr(solrj 、索引API 、 结构化数据导入)
一.SolrJ介绍 1. SolrJ是什么? Solr提供的用于JAVA应用中访问solr服务API的客户端jar.在我们的应用中引入solrj: <dependency> <gro ...
- Solr与MySQL查询性能对比
本文简单对比下Solr与MySQL的查询性能速度. 测试数据量:10407608 Num Docs: 10407608 这里对MySQL的查询时间都包含了从MySQL Server获取数据的时 ...
- 使用Solr索引MySQL数据
环境搭建 1.到apache下载solr,地址:http://mirrors.hust.edu.cn/apache/lucene/solr/ 2.解压到某个目录 3.cd into D:\Solr\s ...
- Solr导入MySql中的数据
1.参照 http://www.cnblogs.com/luxh/p/5016894.html 部署好solr的环境 2.在solr_home下建立一个core_item目录 [root@iZ23ex ...
- solr导入mysql数据库
感谢ITeye的博主viskyzz分享的经验,笔者基本参考ta的方法.然而,解决中间出现的问题时也融入了自己的经验. 查看ta的原文请戳: http://tbwuming.iteye.com/blog ...
- Solr与Mysql简单集成
Solr与Mysql数据库的集成,实现全量索引.增量索引的创建. 基本原理很简单:在Solr项目中注册solr的DataImportHandler并配置Mysql数据源以及数据查询sql语句.当我们通 ...
随机推荐
- grep 的学习 正则
grep 命令: grep "name" /path/file_name 从file_name文件中中查找 name 字符 grep -c "name ...
- Blender 插件整理
系统自带插件列表: 好用的第三方插件: Align Vertices to Grease Pencil, 对齐顶点到蜡笔, https://blenderartists.org/t/addon-a ...
- C++学习(一)之Visual Studio安装以及首次使用
一.安装Visual Studio 首先下载Visual Studio 链接: http://pan.baidu.com/s/1pLhJt0Z 密码:uqyc 将.ios文件解压得到以下文件: 点击v ...
- [小A与最大子段和][斜率优化dp+二分]
链接:https://ac.nowcoder.com/acm/contest/545/A来源:牛客网题目描述 小A在网上看到了 "最大子段和" 问题的解法.第二天,小A向小B讲解了 ...
- python------面向对象介绍之多态实例
一. 多态 一种接口,多种实现. 多态性(polymorphisn)是允许你将父对象设置成为和一个或更多的他的子对象相等的技术,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作. ...
- 远程登录多用户同时访问Win7系统远程桌面
https://jingyan.baidu.com/article/ca00d56c384ea0e99febcf45.html 一,远程电脑上新增三个用户名 1 在远程电脑桌面,右击[计算机]图标 ...
- LeetCode – Group Shifted Strings
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- python实现单链表的翻转
#!/usr/bin/env python #coding = utf-8 class Node: def __init__(self,data=None,next = None): ...
- mysql为int类型的字段php取出来之后为何变为string类型?
https://segmentfault.com/q/1010000002957162 php从mysql取出int数据,变成了string https://blog.csdn.net/as17501 ...
- .Net Core 应用方向 图谱
.Net Core 应用方向 图谱, 如下图 : 大规模并行计算 是 大数据 和 人工智能 的 基础, 是 未来 大计算能力 的 基础, 网格计算 是 未来 大计算能力 的 一个 分支 . 所以, ...