# How can I drop the domain from host.name field in logstash?

**URL:** <https://discuss.elastic.co/t/how-can-i-drop-the-domain-from-host-name-field-in-logstash/267031>\
**Category:** Logstash\
**Created:** [March 12, 2021, 4:42am UTC](https://discuss.elastic.co/t/how-can-i-drop-the-domain-from-host-name-field-in-logstash/267031 "2021-03-12T04:42:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ishaan](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ishaan](https://discuss.elastic.co/u/Ishaan)\
**Post date:** [March 12, 2021, 4:42am UTC](https://discuss.elastic.co/t/how-can-i-drop-the-domain-from-host-name-field-in-logstash/267031/1 "2021-03-12T04:42:14Z")

</div>

I want to remove domain from host.name field coming from metricbeat.

For example:  
host.name = [abcd.xyz.com](http://abcd.xyz.com)  
host.name = [abc@xyz.com](mailto:abc@xyz.com)

I want to remove everything after . or @ or any other delimiter to save the value of host.name field like:

host.name = abcd  
host.name = abc

How can I do that in logstash?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 12, 2021, 3:44pm UTC](https://discuss.elastic.co/t/how-can-i-drop-the-domain-from-host-name-field-in-logstash/267031/2 "2021-03-12T15:44:26Z")

</div>

You could try it using a mutate filter

```
mutate { gsub => ["[host][name]", "([A-Za-z0-9_]*)[\.@].*", "\1" ] }
```

---

<div class="post-metadata">

**Author:** ![Ishaan](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ishaan](https://discuss.elastic.co/u/Ishaan)\
**Post date:** [March 12, 2021, 4:00pm UTC](https://discuss.elastic.co/t/how-can-i-drop-the-domain-from-host-name-field-in-logstash/267031/3 "2021-03-12T16:00:56Z")

</div>

Is this expression storing the substring in [host][name] before . or @?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 12, 2021, 4:03pm UTC](https://discuss.elastic.co/t/how-can-i-drop-the-domain-from-host-name-field-in-logstash/267031/4 "2021-03-12T16:03:48Z")

</div>

It uses a capture group (the parentheses around `[A-Za-z0-9_]*`), and references the first capture group in the substitution using `\1`.

---

<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 9, 2021, 4:04pm UTC](https://discuss.elastic.co/t/how-can-i-drop-the-domain-from-host-name-field-in-logstash/267031/5 "2021-04-09T16:04:18Z")

</div>

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