我有一个包含多个文档的索引。现在,我想在弹性搜索中编写一个查询,这将使我能够过滤存储桶键和doc_count
{
"aggs": {
"genres": {
"terms": {
"field": "event.keyword"
}
}
}
}
"aggregations": {
"genres": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 33,
"buckets": [
{
"key": "eone",
"doc_count": 5
}
,
{
"key": "etwo",
"doc_count": 2
}
]
}
}
我想编写查询,通过该查询可以对键名和dpc计数应用过滤器。假设我想得到键为eone并且文档数为5的结果,那么我应该只得到匹配此critera的结果
答案 0 :(得分:1)
您可以尝试使用min_doc_count
,如下所示,
{
"aggs": {
"genres": {
"terms": {
"field": "event.keyword",
"min_doc_count": 5
}
}
}
}
通过使用filter
和min_doc_count
GET index_name/_search
{
"size": 0,
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"match": {
"event.keyword": "eone"
}
}
]
}
}
}
},
"aggs": {
"genres": {
"terms": {
"field": "event.keyword",
"min_doc_count": 5
}
}
}
}
OR ,同时使用include
和min_doc_count
,如下所示,
GET index_name/_search
{
"size": 0,
"aggs": {
"genres": {
"terms": {
"field": "event.keyword",
"min_doc_count": 5,
"include" : "eone"
}
}
}
}