ElasticSearch过滤器聚合中的空子桶列表

时间:2018-05-22 11:06:05

标签: elasticsearch

我有一个带有过滤器的多级聚合,我得到了没有匹配过滤器的桶的空结果。我想要消除那些桶。

我尝试指定

文档+查询

GET test/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "type": {
      "terms": {
        "field": "type.keyword",
        "size": 10
      },
      "aggs": {
        "languages": {
          "filter": {
            "term": {
              "sub_type.keyword": "fdsfsd"
            }
          },
          "aggs": {
            "sub_type": {
              "terms": {
                "field": "sub_type.keyword",
                 "min_doc_count": 1
                "size": 10
              }
            }
          }
        }
      }
    }
  }
}

响应:

      "buckets": [
        {
          "key": "language",
          "doc_count": 1,
          "languages": {
            "doc_count": 0,
            "sub_type": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": []
            }
          }
        }

1 个答案:

答案 0 :(得分:0)

试一试

GET test/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "type": {
      "terms": {
        "field": "type.keyword",
        "min_doc_count": 1, 
        "size": 10
      },
      "aggs": {
        "languages": {
          "filter": {
            "term": {
              "sub_type.keyword": "fdsfsd"
            }
          },
          "aggs": {
            "sub_type": {
              "terms": {
                "field": "sub_type.keyword",
                "min_doc_count": 1,
                "size": 10
              }
            }
          }
        }
      }
    }
  }
}

<强>更改

在顶级聚合时指定 min_doc_count