# How to Retrieve All Entities with a Specific Tag Using DQL

**URL:** <https://community.dynatrace.com/t/how-to-retrieve-all-entities-with-a-specific-tag-using-dql/51499>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed\
**Created:** [May 6, 2025, 11:11am UTC](https://community.dynatrace.com/t/how-to-retrieve-all-entities-with-a-specific-tag-using-dql/51499 "2025-05-06T11:11:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VictorRuiz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/victorruiz/32/32860_2.png) [@VictorRuiz](https://community.dynatrace.com/u/VictorRuiz)\
**Post date:** [May 6, 2025, 11:11am UTC](https://community.dynatrace.com/t/how-to-retrieve-all-entities-with-a-specific-tag-using-dql/51499/1 "2025-05-06T11:11:47Z")

</div>

Dear DQL Masters,

I have the following use case:

- I need to know all the entities that have a tag using DQL. For example I need to know all the entities, no matter if they are hosts, services, process groups, synthetics… and that contain a specific tag.

- I have created the following DQL:

fetch dt.entity.host  
| fieldsAdd tags  
| expand tags  
| filter contains(toString(tags), “APP:TEST”)  
| parse tags, “ld:key ‘:’ ld:tag\_value”  
| lookup [fetch dt.entity.service], lookupField: id, prefix:“lookup.affected.entity.services”  
| lookup [fetch dt.entity.application], lookupField: id, prefix:“lookup.affected.entity.applications”  
| lookup [fetch dt.entity.mobile\_application], lookupField: id, prefix:“lookup.affected.entity.mobile”  
| lookup [fetch dt.entity.custom\_application], lookupField: id, prefix:“lookup.affected.entity.customapplication”  
| lookup [fetch dt.entity.cloud\_application], lookupField: id, prefix:“lookup.affected.entity.cloudapplication”  
| lookup [fetch dt.entity.synthetic\_test], lookupField: id, prefix:“lookup.affected.entity.synthetictest”  
| lookup [fetch dt.entity.multiprotocol\_monitor], lookupField: id, prefix:“lookup.affected.entity.multiprotocolmonitor”  
| lookup [fetch dt.entity.custom\_device], lookupField: id, prefix:“lookup.affected.entity.customdevices”  
| lookup [fetch dt.entity.environment], lookupField: id, prefix:“lookup.affected.entity.environment”

But in the results it only shows me entities type hosts.

Is there any way to get all the entities that have this label using DQL?

Thanks a lot for your time

---

<div class="post-metadata">

**Author:** ![Etienne1](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@Etienne1](https://community.dynatrace.com/u/Etienne1)\
**Post date:** [May 6, 2025, 11:58am UTC](https://community.dynatrace.com/t/how-to-retrieve-all-entities-with-a-specific-tag-using-dql/51499/2 "2025-05-06T11:58:17Z")

</div>

Hello

here’s how I did it, you should use :

| expand tags

| filter matchesvalue(tags, ‘Yourtags’)

here’s an example of what I did

```auto
fetch events
| filter matchesvalue(event.description, "*Host shutdown*") or matchesvalue(event.description, "*Host gracefully rebooted*")
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id
| fieldsAdd tags = lookup.tags
| fieldsAdd lookup.hostGroupName
| expand tags
| filter matchesValue(tags,"Function:BDD-MSSQL") or matchesValue(tags,"[Environment]Function:EDITION") or matchesValue(tags,"[Environment]Function:WEB") or matchesValue(tags,"Function:APP")
| parse tags, """DATA * "Function:"LD:"Name""""
| fields event.start, event.end, Name, event.description
| sort Name,event.description asc

```

 ![Etienne1_0-1746532619688.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/1/f12a8b8672386e6bc1148f59ee1d95d01d31d246.png)
