# HTTP output - conditional mapping

**URL:** https://discuss.elastic.co/t/http-output-conditional-mapping/169502
**Category:** Logstash
**Created:** [February 21, 2019, 11:07pm UTC](https://discuss.elastic.co/t/http-output-conditional-mapping/169502 "2019-02-21T23:07:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![somni](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@somni](https://discuss.elastic.co/u/somni)
#### Post date: [February 21, 2019, 11:07pm UTC](https://discuss.elastic.co/t/http-output-conditional-mapping/169502/1 "2019-02-21T23:07:10Z")

</div>

I'm doing mapping on my http output to slim down which fields for event logs are included. Currently I'm doing this in the http output:  
mapping =\> {  
"event" =\> {  
"event\_id" =\> "%{event\_id}"  
"message" =\> "%{message}"  
"log\_name" =\> "%{log\_name}"  
}  
}

Challenge is, some of the logs coming in dont contain some of the fields i'm referencing in the mapping, yet the raw %{fieldname} is still passed in the output. Is it possible to do conditional mapping in outputs? If not, what's the best way to do the conditional mapping before passing to output?

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: [February 21, 2019, 11:50pm UTC](https://discuss.elastic.co/t/http-output-conditional-mapping/169502/2 "2019-02-21T23:50:43Z")

</div>

You could use mutate+add\_field to add fields to a field on the event called event. Then you could remove any fields from inside event that start with "%{". Then add event to the mapping perhaps?

```
    ruby {
        code => '
            event.get("event").each { | k, v |
                if v.start_with? "%{"
                    event.remove("[event][#{k}]")
                end
            }
        '
    }
```

---

<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: [March 21, 2019, 11:50pm UTC](https://discuss.elastic.co/t/http-output-conditional-mapping/169502/3 "2019-03-21T23:50:46Z")

</div>

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