# Entity Selector host custom metadata

**URL:** <https://community.dynatrace.com/t/entity-selector-host-custom-metadata/41336>\
**Category:** Dynatrace Tips\
**Tags:** entity-selector, forum-tip\
**Created:** [August 24, 2023, 1:01am UTC](https://community.dynatrace.com/t/entity-selector-host-custom-metadata/41336 "2023-08-24T01:01:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![axel\_tapia](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@axel\_tapia](https://community.dynatrace.com/u/axel_tapia)\
**Post date:** [August 24, 2023, 1:01am UTC](https://community.dynatrace.com/t/entity-selector-host-custom-metadata/41336/1 "2023-08-24T01:01:09Z")

</div>

Today I spend most of my day trying to find an example for entitySelector where certain custom host metadata is present (or not present), after asking dynatrace support finally fot the right syntax for this

just want to share this as I was unable to find documentation or post related to this.

my starting point was a post from the community:&nbsp;[https://community.dynatrace.com/t5/Open-Q-A/Entity-Selector/td-p/205554](https://community.dynatrace.com/topic/205554)&nbsp;however the details I needed were not part of the post

First, I don’t know all the “sources” for customHostMetadata, you can start querying a single HOST to get the customHostMetadata using entities api (notice the fields, I am grabbing only **properties.customHostMetadata** )

```auto
https://dt-host/e/[env-id]/api/v2/entities?entitySelector=type(HOST),entityId(HOST-X)&fields=properties.customHostMetadata

```

Result will be something like:

```javascript
{
   "totalCount":1,
   "pageSize":50,
   "entities":[
      {
         "entityId":"HOST-XXXXXXXXXXXXX",
         "type":"HOST",
         "displayName":"random.madeup.server",
         "properties":{
            "customHostMetadata":[
               {
                  "value":"hello",
                  "key":{
                     "source":"ENVIRONMENT",
                     "key":"myRealMetadata"
                  }
               }
            ]
         }
      }
   ]
}

```

each value from customHostMetadata will contain source, key and value (if present), source is used in the next step

Now, the actual examples:

get all host where **ENVIRONMENT** (source) metada with name:&nbsp; **myRealMetadata** exists (regardless its value)

```auto
entitySelector=type(HOST),customHostMetadata([ENVIRONMENT]myRealMetadata)

```

the opposite (adding the “negate” statement):

```auto
entitySelector=type(HOST),not(customHostMetadata([ENVIRONMENT]myRealMetadata))

```

get all host where environment metada with name:&nbsp; **myRealMetadata** exists and has the value “ **hello** ”

```auto
entitySelector=type(HOST),customHostMetadata([ENVIRONMENT]myRealMetadata:hello)

```

---

<div class="post-metadata">

**Author:** ![36Krazyfists](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/36krazyfists/32/37434_2.png) [@36Krazyfists](https://community.dynatrace.com/u/36Krazyfists)\
**Post date:** [June 18, 2024, 4:16pm UTC](https://community.dynatrace.com/t/entity-selector-host-custom-metadata/41336/2 "2024-06-18T16:16:02Z")

</div>

Good stuff. I found this in my search for how to create custom metadata for entities.&nbsp; Specifically, custom entities that I’ve created through the Metrics Ingest API v2 or Extensions 2.0.&nbsp; I can find info in their docs about setting metadata for metrics, but nothing about metadata for Entities.

I know I can go in the **Topology model** settings and create rules to extract metric dimensions into custom entities with attributes, but I’m not sure if that’s the same thing as metadata or properties or whatever?&nbsp; Their docs are kind of all over the place and sort of vague…
