Jquery 带范围计数的Agg计数
我的医生看起来像Jquery 带范围计数的Agg计数,jquery,elasticsearch,aggregation,Jquery,elasticsearch,Aggregation,我的医生看起来像 { "path": "/foo/bar", "userId" : "33", } 我想有一个用户ID谁拥有超过 100份文件 在50到100个文档之间 少于100份文件 我尝试使用不同的聚合,但我不知道如何对另一个聚合的计数进行范围聚合 感谢您的帮助,您需要与一起使用,以便根据他们的文档数分离用户ID 在下面的示例中,考虑5个文件:“代码> USEID”:“33”,3个文件
{
"path": "/foo/bar",
"userId" : "33",
}
我想有一个用户ID谁拥有超过
100份文件
在50到100个文档之间
少于100份文件
我尝试使用不同的聚合,但我不知道如何对另一个聚合的计数进行范围聚合
感谢您的帮助,您需要与一起使用,以便根据他们的文档数分离用户ID
在下面的示例中,考虑5个文件:“代码> USEID”:“33”<代码>,3个文件“USEID”:“34”和1个文件“<代码> USEID”:“35”< /代码>。现在,搜索查询将根据
{
"path": "/foo/bar",
"userId" : "34"
}
{
"path": "/foo/bar",
"userId" : "34"
}
{
"path": "/foo/bar",
"userId" : "34"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "35"
}
{
"size": 0,
"aggs": {
"userId_lessThanEqualTo2": {
"terms": {
"field": "userId.keyword"
},
"aggs": {
"less_than_2": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count < 2"
}
}
}
},
"userId_btw2-4": {
"terms": {
"field": "userId.keyword"
},
"aggs": {
"less_than_4": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count >= 2 && params.the_doc_count < 4"
}
}
}
},
"userId_greaterThanEqualTo4": {
"terms": {
"field": "userId.keyword"
},
"aggs": {
"greater_than_4": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count >= 4"
}
}
}
}
}
}
"aggregations": {
"userId_btw2-4": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "34",
"doc_count": 3
}
]
},
"userId_greaterThanEqualTo4": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "33",
"doc_count": 5
}
]
},
"userId_lessThanEqualTo2": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "35",
"doc_count": 1
}
]
}
}
搜索查询:
{
"path": "/foo/bar",
"userId" : "34"
}
{
"path": "/foo/bar",
"userId" : "34"
}
{
"path": "/foo/bar",
"userId" : "34"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "33"
}
{
"path": "/foo/bar",
"userId" : "35"
}
{
"size": 0,
"aggs": {
"userId_lessThanEqualTo2": {
"terms": {
"field": "userId.keyword"
},
"aggs": {
"less_than_2": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count < 2"
}
}
}
},
"userId_btw2-4": {
"terms": {
"field": "userId.keyword"
},
"aggs": {
"less_than_4": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count >= 2 && params.the_doc_count < 4"
}
}
}
},
"userId_greaterThanEqualTo4": {
"terms": {
"field": "userId.keyword"
},
"aggs": {
"greater_than_4": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count >= 4"
}
}
}
}
}
}
"aggregations": {
"userId_btw2-4": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "34",
"doc_count": 3
}
]
},
"userId_greaterThanEqualTo4": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "33",
"doc_count": 5
}
]
},
"userId_lessThanEqualTo2": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "35",
"doc_count": 1
}
]
}
}
谢谢你的帮助。
我尝试了一下,搜索结果是:
"aggregations": {
"userId_btw2-4": {
"doc_count_error_upper_bound" : 2125,
"sum_other_doc_count" : 2482161,
"buckets": []
},
"userId_greaterThanEqualTo4": {
"doc_count_error_upper_bound" : 2125,
"sum_other_doc_count" : 2482138,
"buckets" : [
{
"key" : "804ba398-e512-4e43-a289-3e63483baabd",
"doc_count" : 13914
},
{
"key" : "de0ce908-7172-4be7-8e3e-181d94fb0571",
"doc_count" : 8561
},
{
"key" : "03670858-cb0b-4ca5-ae5a-07e92b12905f",
"doc_count" : 4918
},
{
"key" : "25a17282-2eb0-4a1f-8fdd-b0eef083af25",
"doc_count" : 4847
},
{
"key" : "c096169d-0bb3-42d2-8c24-92fa15754339",
"doc_count" : 4265
},
{
"key" : "9ff15fdc-2aa3-49a6-8422-4d7137f434ae",
"doc_count" : 4159
},
{
"key" : "ce77b5c0-e858-47a6-8598-879d78124857",
"doc_count" : 3730
},
{
"key" : "171bf337-8c19-4180-ba21-2ec9e72e380f",
"doc_count" : 3513
},
{
"key" : "745dd8e0-a021-4c91-abd8-2193e1805fd0",
"doc_count" : 3245
},
{
"key" : "e6645d55-a411-44c3-82db-1a5be1534e5e",
"doc_count" : 3051
}
]
},
"userId_lessThanEqualTo2": {
"doc_count_error_upper_bound" : 2125,
"sum_other_doc_count" : 2482161,
"buckets": []
}
}
@user2478384请仔细阅读答案,并让我知道这是否解决了您的问题?@user2478384欢迎使用Stackoverflow!!如果答案帮助你解决了问题,那么请不要忘记接受答案。你可以通过点击答案旁边的复选标记来接受答案:-)@user2478384你能回复我之前的评论吗?