# Mutate add\_field gives sprint f format for nil values. How to solve this?

**URL:** https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473
**Category:** Logstash
**Created:** [May 16, 2019, 7:58pm UTC](https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473 "2019-05-16T19:58:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)
#### Post date: [May 16, 2019, 7:58pm UTC](https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473/1 "2019-05-16T19:58:28Z")

</div>

Hi All

I am using mutate add\_field in my confile

```
mutate {
add_field => {"CloserName" => "%{[Bugs]CloserName}"}
    }

```

The value for many CloserName is null but some has value  
Which ever record is having null values, i am not getting null instead i am getting sprintf  
format.  
i get the output like this  
`%{[Bugs]CloserName}`

I can use If condition to solve for one column, i have 200 columns like this, i cannot write if condition for each of these newly added field.

I think this will be common problem, please let me know if someone is having solution for this?

---

<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: [May 16, 2019, 8:01pm UTC](https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473/2 "2019-05-16T20:01:58Z")

</div>

That is not a valid sprintf reference. Is CloserName and field within the [Bugs] object? If so, use

```
%{[Bugs][CloserName]}

```

If it still does not work, configure

```
output { stdout { codec => rubydebug } }

```

and show us what an event looks like.

---

<div class="post-metadata">

### Author: ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)
#### Post date: [May 16, 2019, 8:09pm UTC](https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473/3 "2019-05-16T20:09:41Z")

</div>

Hi @Badger

I tried your suggested sprintf, still i get the same value. Pasting the json from kibana

> {  
> "\_index": "sdfdsfff",  
> "\_type": "logs",  
> "\_id": "AWrCP3j9UCagDdWuJhQ7",  
> "\_score": 1,  
> "\_source": {  
> "BugTypeName": "Support",  
> "Status": "Under Review",  
> "Severity": "Normal",  
> "CloserName": "%{[Bugs][CloserName]}",  
> "@timestamp": "2019-05-16T20:05:04.413Z",  
> "DaysOpened": "6",  
> "BugNumber": "1010",  
> "@version": "1",  
> "DateModified": "5/10/2019 3:19 AM"  
> },  
> "fields": {  
> "@timestamp": [  
> 1558037104413  
> ]  
> }  
> }

This is what i am using in conf file

` add_field => {"CloserName" => "%{[Bugs][CloserName]}"}`

Under Bugs, this is how my value looks like, i am just parsing it to new field

> [  
> {  
> .............  
> .  
> .
> 
> ```
> "CloserName": null,
> "DaysOpened": "8",
> "ReportedVersionID": null,
> "BugsSeverityID": "38522",
> .
> .
> .
> },
> 
> {
> 
> }
> 
> ```
> 
> ]

---

<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: [May 16, 2019, 8:38pm UTC](https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473/4 "2019-05-16T20:38:13Z")

</div>

OK, so that event does not have a [Bugs][CloserName] field, so you should expect the mutate to leave it with the sprintf reference. You could use something like [this](https://discuss.elastic.co/t/removing-fields-with-certain-value-or-if-mapping-is-not-found-from-the-output/180941/2) to remove any fields whose value starts with "%{".

---

<div class="post-metadata">

### Author: ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)
#### Post date: [May 18, 2019, 1:01pm UTC](https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473/5 "2019-05-18T13:01:58Z")

</div>

Thanks @Badger, from the linked topic, i got my solution

---

<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: [June 15, 2019, 1:02pm UTC](https://discuss.elastic.co/t/mutate-add-field-gives-sprint-f-format-for-nil-values-how-to-solve-this/181473/6 "2019-06-15T13:02:10Z")

</div>

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