对术语使用缺少的聚合,而不是字段
我希望这是问这个问题的好地方。我正在尝试获取不包含特定字段的项的聚合。它们是具有嵌套字段的项,如下所示:对术语使用缺少的聚合,而不是字段,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我希望这是问这个问题的好地方。我正在尝试获取不包含特定字段的项的聚合。它们是具有嵌套字段的项,如下所示: "customFields": [ { "key": "firstType", "keywordValue": "1" }, { "key"
"customFields": [
{
"key": "firstType",
"keywordValue": "1"
},
{
"key": "secondType",
"keywordValue": "A"
}
]
如果我试图查找所有不包含值为firstType的键但运气不好的项,那么我一直在尝试使用缺少的聚合。我的问题是:
"aggregations": {
"custom.firstType": {
"missing": {
"field": "firstType"
},
"aggregations": {
"values": {
"reverse_nested": {}
}
}
}
}
不幸的是,这对我来说不是什么好运气。我在看什么
谢谢 缺失聚合用于查找不包含给定字段(非值)的文档 第二个文档不包含字段“价格”。要查找所有没有价格的产品,您将使用缺失聚合 如果您希望在没有特定值的文档上进行聚合,则需要将嵌套聚合与过滤器子聚合一起使用 映射:
PUT index19
{
"mappings": {
"properties": {
"customFields": {
"type": "nested",
"properties": {
"key": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"keywordValue":{
"type":"integer"
}
}
}
}
}
}
查询:
GET index19/_search
{
"size": 0,
"aggs": {
"without_firsttype": {
"nested": {
"path": "customFields"
},
"aggs": {
"key_check": {
"filter": {
"bool": {
"must_not": [
{
"term": {
"customFields.key.keyword": {
"value": "firstType"
}
}
}
]
}
},
"aggs": {
"Document": {
"reverse_nested": {}
}
}
}
}
}
}
}
结果:
"aggregations" : {
"without_firsttype" : {
"doc_count" : 4,
"key_check" : {
"doc_count" : 3,
"Document" : {
"doc_count" : 2
}
}
}
}
"aggregations" : {
"without_firsttype" : {
"doc_count" : 4,
"key_check" : {
"doc_count" : 3,
"Document" : {
"doc_count" : 2
}
}
}
}