[英]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.