【问题标题】:Solr MultiValued fields returned in a CSVCSV 中返回的 Solr 多值字段
【发布时间】:2016-05-10 20:56:24
【问题描述】:

我正在尝试编写一个 Solr 查询,该查询与 Hive 的 LATERAL EXPLODE 类似,并以 CSV 格式返回结果。我想为多值字段中的每个值返回一个“行”并复制“父”值。

这是我的查询...

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 可以做到这一点吗?

【问题讨论】:

    标签: csv solr hive


    【解决方案1】:

    非规范化您的数据并使用 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
    

    当你想将数据分组时

    查询: http://localhost:8983/solr/awesome-collection/select?q=*:*&fl=parent,id_group&wt=json&indent=true&group=true&group.field=parent&group.format=simple

    结果:

    parent,id_group
    10,"4100,4435"
    11,"376,190,4542"
    12,"141,142"
    

    【讨论】:

      猜你喜欢
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 2012-05-23
      • 1970-01-01
      相关资源
      最近更新 更多