# Clean and split email address into two new fields

**URL:** <https://discuss.elastic.co/t/clean-and-split-email-address-into-two-new-fields/267489>\
**Category:** Logstash\
**Tags:** ingest-pipeline\
**Created:** [March 17, 2021, 11:30am UTC](https://discuss.elastic.co/t/clean-and-split-email-address-into-two-new-fields/267489 "2021-03-17T11:30:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cibernicola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cibernicola/32/85621_2.png) [@cibernicola](https://discuss.elastic.co/u/cibernicola)\
**Post date:** [March 17, 2021, 11:30am UTC](https://discuss.elastic.co/t/clean-and-split-email-address-into-two-new-fields/267489/1 "2021-03-17T11:30:08Z")

</div>

Hello

I have a field from a csv file called email, this field contains a string like this: `mailtio:user@domain.tld`  
I'm trying to remove "mailto:" as first step, then, copying field to a temp. one split the result into two new fields "user" and "provider"

An approach to reach this is something like:

```
		 mutate {copy => { "email" => "email_tmp" }}
		 mutate{
			split => {"email_tmp" => "@"}
				add_field => ["user", "%{[email_tmp][0]}"]
				add_field => ["provider","%{[email_tmp[1]}"]
			}

```

But its not working and I have no clue why (yes, I'm using verbose to see the logs, no luck).  
What m ' doing wrong?  
Thanks in advance.

---

<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 17, 2021, 4:57pm UTC](https://discuss.elastic.co/t/clean-and-split-email-address-into-two-new-fields/267489/2 "2021-03-17T16:57:35Z")

</div>

> [@cibernicola](#):
>
> ```auto
> add_field => ["user", "%{[email_tmp][0]}"]
> add_field => ["provider","%{[email_tmp[1]}"]
> 
> ```

The second field reference is invalid (it is missing a bracket). Try

```
mutate { copy => { "email" => "[@metadata][email_tmp]" } }
mutate { gsub => ["[@metadata][email_tmp]", "^mailto:", "" ] }
mutate {
    split => { "[@metadata][email_tmp]" => "@" }
    add_field => {
        "user" => "%{[@metadata][email_tmp][0]}"]
        "provider" => "%{[@metadata][email_tmp][1]}"]
    }
}

```

---

<div class="post-metadata">

**Author:** ![cibernicola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cibernicola/32/85621_2.png) [@cibernicola](https://discuss.elastic.co/u/cibernicola)\
**Post date:** [March 17, 2021, 5:45pm UTC](https://discuss.elastic.co/t/clean-and-split-email-address-into-two-new-fields/267489/3 "2021-03-17T17:45:53Z")

</div>

> [@Badger](#):
>
> ```auto
> mutate {
> split => { "[@metadata][email_tmp]" => "@" }
> add_field => {
> "user" => "%{[@metadata][email_tmp][0]}"]
> "provider" => "%{[@metadata][email_tmp][1]}"]
> }
> }
> 
> ```

I was waiting for you! Thanks, its working!!!! But it needs two claudators

```
mutate { copy => { "email" => "[@metadata][email_tmp]" } }
mutate { gsub => ["[@metadata][email_tmp]", "^mailto:", "" ] }
mutate {
    split => { "[@metadata][email_tmp]" => "@" }
    add_field => {
        "user" => "[%{[@metadata][email_tmp][0]}"]
        "provider" => ["%{[@metadata][email_tmp][1]}"]
    }
}

```

Again, thanks!

---

<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 17, 2021, 6:16pm UTC](https://discuss.elastic.co/t/clean-and-split-email-address-into-two-new-fields/267489/4 "2021-03-17T18:16:17Z")

</div>

> [@Badger](#):
>
> ```auto
> "user" => "%{[@metadata][email_tmp][0]}"]
> "provider" => "%{[@metadata][email_tmp][1]}"]
> 
> ```

Sorry, that should have been

```
    "user" => "%{[@metadata][email_tmp][0]}"
    "provider" => "%{[@metadata][email_tmp][1]}"

```

You do not need the brackets around the string

---

<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 14, 2021, 6:17pm UTC](https://discuss.elastic.co/t/clean-and-split-email-address-into-two-new-fields/267489/5 "2021-04-14T18:17:03Z")

</div>

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