# Using collapse DSL queries in Kibana?

**URL:** <https://discuss.elastic.co/t/using-collapse-dsl-queries-in-kibana/328500>\
**Category:** Kibana\
**Tags:** elastic-stack-graph\
**Created:** [March 24, 2023, 9:39pm UTC](https://discuss.elastic.co/t/using-collapse-dsl-queries-in-kibana/328500 "2023-03-24T21:39:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pocketcolin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pocketcolin/32/117585_2.png) [@pocketcolin](https://discuss.elastic.co/u/pocketcolin)\
**Post date:** [March 24, 2023, 9:39pm UTC](https://discuss.elastic.co/t/using-collapse-dsl-queries-in-kibana/328500/1 "2023-03-24T21:39:15Z")

</div>

I have a DSL query that I wrote in Dev Console and I'm trying to use it in Kibana to filter down results to show in a pie chart. However, when I add the following script as a filter in Kibana, it removes the `collapse` portion of the query which is the most important part. What am I doing wrong? How do I get this complex `collapse` logic into a Kibana graph?

I am running Kibana in Elastic Cloud (v8.6.2).

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "message": "Survey response"
          }
        },
        {
          "exists": {
            "field": "labels.userId"
          }
        }
      ]
    }
  },
  "collapse": {
    "field": "labels.userId.keyword",
    "inner_hits": {
      "name": "labels.passed",
      "size": 1,
      "sort": [
        {
          "@timestamp": "desc"
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![pocketcolin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pocketcolin/32/117585_2.png) [@pocketcolin](https://discuss.elastic.co/u/pocketcolin)\
**Post date:** [March 27, 2023, 2:20pm UTC](https://discuss.elastic.co/t/using-collapse-dsl-queries-in-kibana/328500/2 "2023-03-27T14:20:35Z")

</div>

I'm pretty sure what I'm trying to do is impossible which is annoying and I hope they eventually make it possible to do DSL in Kibana. But for now I used a Transform to create a new index that only stores the most recent record and I'm building the graph from that.

---

<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:** [April 24, 2023, 2:21pm UTC](https://discuss.elastic.co/t/using-collapse-dsl-queries-in-kibana/328500/3 "2023-04-24T14:21:19Z")

</div>

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