我正试图从我们的solr服务器获得两级方面的计数。文档看起来像这样(仅缩写为相关字段):
{
"id":"100071F5",
"datasource":"ABC",
"mediatype":"ISSBD"
}
使用这样的查询...
http://localhost:8983/solr/select?wt=json&fl=id&indent=true&facet=true&facet.field=datasource&facet.field=mediatype
......我得到这样的结果:
"facet_fields":{
"datasource":[
"ABC",75286,
"DEF",47257],
"mediatype":[
"POSTCARD",75286,
"RARE",12033,
"MANUSCRIPT",9418,
"BOOK",5849,
"OTHER",4747,
"UNKNOWN",2603,
"MAP",1033,
"GLOBE",704,
"MIXED",13,
"ISSUE",1]} ...
但我真正想要的是这样的事情:
"facet_fields":{
"datasource":[
"ABC",75286,
"mediatype":[
"POSTCARD",1234,
"RARE",1,
"BOOK",533,
"OTHER",47],
"DEF",47257,
"mediatype":[
"POSTCARD",7286,
"RARE",1203,
"MANUSCRIPT",918,
"BOOK",549,
"OTHER",4747,
"UNKNOWN",2603,
"MAP",1033,
"GLOBE",704,
"MIXED",13,
"ISSUE",1]} ...
在单词中:我喜欢在一个字段上有一个方面,然后在另一个字段上有每个子结构的子方面。这在Solr有可能吗?
答案 0 :(得分:1)
您可以使用Pivot Faceting:
&facet.pivot=datasource,mediatype
它应该给你一个类似的结构:
[{
"field":"datasource",
"value":"ABC",
"count":75286,
"pivot":[{
"field":"mediatype",
"value":"POSTCARD",
"count":34919
}, { ....
}]
}]
您还可以使用the JSON Facet API制作更详细的构面聚合和子构面。从上面的参考指南中采用的例子:
top_datasource:{
type: terms,
field: datasource,
facet:{
top_mediatype:{
type: terms, // nested terms facet on author will be calculated for each parent bucket (datasource)
field: mediatype
}
}
}