Nested Aggregation with Filter

I'm trying to get the counts for a given aggregation filtered against a different query.

Here's an example document:

{
        "_index": "studies_development_20200403181856384",
        "_type": "study",
        "_id": "NCT00001431",
        "_score": 3.8140426,
        "_source": {
          "nct_id": "NCT00001431",
          "study_first_submitted_date": "1999-11-03",
          "results_first_submitted_date": null,
          "disposition_first_submitted_date": null,
          "last_update_submitted_date": "2008-03-03",
          "study_first_submitted_qc_date": "2002-12-09",
          "study_first_posted_date": "2002-12-10",
          "study_first_posted_date_type": "Estimate",
          "results_first_submitted_qc_date": null,
          "results_first_posted_date": null,
          "results_first_posted_date_type": null,
          "disposition_first_submitted_qc_date": null,
          "disposition_first_posted_date": null,
          "disposition_first_posted_date_type": null,
          "last_update_submitted_qc_date": "2008-03-03",
          "last_update_posted_date": "2008-03-04",
          "last_update_posted_date_type": "Estimate",
          "start_date": "1995-02-28",
          "completion_date": "2000-11-30",
          "study_type": "Interventional",
          "acronym": null,
          "baseline_population": "",
          "brief_title": "A Phase I Trial of Gemcitabine and Radiation in Locally Advanced Unresectable Cancer of the Pancreas",
          "official_title": "A Phase I Trial of Gemcitabine and Radiation in Locally Advanced Unresectable Cancer of the Pancreas",
          "overall_status": "Completed",
          "last_known_status": null,
          "phase": "Phase 1",
          "enrollment": 20,
          "enrollment_type": null,
          "source": "National Institutes of Health Clinical Center (CC)",
          "ipd_time_frame": null,
          "ipd_access_criteria": null,
          "ipd_url": null,
          "plan_to_share_ipd_description": null,
          "created_at": "2020-04-01T18:22:27.063-04:00",
          "updated_at": "2020-04-01T18:22:27.063-04:00",
          "brief_summary": "\n      Radiotherapy plus Single-Agent Chemotherapy/Radiosensitization. Involved-field irradiation\n      using 4-15 MV photons; plus Gemcitabine, NSC-613327.\n    ",
          "detailed_description": "\n      This is a Phase I trial of gemcitabine given weekly as a 30 minute infusion administered\n      concurrently with radiation in patients with locally advanced or locally recurrent pancreatic\n      carcinoma. Patients will be treated with external beam radiation therapy in a standard\n      manner. Gemcitabine will be administered as a 30 minute infusion beginning on the first day\n      of irradiation and weekly afterwards for a total of 5 doses. Patients will be assessed\n      clinically for acute toxicity which will be graded per RTOG and DCT toxicity grading system.\n    ",
          "browse_condition_mesh_terms": [
            "Pancreatic Neoplasms",
            "Digestive System Neoplasms",
            "Neoplasms",
            "Gastrointestinal Neoplasms"
          ],
          "browse_interventions_mesh_terms": [
            "Gemcitabine",
            "Pancrelipase"
          ],
          "interventions_mesh_terms": [],
          "interventions": [],
          "facility_names": [
            "National Cancer Institute (NCI)"
          ],
          "facility_states": [
            "Maryland"
          ],
          "facility_cities": [
            "Bethesda"
          ],
          "facility_countries": [
            "United States"
          ],
          "average_rating": 0,
          "reviews": [],
          "sponsors": [
            "National Cancer Institute (NCI)"
          ],
          "rating_dimensions": [],
          "indexed_at": "2020-04-29T22:18:42.826Z",
          "wiki_page_edits": {
            "email": [
              "clinwiki-user@gmail.com",
              "clinwiki-user@gmail.com",
              "clinwiki-user@gmail.com",
              "clinwiki-user@gmail.com",
              "clinwiki-user@gmail.com",
              "clinwiki-user@gmail.com",
            ],
            "created_at": [
              "2020-04-14T17:02:58.050-04:00",
              "2020-04-14T17:03:05.728-04:00",
              "2020-04-14T17:03:14.164-04:00",
              "2020-04-25T13:05:45.006-04:00",
              "2020-04-25T14:06:28.110-04:00",
              "2020-04-29T18:18:40.715-04:00"
            ]
          },
          "wiki_text": "---\nsome: label\nwf_guts: guts\nDate of Arrest: \"-780696000000\"\nfard: tapa\n---\n## Lay Summary\n\nRadiotherapy plus Single-Agent Chemotherapy/Radiosensitization. Involved-field irradiation using 4-15 MV photons; plus Gemcitabine, NSC-613327.\n\n## Pros\n\n- One big pro\n\n## Cons\n\n- Add a con here\n\n## Ideal Patient\n\n- Add descriptions here\n\n## Contraindicated Patient\n\n- Add descriptions here\n\n## References\n\n- Here is a reference\n\n## Requests\n\n- Post open questions about study here (temporary)\n",
        }
      }

Here's the query that I have constructed to attempt to get the distinct wiki_page_edit.email with counts associated:

{
  "aggs": {
    "wiki_page_edits": {
      "nested": {
        "path": "wiki_page_edits"
      },
      "aggs": {
        "wiki_page_edits.email": {
          "filter": {
            "bool": {
              "must": [
                {
                  "bool": {
                    "must": [
                      {
                        "bool": {
                          "filter": [
                            {
                              "bool": {
                                "should": [
                                  {
                                    "bool": {
                                      "filter": [
                                        {
                                          "term": {
                                            "overall_status": {
                                              "value": "Completed"
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      },
                      {
                        "bool": {
                          "filter": [

                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          "aggs": {
            "wiki_page_edits.email": {
              "terms": {
                "field": "wiki_page_edits.email",
                "size": 1000000,
                "order": {
                  "_term": "asc"
                },
                "missing": "-99999999999"
              },
              "aggs": {
                "agg_bucket_sort": {
                  "bucket_sort": {
                    "from": 0,
                    "size": 25,
                    "sort": [
                      {
                        "_key": {
                          "order": "asc"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "*"
          }
        }
      ],
      "filter": [
        {
          "bool": {
            "must": [
              {
                "bool": {
                  "filter": [
                    {
                      "bool": {
                        "should": [
                          {
                            "bool": {
                              "filter": [
                                {
                                  "term": {
                                    "overall_status": {
                                      "value": "Completed"
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "filter": [

                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "sort": [
    {
      "nct_id": "asc"
    }
  ],
  "timeout": "11s",
  "size": 0
}

I would expect to get at least one match (given the example document in the index), but instead I get no aggregations data at all. I'm sure I have constructed the query poorly. Just looking for help -- thanks!

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