简体   繁体   English

如何在不使用json.facet的情况下使用countDistinct来获得按…分组的不同值

[英]How to use countDistinct to get distinct values grouped by … without using json.facet

Using solr 5.2.1 I'm trying to do something that in sql would look like: 使用solr 5.2.1我正在尝试在sql中执行以下操作:

SELECT COUNT(DISTINCT(SESSION_ID)), COUNTRY FROM LOG
GROUP BY COUNTRY

The following answer would work but uses json.facet and I would like to create a banan panel for this query without having to re write the query and filter services. 以下答案将起作用,但使用json.facet,我想为此查询创建一个banan面板,而不必重新编写查询和过滤服务。

This is what I got so far: 这是我到目前为止所得到的:

stats.countDistinct=true stats.distinctValues=true/false

JSON response: 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"}},

It does not matter if distinctValues is true or false, no countDistinct value is provided in the result. 不管true或false是true还是false,结果中都不会提供countDistinct值。

The following: 下列:

stats.calcdistinct=true

JSON response: 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"}},

This seems to be doing what I want but adds hundreds of thoudsands of distinctValues to the result. 这似乎可以满足我的要求,但会在结果中添加成百上千的distinctValues。

According to the documentation calcdistinct would set countDistinct and distinctValues to true but replacing calcdistinct with countDistinct and distinctValues true does not do the same thing. 根据文档, calcdistinct会将countDistinct和distinctValues设置为true,但是用countDistinct和distinctValues true替换calcdistinct不会做相同的事情。

Is there a way to get the count distinct without getting the hundreds of thousands of distinct values as well? 有没有办法在不获得成千上万个不同值的情况下使计数变得与众不同?

Can this be done without using facet.json? 可以不使用facet.json来完成吗?

You have to use the stats.field param to solve this, the distinctValues or countDistinct can't be used directly. 您必须使用stats.field参数来解决此问题,distinctValues或countDistinct不能直接使用。

In my problem I need only the distinct count of the primary domains. 在我的问题中,我只需要主域的不同数量即可。

"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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM