问题描述
当前请求是
{
"query": "*:*","facet": {
"prices": {
"type": "range","field": "price","start": 0,"end": 100,"gap": 20
}
}
}
我需要检索范围的计数
0 TO 5
5 TO 10
10 TO 20
20 TO 30
30 TO 40
40 TO 50
50 TO 100
100 TO ?(NO END)
如何检索这些范围的计数的请求?
解决方法
range parameters listing shows you the available parameters及其含义。要获得5
作为差距,请使用"gap": 5
。要获取超出您范围的条目,请包括"other": "after"
:
"type": "range","field": "price","start": 0,"end": 100,"gap": 5,"other": "after"
对于您的自定义范围,您需要include the ranges explicitly。您不能将other
与range
一起使用,但是有一些解决方法:
"ranges": [
{"range": "[0,5)"},{"range": "[5,10)"},{"range": "[10,20)"},{"range": "[20,30)"},{"range": "[30,40)"},{"range": "[40,50)"},{"range": "[50,100)"},{"range": "[100,*]"},]