[英]How to use countDistinct to get distinct values grouped by … without using json.facet
使用solr 5.2.1我正在尝试在sql中执行以下操作:
SELECT COUNT(DISTINCT(SESSION_ID)), COUNTRY FROM LOG
GROUP BY COUNTRY
以下答案将起作用,但使用json.facet,我想为此查询创建一个banan面板,而不必重新编写查询和过滤服务。
这是我到目前为止所得到的:
stats.countDistinct=true stats.distinctValues=true/false
JSON响应:
"responseHeader":{
"status":0,
"QTime":3,
"params":{
"q":"*:*",
"stats.countDistinct":"true",
"indent":"true",
"stats":"true",
"stats.facet":"country_s",
"fq":"serverUtc_dt:[2015-09-01T07:59:00.000Z TO 2015-09-01T07:59:01.000Z]",
"rows":"0",
"wt":"json",
"stats.distinctValues":"false",
"stats.field":"sessionid_s"}},
不管true或false是true还是false,结果中都不会提供countDistinct
值。
下列:
stats.calcdistinct=true
JSON响应:
"responseHeader":{
"status":0,
"QTime":7,
"params":{
"q":"*:*",
"stats.calcdistinct":"true",
"indent":"true",
"stats":"true",
"stats.facet":"country_s",
"fq":"serverUtc_dt:[2015-09-01T07:59:00.000Z TO 2015-09-01T07:59:01.000Z]",
"rows":"0",
"wt":"json",
"stats.distinctValues":"false",
"stats.field":"sessionid_s"}},
这似乎可以满足我的要求,但会在结果中添加成百上千的distinctValues。
根据文档, calcdistinct会将countDistinct和distinctValues设置为true,但是用countDistinct和distinctValues true替换calcdistinct不会做相同的事情。
有没有办法在不获得成千上万个不同值的情况下使计数变得与众不同?
可以不使用facet.json来完成吗?
您必须使用stats.field参数来解决此问题,distinctValues或countDistinct不能直接使用。
在我的问题中,我只需要主域的不同数量即可。
"params":{
"q":"*:*",
"stats.calcdistinct":"true",
"indent":"true",
"stats":"true",
"rows":"0",
"wt":"json",
"stats.field":["{!key=c_primary_domain}c_primary_domain",
"{!distinctValues=false}c_primary_domain"]}},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.