[英]Can Elasticsearch suggest range for query on number fields?
For example I have a list of person with have age
property. 例如,我有一个具有
age
属性的人的列表。
On my search page, I allow user to query this list base on the range of age: 在搜索页面上,我允许用户根据年龄范围查询此列表:
"mus" : {
"range" : {
"age" : { "from" : 60, "to" : 80 }
}
},
Let say the above query return 0 result (since my list include only person from 20 to 50), do ES support any method to return the suggestion for this range query (in this case [20, 50])? 假设上述查询返回0个结果(由于我的列表仅包含20至50个人),ES是否支持任何方法返回此范围查询的建议(在本例中为[20,50])?
Yes, you can use the histogram
aggregation in order to retrieve these counts. 是的,您可以使用
histogram
聚合来检索这些计数。
{
"post_filter": {
"bool": {
"must": {
"range": {
"age": {
"from": 60,
"to": 80
}
}
}
}
},
"aggs": {
"ages": {
"histogram": {
"field": "age",
"interval": 10
}
}
}
}
The above query would return: 上面的查询将返回:
age
field is between 60 and 80 age
在60至80 age
之间的文件 age
field is within 10-year buckets, ie age
字段在10年以内的文档数,即
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.