Solr:具有多值字段的mysql查询的DIH



我试图在Solr中设置一个多值字段,但在我的情况下失败了!!

DB查询结果(示例(

|id  | another_id    | name          | phone       | type        |
|----------------------------------------------------------------|
|'1' | '11'          | 'F. Brown'    | '112233440' | 'employee'  |
|'2' | '22'          | 'Jhon Smith'  | '123123123' | 'guest'     |
|'2' | '22'          | 'Jhon Smith'  | '321321321' | 'guest'     |

Solr数据配置.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource   type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/servme_prd"
user="root"
password="root" />
<document>
<entity name="person_cards" query="SELECT table1.id, table2.id AS another_id, table1.name, table2.phone, table1.type 
FROM table1
INNER JOIN table2 ON table1.id = table2.fk_id">
<field column="id" name="uid" />
<field column="another_id" name="pid" />
<field column="name" name="name" />
<field column="phone" name="phone" />
<field column="type" name="type"/>
</entity>
</document>
</dataConfig>

托管架构.xml

<uniqueKey>uid</uniqueKey>
<field name="_version_" type="plong" indexed="false" stored="false"/>
<field name="uid" type="string" docValues="false" multiValued="false" indexed="true" required="true" stored="true"/>
<field name="pid" type="string" docValues="false" multiValued="false" indexed="true" required="true" stored="true"/>
<field name="name" type="string" indexed="true" stored="true"/>
<field name="phone" type="string" docValues="false" multiValued="true" indexed="true" stored="true"/>
<field name="type" type="string" indexed="true" stored="true"/>

无论何时,我都在做一个完整的导入,我没有得到手机作为多值字段;示例solr查询响应:

{
"name":"F. Brown",
"uid":"1",
"pid":"11",
"phone":["112233440"],
"type":"employee" 
"_version_":1608065390436417536
},
{
"name":"Jhon Smith",
"uid":"2",
"pid":"22",
"phone":["123123123"],
"type":"guest" 
"_version_":1608065390436417536
},
{
"name":"Jhon Smith",
"uid":"2",
"pid":"22",
"phone":["321321321"],
"type":"guest" 
"_version_":1608065390436417536
}

我想在哪里从solr查询搜索中获得以下响应:

{
"name":"F. Brown",
"uid":"1",
"pid":"11",
"phone":["112233440"],
"type":"employee" 
"_version_":1608065390436417536
},
{
"name":"Jhon Smith",
"uid":"2",
"pid":"22",
"phone":["123123123", "321321321"],
"type":"guest" 
"_version_":1608065390436417536
}

solr配置部分缺少什么,所以我没有让多值字段按预期工作?

顺便说一句,我使用的是安装在ubuntu 14服务器上的Solr 7.4。感谢

由于您使用的是MySQL,因此快速修复方法是使用GROUP_CONCAT,然后使用DIH的RegexTransformer:拆分列

<entity transformer="RegexTransformer" name="person_cards" query="SELECT 
table1.id, 
table2.id AS another_id, 
table1.name, 
GROUP_CONCAT(table2.phone) AS phone, table1.type 
FROM table1
INNER JOIN table2 ON table1.id = table2.fk_id
GROUP BY uid
">
...
<field column="phone" name="phone" splitBy="," />
...
</entity>

最新更新