我尝试编写一个Solr查询,该查询与Hive的LATERAL EXPLODE类似,并以CSV格式返回结果。我想返回一个" row"对于multiValued字段中的每个值,并复制" parent"值。
这是我的查询...
http://localhost:8983/solr/select?q=*%3A*&fl=parent,id&wt=csv
返回此输出。
parent,id
10,"4100,4435"
11,"376,190,4542"
12,"141,142"
但是,我希望查询结果返回如下内容:
parent,id
10,4100
10,4435
11,376
11,190
11,4542
12,141
12,142
Solr可以实现吗?
答案 0 :(得分:2)
对您的数据进行非规范化并使用Solr的Result Grouping。
存储以下数据:
parent,id,id_group
10,"4100","4100,4435"
10,"4435","4100,4435"
11,"376","376,190,4542"
11,"190","376,190,4542"
11,"4542","376,190,4542"
12,"141","141,142"
12,"142","141,142"
现在,当您想为每个多值字段添加单行时。
<强>查询:强> http://localhost:8983/solr/awesome-collection/select?q=*:*&fl=parent,id&wt=json&indent=true
<强>结果:强>
parent,id
10,4100
10,4435
11,376
11,190
11,4542
12,141
12,142
如果要将数据分组为
<强>结果:强>
parent,id_group
10,"4100,4435"
11,"376,190,4542"
12,"141,142"