1

Using solr 5.2.1 I'm trying to do something that in sql would look like:

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.

This is what I got so far:

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

JSON response:

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

The following:

stats.calcdistinct=true

JSON response:

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

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.

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?

Community
  • 1
  • 1
HMR
  • 37,593
  • 24
  • 91
  • 160
  • 1
    Could you add the json.facet-values as a requestHandler with those values hardcoded in on the server side? – MatsLindh Oct 26 '15 at 12:58
  • @MatsLindh Thank you for your reply, I will probably solve it with a custom panel, first have to get silk (as this is the newer banana I guess) and tinker with it. Was hoping I missed and have a simpler solution. The query and filter services would not be affected if the panel adds a json.facet to the url after they are done. – HMR Oct 27 '15 at 01:02
  • were you able to integrate the query output to a panel in banana? I am struck with the same issue of getting so many distinct values. – Ramzy Feb 01 '16 at 19:17
  • @HMR hi,guys,have you solved this problem?what your solution?i'm facting the same problme.thanks in advance. – zhouxiang Aug 19 '16 at 03:17
  • @zhouxiang Requirements have changed and we don't use solr for this anymore. – HMR Aug 23 '16 at 08:08
  • @HMR thank you very much.i finally resolve this by using local parameters, which is added since version 5.2 – zhouxiang Aug 24 '16 at 09:33

1 Answers1

0

You have to use the stats.field param to solve this, the distinctValues or countDistinct can't be used directly.

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"]}},
HMR
  • 37,593
  • 24
  • 91
  • 160
kishore
  • 1
  • 1