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

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.

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