# Unable to add empty field with Logstash

**URL:** <https://discuss.elastic.co/t/unable-to-add-empty-field-with-logstash/329306>\
**Category:** Logstash\
**Created:** [April 4, 2023, 10:37am UTC](https://discuss.elastic.co/t/unable-to-add-empty-field-with-logstash/329306 "2023-04-04T10:37:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jirka\_Liska](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jirka_liska/32/117513_2.png) [@Jirka\_Liska](https://discuss.elastic.co/u/Jirka_Liska)\
**Post date:** [April 4, 2023, 10:37am UTC](https://discuss.elastic.co/t/unable-to-add-empty-field-with-logstash/329306/1 "2023-04-04T10:37:15Z")

</div>

Hello community!

I'm trying to add **empty field** into Logstash parsers like this:

```auto
mutate {
add_field => {"comments" => {} }
}

```

this is my mapping in Kibana:

```auto
{
  "_meta": {
    "documentation": "https://www.elastic.co/guide/en/ecs/current/ecs-base.html",
    "ecs_version": "8.3.1"
  },
  "template": {
    "mappings": {
      "properties": {
        "comments": {
          "type": "object"
        }
      }
    }
  }
}

```

but it just do not appear in Kibana - even under json view \_source. Any idea what am I doing wrong? Thanks in advance!

output file:

```auto
output {
  if [type] == "office365" {
    elasticsearch {
      index => "report-%{[PK]}"
      ecs_compatibility => v8
      hosts => "elastic:9200"
    }
  }
}

```

input

preprocess file:

```auto
filter {
  if [type] == "office365" {
    # drop any comments
    if [message] =~ /^#/ {
      drop {}
    }

    # lowercase all true/false values so downstream picks them up as booleans
    mutate {
      gsub => [
        "message", '(?i)""true""', 'true',
        "message", '(?i)""false""', 'false',
        "message", '(?i)"true"', '"true"',
        "message", '(?i)"false"', '"false"'
      ]
    }
  }
}

```

postprocess file:

```auto
filter {
  if [type] == "office365" {
    # enrich the useragent field
    if [useragent] {
      mutate {
        # remove quotes from quoted string
        # convert + sign to space
        gsub => [
          "useragent", "\"", "",
          "useragent", "\+", " "
        ]
      }
      useragent {
        source => [useragent]
        target => [useragentinfo]
      }
    }
  }
}

```

---

<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:** [April 4, 2023, 5:08pm UTC](https://discuss.elastic.co/t/unable-to-add-empty-field-with-logstash/329306/2 "2023-04-04T17:08:02Z")

</div>

> [@Jirka\_Liska](#):
>
> ```auto
> mutate { add_field => {"comments" => {} } }
> 
> ```

That doesn't do anything. Not sure why. Try

```
ruby { code => 'event.set("comments", {})' }

```

---

<div class="post-metadata">

**Author:** ![Jirka\_Liska](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jirka_liska/32/117513_2.png) [@Jirka\_Liska](https://discuss.elastic.co/u/Jirka_Liska)\
**Post date:** [April 5, 2023, 9:34am UTC](https://discuss.elastic.co/t/unable-to-add-empty-field-with-logstash/329306/3 "2023-04-05T09:34:39Z")

</div>

Awesome! It's working exactly I needed. Would you mind bit elaborate on it to help me understand it? Thanks in advance

---

<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:** [May 3, 2023, 9:35am UTC](https://discuss.elastic.co/t/unable-to-add-empty-field-with-logstash/329306/4 "2023-05-03T09:35:18Z")

</div>

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