我有一个带有以下映射的elasticsearch索引:
{
"properties":{
"asset":{
"properties":{
"customerId":{
"type":"long"
}
}
},
"software":{
"type": "nested",
"properties":{
"id":{
"type":"long"
},
... (more properties)
}
}
}
可能存在一些具有"software":null
的文档当对软件属性(例如id)执行嵌套过滤器聚合时,过滤器聚合中的doc_count也包括那些为null的软件。
聚合看起来像这样:
"aggregations": {
"aggs": {
"nested": {
"path": "software"
},
"aggregations": {
"filtered": {
"filter": {
"term": {
"software.type": {
"value": "Application",
"boost": 1.0
}
}
},
"aggregations": {
"software_ids": {
"terms": {
"field": "software.id",
"min_doc_count": 1,
"shard_min_doc_count": 0
}
}
}
}
}
}
}
回应的部分:
"aggregations": {
"aggs": {
"doc_count": 129958,
"filtered": {
**"doc_count": 7094,**
这个doc_count包括“软件”:null有没有办法排除它们?
编辑:我考虑过对内部术语聚合使用“缺失”参数(即对于过滤器聚合内的聚合)。但是想知道是否有任何方法可以完全从聚合中排除这种“嵌套”空值。
Missing归于救援。
使用“缺失”属性,您可以指定字段缺失时字段应采用的值。您可以将值指定为“JUNK”,然后文档将在聚合中的JUNK存储桶中登陆。
以下应该现在工作。
"aggregations": {
"aggs": {
"nested": {
"path": "software"
},
"aggregations": {
"filtered": {
"filter": {
"term": {
"software.type": {
"value": "Application",
"boost": 1.0
}
}
},
"aggregations": {
"software_ids": {
"terms": {
"field": "software.id",
"min_doc_count": 1,
"shard_min_doc_count": 0,
"missing": "JUNK"
}
}
}
}
}
}
}