Can't get empty buckets with nested, terms aggregation


(Seongjun Kang) #1

Elasticsearch version: 2.3.1

Description of the problem including expected versus actual behavior:
Hi I'm trying to use nested, terms aggregation including empty bucket as search result.
Problem is when I send nested, terms aggregation query with min_doc_count: 0 option, I can't get empty buckets. But when I send not nested terms aggregation, result is same as I expected (it includes empty buckets with value of null or 0).

For example below works well (without nested) :

{
  "size":0,
  "query":{
    "bool":{  
      "filter":[
        {
          "range":{
            "date":{
              "time_zone":"+09:00",
              "format":"yyyy-MM-dd",
              "gte":"2016-11-01||/d",
              "lt":"2016-11-01||+1d/d"
            }
          }
        }
      ]
    }
  },
  "aggs":{  
    "item_name":{  
      "terms":{  
        "field":"name",
        "min_doc_count":0,
        "size":0
      },
      "aggs":{  
        "price_sum":{  
          "sum":{  
            "field":"price"
          }
        }
      }
    }
  }
}

Above query returns below:

{  
  "took":1,
  "timed_out":false,
  "_shards":{  
    "total":1,
    "successful":1,
    "failed":0
  },
  "hits":{  
    "total":0,
    "max_score":0,
    "hits":[]
  },
  "aggregations":{  
    "name":{  
      "doc_count_error_upper_bound":0,
      "sum_other_doc_count":0,
      "buckets":[  
        {  
          "key":"key1",
          "doc_count":0,
          "price_sum":{  
            "value":0
          }
        },
        {  
          "key":"key2",
          "doc_count":0,
          "price_sum":{  
            "value":0
          }
        }
      ]
    }
  }
}

Now below query is what I'd like to send (aggregation with nested, item.property):

{  
  "size":0,
  "query":{  
    "bool":{  
      "filter":[  
        {  
          "range":{  
            "date":{  
              "time_zone":"+09:00",
              "format":"yyyy-MM-dd",
              "gte":"2016-11-01||/d",
              "lt":"2016-11-01||+1d/d"
            }
          }
        }
      ]
    }
  },
  "aggs":{  
    "lines":{  
      "nested":{  
        "path":"property"
      },
      "aggs":{  
        "property_types":{  
          "terms":{  
            "field":"property.type",
            "size":0
          },
          "aggs":{  
            "some_value_of_property_sum":{  
              "sum":{  
                "field":"property.some_value"
              }
            }
          }
        }
      }
    }
  }
}

But it returns below :

{  
  "took":1,
  "timed_out":false,
  "_shards":{  
    "total":1,
    "successful":1,
    "failed":0
  },
  "hits":{  
    "total":0,
    "max_score":0,
    "hits":[]
  },
  "aggregations":{  
    "property_types":{  
      "doc_count":0,
      "some_value_of_property_sum":{  
        "doc_count_error_upper_bound":0,
        "sum_other_doc_count":0,
        "buckets":[]
      }
    }
  }
}

while I expect below :

"buckets":[  
  {
    "key":"key1",
    "doc_count":0,
    "some_value_of_property_sum":{
      "value":0
    }
  },
  {
    "key":"key2",
    "doc_count":0,
    "some_value_of_property_sum":{
      "value":0
    }
  }
]

What am I doing wrong?


(system) #2