问题描述
在Solr索引中,我有一个可选的日期字段.我们称之为 Property_3_1044
.
In my Solr index I have an optional date field. Let's call it Property_3_1044
.
我想找到 Property_3_1044
的最大值和最小值,以及所有没有该日期的项目的数量.
I want to find the maximum and the minimum of Property_3_1044
as well as the number of all items without that date.
我相信刻面是最好的方法.如果有更好的方法,请纠正我!
I believe faceting is the best approach. Please correct me if there is a better way!
使用查询构面我可以使用集合函数 min
和 max
分别获得最小值和最大值:
Using Query Facets I can use aggregate functions min
and max
to obtain minimum and maximum, respectively:
http://localhost:8983/solr/Shard/query?q=:&json.facet={Date1:{type:query,facet:{"min":"min(Property_3_1044)","max":"max(Property_3_1044)"}}}&rows=0
结果:
"facets":{
"count":249,
"Date1":{
"count":249,
"min":"2019-01-09T00:00:00Z",
"max":"2019-01-22T00:00:00Z"}}}
(除了问题:如何摆脱2个 count
s?)
(Question aside: How to get rid of the 2 count
s?)
使用术语方面我可以使用 missing
参数查找所有没有日期的项目:
Using Terms Facets I can use the missing
parameter to find all items without date:
http://localhost:8983/solr/Shard/query?q=:&rows=0&json.facet={Date2:{terms:{field:Property_3_1044,missing:true,limit:0}}}
结果:
"facets":{
"count":249,
"Date2":{
"buckets":[],
"missing":{
"count":240}}}}
如何组合这两个查询?我知道我可以只执行两个(通过串联两个查询字符串),但是我想知道是否有更有效的方法.我假设同时执行查询构面和术语构面比仅拥有一个构面要昂贵得多.例如,聚合函数 missing
允许我仅使用查询构面来做所有事情(但是没有这样的方法,对吗?).
How can I combine these two queries? I know I can just execute both (by just concatenating the two queries strings), but I'd like to know whether there is a more efficient way. I assume that performing both a query facet and a terms facet is more expensive than just having a single facet. For example, an aggregate function missing
would allow me to do everything just using the query facet (but there is no such method, is there?).
推荐答案
我自己找到了解决方案;我只需要添加一个方面查询 q
即可过滤非空值-> [* TO *]
:
I found a solution myself; I just need to add a facet query q
which filters for not-null values -> [* TO *]
:
http://localhost:8983/solr/Shard/query?q=:&json.facet={Date1:{type:query,q:"Property_3_1044:[* TO *]",facet:{"min":"min(Property_3_1044)","max":"max(Property_3_1044)"}}}&rows=0
结果中,外部计数是所有项目的数量(此处为225),内部构面计数将给出已设置日期的项目数量,即.在应用 q
之后(此处为9):
In the result, the outer count is the number of all items (here: 225) and the inner facet count will give the the number of items with date set, ie. after q
was applied (here: 9):
"facets":{
"count":225,
"Date1":{
"count":9,
"min":"2019-01-09T00:00:00Z",
"max":"2019-01-22T00:00:00Z"}}}
没有日期的商品数量是差异(225-9 = 216).
The number of items without date is the difference (225-9=216).
这篇关于Solr:查询构面并计数缺失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!