5.5.3. Facet使用

1. cl.facet.fl的使用

--按照性别、学历进行分类统计

select sex,education from facet where
syskv='cl.facet.fl:sex,education'
limit 4;

--按照性别、学历进行分类统计

--cl.facet.group.max.count用来决定每个分组统计值达到200后就不在继续统计,从而节省计算资源

select sex,education from facet where
syskv='cl.facet.fl:sex,education'
and syskv='cl.facet.group.max.count:200'
limit 4;

注意:

(1) 该处cl.facet.group.max.count设置为200,但在实际统计过程中为了考虑到每个executor读取的数量差异,故单个executor的实际统计结果为设置值的1.3倍,即总的统计结果为2001.31=260(本次测试软件executor数为1)。

(2) 该处cl.facet.group.max.count参数仅适用于每个executor中数据量均匀的情况。若每个executor中数据分布不均,则回导致统计结果出现错误。

--按照性别、学历进行分类统计

--如果设置limit 0 则只返回facet结果,不会返回数据明细

select sex,education from facet where
syskv='cl.facet.fl:sex,education'
limit 0;

--按照性别、学历、去过的城市进行分类统计

--多值列也可以使用facet

--如果设置limit 0 则只返回facet结果,不会返回数据明细

select sex,education,city from facet where
syskv='cl.facet.fl:city'
limit 4;

--按照性别、学历、去过的城市进行分类统计

--多值列也可以使用facet

--如果设置limit 0 则只返回facet结果,不会返回数据明细

select sex,education,city from facet where
syskv='cl.facet.fl:city'
limit 0;

2. cl.facet.fq的使用

--对年龄在0-18以及22-60周岁的人群进行统计

-- cl.facet.group.max.count用来决定每个分组统计值达到1000后就不在继续统计,从而节省计算资源。

select * from facet where 
syskv='cl.facet.fq:q1:age>=0 and age<18' and syskv='cl.facet.fq:q2:age>22 and age<60'
and syskv='cl.facet.group.max.count:1000'
limit 4;

--对年龄在0-18以及22-60周岁的人群进行统计

-- cl.facet.group.max.count用来决定每个分组统计值达到1000后就不在继续统计,从而节省计算资源

----如果设置limit 0 则只返回facet结果,不会返回数据明细

select * from facet where 
syskv='cl.facet.fq:q1:age>=0 and age<18' and syskv='cl.facet.fq:q2:age>22 and age<60'
and syskv='cl.facet.group.max.count:1000'
limit 0;

3. 组合使用

--按照性别、学历进行分类统计

--对年龄在0-18以及22-60周岁的人群进行统计

-- cl.facet.group.max.count用来决定每个分组统计值达到1000后就不在继续统计,从而节省计算资源

select sex,education,city from facet where 
syskv='cl.facet.fl:sex,education' and
syskv='cl.facet.fq:q1:age>=0 and age<18' and syskv='cl.facet.fq:q2:age>22 and age<60'
and syskv='cl.facet.group.max.count:1000'
limit 4;

4. 按照日期分区分批次返回

配置 cl.highpriority.partition 如何分区返回 ,以及配置 cl.highpriority.facet.count 控制数量达到多少即可停止不在继续请求。

也通常与cl.facet.group.max.count 组合使用,来决定每个分组统计值达到多少后就不在继续统计,从而节省计算资源。

select age from facet 
where partition like '%' and age like '1*'
and syskv='cl.facet.fl:age' 
and syskv='cl.highpriority.partition:day_1@day_4@day_16@day_64'
and syskv='cl.highpriority.facet.count:1000'
and syskv='cl.facet.group.max.count:1000'
 limit 5;

查看facet表内分区如下:

改小参数:

5. 限制搜索,只搜索到TOPN个结果即可

再缩小范围:

6. 限制超时时间搜索,只搜索到TOPN个结果即可

可以通过cl.search.max.collect.return.break.size、cl.sql.execute.timeout.secs来控制搜索,控制匹配到的结果数。

select count(*) from facet where partition = '20191202' 
and syskv='cl.search.max.collect.return.break.size:30000';

select count(*) from facet where partition = '20191202' 
and syskv='cl.sql.execute.timeout.secs:120';

select count(*) from facet where partition = '20191202' 
and syskv='cl.search.max.collect.return.break.size:30000' 
and syskv='cl.sql.execute.timeout.secs:120';
Copyright © lucene.xin 2020 all right reserved修改时间: 2021-07-02 11:42:23

results matching ""

    No results matching ""