Skip to content

Instantly share code, notes, and snippets.

@relwell
Created April 30, 2020 21:06
Show Gist options
  • Save relwell/f4ac915aa0fd52515be896a03e4e8b0b to your computer and use it in GitHub Desktop.
Save relwell/f4ac915aa0fd52515be896a03e4e8b0b to your computer and use it in GitHub Desktop.
nested aggregation filter?
{
"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
}
@relwell
Copy link
Author

relwell commented Apr 30, 2020

I'm trying to filter the wiki_page_edits.email aggregation by overall_status:Completed, but I keep getting no matches back. I know for a fact there are pages that satisfy that search. For example, the result of this query by ID:

{
  "took": 37,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 3.8140426,
    "hits": [
      {
        "_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": [
              "[email protected]",
              "[email protected]",
              "[email protected]",
              "[email protected]",
              "[email protected]",
              "[email protected]",
            ],
            "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",
        }
      }
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment