nested

The purpose of this is to perform aggregation on the field of the nested object pointing by the path parameter, following grouping by the field of the parent document:

  • Example: The purpose is to sum the dividend amounts for each ETF in the cf_etf_dividend_nested index. Recall that the announcement field is in the nested object data type. To make the return result smaller, we only list the first three ETFs in the alphabetical order of the symbol:
"aggs": {"per_symbol":{"terms": {"field":"symbol", "size":3},
"aggs":{"total_dividend": { "nested": {"path":"announcement"},
"aggs": {"total_amount": {"sum": {"field": "announcement.amount"}}}}}}}
  • Resulting buckets: There are 7 dividends for the ACWF ETF and the total dividend is about 1.63133:
"per_symbol": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 7,"buckets": [
{"key": "ACWF","doc_count": 1,"total_dividend": {"doc_count": 7,"total_amount": {
"value": 1.6313300058245659}}},
{"key": "ACWI","doc_count": 1,"total_dividend": {"doc_count": 11,"total_amount": {"value": 6.54360693693161}}},
{"key": "ACWV","doc_count": 1,"total_dividend": {"doc_count": 10,"total_amount": {"value": 8.262333989143372}}}]}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.177.14