# How do I query elasticsearch in a way that returns entire rows instead of nested buckets?

**URL:** <https://discuss.elastic.co/t/how-do-i-query-elasticsearch-in-a-way-that-returns-entire-rows-instead-of-nested-buckets/134583>\
**Category:** Elasticsearch\
**Created:** [June 5, 2018, 9:51am UTC](https://discuss.elastic.co/t/how-do-i-query-elasticsearch-in-a-way-that-returns-entire-rows-instead-of-nested-buckets/134583 "2018-06-05T09:51:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dennis.1157](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dennis.1157](https://discuss.elastic.co/u/dennis.1157)\
**Post date:** [June 5, 2018, 9:51am UTC](https://discuss.elastic.co/t/how-do-i-query-elasticsearch-in-a-way-that-returns-entire-rows-instead-of-nested-buckets/134583/1 "2018-06-05T09:51:45Z")

</div>

The request body for my data table with 7 columns on Kibana looks like this:

```
{
  "aggs": {
    "2": {
      "terms": {
        "field": "efe_board",
        "size": 999,
        "order": {
          "_count": "desc"
        }
      },
      "aggs": {
        "3": {
          "terms": {
            "field": "efe_fid",
            "size": 999,
            "order": {
              "_count": "desc"
            }
          },
          "aggs": {
            "4": {
              "terms": {
                "field": "efe_die",
                "size": 5,
                "order": {
                  "_count": "desc"
                }
              },
              "aggs": {
                "5": {
                  "terms": {
                    "field": "efe_cycle",
                    "size": 5,
                    "order": {
                      "_count": "desc"
                    }
                  },
                  "aggs": {
                    "6": {
                      "terms": {
                        "field": "efe_block",
                        "size": 5,
                        "order": {
                          "_count": "desc"
                        }
                      },
                      "aggs": {
                        "7": {
                          "terms": {
                            "field": "efe_page",
                            "size": 5,
                            "order": {
                              "_count": "desc"
                            }
                          },
                          "aggs": {
                            "8": {
                              "terms": {
                                "field": "efe_page_type",
                                "size": 5,
                                "order": {
                                  "_count": "desc"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  ...
 }

```

If I want to create an entire table (maybe as a pandas DataFrame), I would have to use either recursion or deeply nested for-loops to access the buckets, extract the data, store them in a list of dictionaries and convert said list to a DF.

I'd like to know if there is a better way to achieve the same effect without having to access nested buckets WHILE addressing the issue of omitted rows at the same time e.g. if there's no data `efe_fid`, the remaining nested fields are not queried.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 3, 2018, 9:51am UTC](https://discuss.elastic.co/t/how-do-i-query-elasticsearch-in-a-way-that-returns-entire-rows-instead-of-nested-buckets/134583/2 "2018-07-03T09:51:46Z")

</div>

Closed on July 3, 2018, 9:51am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
