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. php curl 传输是url中带有空格的处理方法

    在crul中,应该用%20代替空格,否则,空格以后的数据将get不到.

  2. jQuery 中json字符串与对象互转

    json字符串转json对象:jQuery.parseJSON(jsonStr); json对象转json字符串:JSON.stringify(jsonObj);

  3. Oracle导入导出表

    使用PL SQL Developer进行操作 一.导出 工具<<导出表<<sql插入<<选择用户和要导出的表,勾选创建表,选择输出文件(格式最好为.sql),点击导 ...

  4. 动态规划-----hdu 1024 (区间连续和)

    给定一个长度为n的区间:求m段连续子区间的和 最大值(其中m段子区间互不相交) 思路: dp[i][j]: 前j个元素i个连续区间最大值 (重要 a[j]必须在最后一个区间内) 转移方程:dp[i][ ...

  5. 01 mysql

    Sql语句: Structured Query Language, 结构化查询语言 分类: DDL (数据定义语句) 数据定义语言 - Data Definition Language 用来定义数据库 ...

  6. hdu1540 Tunnel Warfare 线段树/树状数组

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...

  7. Linux 修改yum源

    第一种方式: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 第二种方式: ...

  8. Distributed Phoenix Chat with PubSub PG2 adapter

    转自:https://www.poeticoding.com/distributed-phoenix-chat-with-pubsub-pg2-adapter/ In this article we’ ...

  9. APACHE如何里一个站点绑定多个域名?用ServerAlias servername

    APACHE2如何里一个站点绑定多个域名?用ServerAlias以前很笨,要使多个域名指向同一站点总是这样写: <VirtualHost *:80>ServerAdmin i@kuigg ...

  10. 如何高效的使用 Git---转

    Git 工作流 当有多个开发者同时涉及到一个项目时那么就非常有必要正确使用 Git 工作流. 这里我将介绍一种工作流,它在一个多人大型项目中将非常有用. 前言 突然有一天,你成为了一个项目的技术 Le ...