# Extract domain with grok

**URL:** https://discuss.elastic.co/t/extract-domain-with-grok/103156
**Category:** Logstash
**Created:** [October 8, 2017, 4:29pm UTC](https://discuss.elastic.co/t/extract-domain-with-grok/103156 "2017-10-08T16:29:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Shoham\_Ben\_Shitrit](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@Shoham\_Ben\_Shitrit](https://discuss.elastic.co/u/Shoham_Ben_Shitrit)
#### Post date: [October 8, 2017, 4:29pm UTC](https://discuss.elastic.co/t/extract-domain-with-grok/103156/1 "2017-10-08T16:29:48Z")

</div>

I'd like to make the simplest grok filter, just to extract domain from url For example, for the url  
`https://discuss.elastic.co/top/all`  
I'd like to get the result  
`discuss.elastic.co`  
I tried to do so with the filter  
`%{URIPROTO}://%{URIHOST:domain}`  
And it did extract me [stackoverflow.com](http://stackoverflow.com), but when I use a different url that has www at the start for example `https://www.elastic.co/`  
the result is  
`www.elastic.co`  
is there a filter that could return me the domain alone, without www?  
Thank you!

---

<div class="post-metadata">

### Author: ![Rodolphe\_Redoute](https://avatars.discourse-cdn.com/v4/letter/r/eb9ed0/32.png) [@Rodolphe\_Redoute](https://discuss.elastic.co/u/Rodolphe_Redoute)
#### Post date: [October 10, 2017, 8:54am UTC](https://discuss.elastic.co/t/extract-domain-with-grok/103156/2 "2017-10-10T08:54:46Z")

</div>

after your grok you could add a mutate like this :

`mutate { gsub => ["domain", "(www.)", ""] }`  
if there is the pattern "www." then it should be replaced by "" and if there isn't the pattern then nothing is made

---

<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: [November 7, 2017, 8:55am UTC](https://discuss.elastic.co/t/extract-domain-with-grok/103156/3 "2017-11-07T08:55:29Z")

</div>

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