这是我的查询 -
{
"from": 0,
"size": 100,
"query": {
"bool": {
"filter": [
{
"terms": {
"folderId.keyword": [
"ff98505e-cdff-43aa-8b05-197bc3f3265e"
],
"boost": 1
}
},
{
"terms": {
"objectType.keyword": [
"File"
],
"boost": 1
}
},
{
"term": {
"tenantId": {
"value": "34202",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggs":{
"_byformat":{
"terms":{
"field":"format.keyword",
"min_doc_count":0,
"size":200
}
}
}
}
min_doc_count = 0 的结果 -
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 0.0,
"hits" : [
{
"_index" : "plnesdv1-34202-1",
"_type" : "_doc",
"_id" : "6adbda83-53ad-457f-a2ab-d5b04c643005",
"_score" : 0.0,
"_source" : {
"format" : "vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"externalSharing" : "N",
"description" : null,
"dateModified" : null,
"type" : "application",
"folderId" : "ff98505e-cdff-43aa-8b05-197bc3f3265e",
"tags" : [ ],
"objectType" : "File",
"dateCreated" : null,
"name" : "New XLSX file",
"tenantId" : "34202",
"modifiedBy" : "rdt001",
"id" : "6adbda83-53ad-457f-a2ab-d5b04c643005",
"status" : "active",
"expirationDate" : null
}
},
{
"_index" : "plnesdv1-34202-1",
"_type" : "_doc",
"_id" : "b1000a15-2d80-41f4-a5df-ba5c27f8e9c6",
"_score" : 0.0,
"_source" : {
"format" : "vnd.ms-excel",
"externalSharing" : "N",
"description" : null,
"dateModified" : null,
"type" : "application",
"folderId" : "ff98505e-cdff-43aa-8b05-197bc3f3265e",
"tags" : [ ],
"objectType" : "File",
"dateCreated" : null,
"name" : "New XLS file",
"tenantId" : "34202",
"modifiedBy" : "rdt001",
"id" : "b1000a15-2d80-41f4-a5df-ba5c27f8e9c6",
"status" : "active",
"expirationDate" : null
}
},
{
"_index" : "plnesdv1-34202-1",
"_type" : "_doc",
"_id" : "630e9f49-3368-408d-a091-03f253127004",
"_score" : 0.0,
"_source" : {
"format" : "msword",
"externalSharing" : "N",
"description" : null,
"dateModified" : null,
"type" : "application",
"folderId" : "ff98505e-cdff-43aa-8b05-197bc3f3265e",
"tags" : [ ],
"objectType" : "File",
"dateCreated" : null,
"name" : "New DOC file",
"tenantId" : "34202",
"modifiedBy" : "rdt001",
"id" : "630e9f49-3368-408d-a091-03f253127004",
"status" : "active",
"expirationDate" : null
}
}
]
},
"aggregations" : {
"_byformat" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "msword",
"doc_count" : 1
},
{
"key" : "vnd.ms-excel",
"doc_count" : 1
},
{
"key" : "vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"doc_count" : 1
},
{
"key" : "bmp",
"doc_count" : 0
},
{
"key" : "gif",
"doc_count" : 0
},
{
"key" : "html",
"doc_count" : 0
}
]
}
}
}
min_doc_count = 1 的结果 -
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 0.0,
"hits" : [
{
"_index" : "plnesdv1-34202-1",
"_type" : "_doc",
"_id" : "6adbda83-53ad-457f-a2ab-d5b04c643005",
"_score" : 0.0,
"_source" : {
"format" : "vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"externalSharing" : "N",
"description" : null,
"dateModified" : null,
"type" : "application",
"folderId" : "ff98505e-cdff-43aa-8b05-197bc3f3265e",
"tags" : [ ],
"objectType" : "File",
"dateCreated" : null,
"name" : "New XLSX file",
"tenantId" : "34202",
"modifiedBy" : "rdt001",
"id" : "6adbda83-53ad-457f-a2ab-d5b04c643005",
"status" : "active",
"expirationDate" : null
}
},
{
"_index" : "plnesdv1-34202-1",
"_type" : "_doc",
"_id" : "b1000a15-2d80-41f4-a5df-ba5c27f8e9c6",
"_score" : 0.0,
"_source" : {
"format" : "vnd.ms-excel",
"externalSharing" : "N",
"description" : null,
"dateModified" : null,
"type" : "application",
"folderId" : "ff98505e-cdff-43aa-8b05-197bc3f3265e",
"tags" : [ ],
"objectType" : "File",
"dateCreated" : null,
"name" : "New XLS file",
"tenantId" : "34202",
"modifiedBy" : "rdt001",
"id" : "b1000a15-2d80-41f4-a5df-ba5c27f8e9c6",
"status" : "active",
"expirationDate" : null
}
},
{
"_index" : "plnesdv1-34202-1",
"_type" : "_doc",
"_id" : "630e9f49-3368-408d-a091-03f253127004",
"_score" : 0.0,
"_source" : {
"format" : "msword",
"externalSharing" : "N",
"description" : null,
"dateModified" : null,
"type" : "application",
"folderId" : "ff98505e-cdff-43aa-8b05-197bc3f3265e",
"tags" : [ ],
"objectType" : "File",
"dateCreated" : null,
"name" : "New DOC file",
"tenantId" : "34202",
"modifiedBy" : "rdt001",
"id" : "630e9f49-3368-408d-a091-03f253127004",
"status" : "active",
"expirationDate" : null
}
}
]
},
"aggregations" : {
"_byformat" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "msword",
"doc_count" : 1
},
{
"key" : "vnd.ms-excel",
"doc_count" : 1
},
{
"key" : "vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"doc_count" : 1
}
]
}
}
}
当 min_doc_count = 1 且仅获取与命中相关的存储桶时,聚合是正确的。
谁能告诉我为什么当设置 min_doc_count = 0 时聚合会获取所有存储桶。我已经浏览了弹性搜索文档,它指出这种行为是设计使然,任何其他方式都可以仅获取命中且计数为零的聚合存储桶。