作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的查询-
{
"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 } ] } }}
result with 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
,
设置min_doc_count=0
还将返回存储桶,以查找与任何命中的不匹配的字词
使用min_doc_count
选项,只能返回匹配的匹配项数量超过配置的匹配项:
"aggs":{
"_byformat":{
"terms":{
"field":"format.keyword",
"min_doc_count":0,
"size":200
}
}
}
上述汇总只会返回在
0个匹配或以上中找到的关键字。 0表示所有有/无,1表示至少1个文档应具有该关键字。
关于elasticsearch - 使用min_doc_count = 0的 Elasticsearch 聚合返回与查询结果或命中无关的所有存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62593947/
我对 interval=week 和 min_doc_count=0 进行了以下聚合 { "aggs": { "scores_by_date": { "date_histogr
我是一名优秀的程序员,十分优秀!