问题描述
我对Elasticsearch世界真的很陌生。
I am really new to elasticsearch world.
假设我在两个字段上嵌套嵌套: field1
和 field2
:
Let's say I have a nested aggregation on two fields : field1
and field2
:
{
...
aggs: {
field1: {
terms: {
field: 'field1'
},
aggs: {
field2: {
terms: {
field: 'field2'
}
}
}
}
}
}
这段代码可以很好地工作,并且给我这样的东西:
This piece of code works perfectly and gives me something like this :
aggregations: {
field1: {
buckets: [{
key: "foo",
doc_count: 123456,
field2: {
buckets: [{
key: "bar",
doc_count: 34323
},{
key: "baz",
doc_count: 10
},{
key: "foobar",
doc_count: 36785
},
...
]
},{
key: "fooOO",
doc_count: 423424,
field2: {
buckets: [{
key: "bar",
doc_count: 35
},{
key: "baz",
doc_count: 2435453
},
...
]
},
...
]
}
}
现在,我需要排除例如 doc_count
小于1000的所有聚合结果,而改为:
Now, my need is to exclude all aggregation results where doc_count
is less than 1000 for instance and get this instead :
aggregations: {
field1: {
buckets: [{
key: "foo",
doc_count: 123456,
field2: {
buckets: [{
key: "bar",
doc_count: 34323
},{
key: "foobar",
doc_count: 36785
},
...
]
},{
key: "fooOO",
doc_count: 423424,
field2: {
buckets: [{
key: "baz",
doc_count: 2435453
},
...
]
},
...
]
}
}
是否可以在查询正文中设置此需求?还是我必须在调用者布局中执行过滤器(在我的情况下为javascript)?
Is it possible to set this need in the query body ? or do I have to perform the filter in the caller layout (in javascript in my case)?
预先感谢
推荐答案
下次,M'sieur Toph':RTFM !!!
Next time, M'sieur Toph' : RTFM !!!
我真的很傻:我找到了答案在手册中,询问后30秒。
我不会删除我的问题,因为它可以帮助,谁知道...
I feel really dumb: I found the anwser in the manual, 30 seconds after asking.I don't remove my question because, it can help, who knows...
这是答案:
您可以在条款
聚合中指定 min_doc_count
属性。
You can specify the min_doc_count
property in the terms
aggregation.
它给您:
{
...
aggs: {
field1: {
terms: {
field: 'field1',
min_doc_count: 1000
},
aggs: {
field2: {
terms: {
field: 'field2',
min_doc_count: 1000
}
}
}
}
}
}
您还可以为汇总的每个级别指定特定的最小计数
You also can specify a specific minimal count for each level of your aggregation.
还有什么? :)
这篇关于最少文档数的Elasticsearch过滤器聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!