Solr 6 - 字段的 SUM 值以及 GROUP BY

Solr 6 - SUM values of a field along with GROUP BY

我有一个 Solr 核心,其文档包含 6 个字段,如下所示 -

FIELDNAME   TYPE    INDEXED   STORED
department  STRING  TRUE      TRUE
group       STRING  TRUE      TRUE
age         INT     TRUE      TRUE
salary      INT     TRUE      TRUE
bonus       INT     TRUE      TRUE

我想要的是以下 -

  1. SUM 来自不同 department 的所有员工的 salary
  2. SUM 来自不同 department.
  3. 的所有员工的 salarybonus
  4. SUM 来自不同 departmentgroup 的所有员工的 salary
  5. SUM 来自不同 departmentgroup.
  6. 的所有员工的 salarybonus

示例数据 -

<doc>
  <str name="department">IT</str>
  <str name="group">INFRASTRUCTURE</str>
  <int name="age">27</int>
  <int name="salary">1000</int>
  <int name="bonus">10</int>
</doc>
<doc>
  <str name="department">IT</str>
  <str name="group">DEVELOPMENT</str>
  <int name="age">30</int>
  <int name="salary">10000</int>
  <int name="bonus">100</int>
</doc>
<doc>
  <str name="department">IT</str>
  <str name="group">DEVOPS</str>
  <int name="age">32</int>
  <int name="salary">2000</int>
  <int name="bonus">150</int>
</doc>
<doc>
  <str name="department">IT</str>
  <str name="group">INFRASTRUCTURE</str>
  <int name="age">35</int>
  <int name="salary">20000</int>
  <int name="bonus">200</int>
</doc>
<doc>
  <str name="department">HR</str>
  <str name="group">PEOPLE</str>
  <int name="age">27</int>
  <int name="salary">900</int>
  <int name="bonus">5</int>
</doc>

异常输出 -

1. For the 1st requirement -
   IT - 33000
   HR - 900
2. For the 2nd requirement -
   IT - 33460
   HR - 905
3. For the 3rd requirement -
   IT -
      INFRASTRUCTURE - 21000
      DEVELOPMENT - 10000
      DEVOPS - 2000
   HR -
      PEOPLE - 900
4. For the 4th requirement -
   IT -
      INFRASTRUCTURE - 21210
      DEVELOPMENT - 10100
      DEVOPS - 2150
   HR -
      PEOPLE - 905

我试图按照说明 here 来实现它,但是,我无法将 PIVOT FACETSUM 函数合并。

这应该有效,未经测试,可能有一些错字等...

curl http://localhost:8983/solr/col/query -d '
  q=*:*&
  json.facet={
   departments:{
    type : terms,
    field : department,
    facet:{
      sumsalary : "sum(salary)",
      sumbonus : "sum(bonus)",
      groups:{
        type : terms,
        field : group,
        facet:{
           sumsalaryg : "sum(salary)",
           sumbonusg : "sum(bonus)"
       }
    }
  }
}'