# Will the "collapse" clause work in Kibana's Alert type "Query DSL"

**URL:** <https://discuss.elastic.co/t/will-the-collapse-clause-work-in-kibanas-alert-type-query-dsl/334726>\
**Category:** Kibana\
**Tags:** elastic-stack-alerting\
**Created:** [May 30, 2023, 9:53pm UTC](https://discuss.elastic.co/t/will-the-collapse-clause-work-in-kibanas-alert-type-query-dsl/334726 "2023-05-30T21:53:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayesh.patel](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@jayesh.patel](https://discuss.elastic.co/u/jayesh.patel)\
**Post date:** [May 30, 2023, 9:53pm UTC](https://discuss.elastic.co/t/will-the-collapse-clause-work-in-kibanas-alert-type-query-dsl/334726/1 "2023-05-30T21:53:23Z")

</div>

Hi, In kibana 8.6, I am trying to create and Alert of type "Query DSL". In the DSL query, I wanted to pick the lastest document, which breached the filesystem used percentage great than 80% for each cloud.instance. Seems like Elasticsearch provides the "collapse" clause, which can be used for grouping and picking the lastest document using sort.  
Will the following DSL query work in Kibana's Alert type "Quey DSL"? Meaning.. Will the "collapse" clause work in Kibana's Alert type "Query DSL"?

```auto
 {
  "size": 500,
  "query": {
    "bool" : {
      "must" : {
        "range" : {
		  "system.filesystem.used.pct" : { "gte" : 80 }
		}
      },
      "must_not" : {
        "term" : { "system.filesystem.mount_point" : "/boot" }
      },
	}
  },
  "collapse": {
    "field": "cloud.instance.name",
	"inner_hits": {
	  "name": "latest",
	  "size": 1,
	  "sort": [{"@timestamp": {"order": "desc"}}]
	}
  }
}

```

---

<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:** [June 27, 2023, 9:53pm UTC](https://discuss.elastic.co/t/will-the-collapse-clause-work-in-kibanas-alert-type-query-dsl/334726/2 "2023-06-27T21:53:24Z")

</div>

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