1

使用 solr 5.2.1 我正在尝试做一些在 sql 中看起来像这样的事情:

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

以下答案可行但使用 json.facet,我想为此查询创建一个香蕉面板,而无需重新编写查询和过滤服务。

这是我到目前为止得到的:

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"}},

distinctValues 是真还是假都没有关系,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,但是将 calcdistinct 替换为 countDistinct 和 distinctValues true 不会做同样的事情。

有没有办法在不获得数十万个不同值的情况下使计数不同?

这可以在不使用 facet.json 的情况下完成吗?

4

1 回答 1

0

您必须使用 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"]}},
于 2018-02-07T07:07:12.237 回答