jsonfacet分组聚合查询算法
unique、hll函数问题:json
对不一样的值进行估算,并不是准确的值,分布式
优势:节省内存消耗,用分组算法对不一样的值count进行估算函数
缺点:没法准确统计count(distinct key)spa
区别:blog
unique给定字段的唯一值的数量。超过100个值,它不会产生精确的估计,唯一的facet函数是Solr最快速的实现来计算不一样值的数量内存
hll经过超log-log算法的分布式基数估计it
记录:request
json.facet={fz:{type:terms,field:khid,refine:true,overrequest:100000,limit:10,facet:{summy:"sum(my)",sumcnt:"hll(posid)"}}}&fq=month:(201808)语法
json.facet={fz:{type:terms,field:khid,refine:true,overrequest:100000,limit:10,facet:{summy:"sum(my)",sumcnt:"unique(posid)"}}}&fq=month:(201808)
计算出的sumcnt是估算,而不是精确计数
hll函数比unqie函数估算的准确些,但都不精确
解决方法:
一、用stats语法对count(distinct)统计
stats=true&stats.field={!countDistinct=true}posid&fq=month:(201808)
精确统计,对全部节点的数据进行全面统计,耗时高,吃内存
二、dv函数解决
&indent=on&json.facet={fz:{terms:{field:posid,method:dv,limit:1000000}}}