# Optional field in dissect plugin

**URL:** <https://discuss.elastic.co/t/optional-field-in-dissect-plugin/149263>\
**Category:** Logstash\
**Created:** [September 20, 2018, 9:39am UTC](https://discuss.elastic.co/t/optional-field-in-dissect-plugin/149263 "2018-09-20T09:39:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitavmohanty01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amitavmohanty01/32/58017_2.png) [@amitavmohanty01](https://discuss.elastic.co/u/amitavmohanty01)\
**Post date:** [September 20, 2018, 9:39am UTC](https://discuss.elastic.co/t/optional-field-in-dissect-plugin/149263/1 "2018-09-20T09:39:42Z")

</div>

I have a dissect plugin in my filter section of the pipeline as follows:

```
   dissect {
   	       mapping => {
       	       "message" => "%{ts} %{+ts} %{+ts} %{host} %{prog}[%{pid}]: %{message}"
       }
   }

```

The pid element is not always present. Is there any way of indicating that an extraction element is optional? The only other option that I can think of is combine prog and pid into a field and run grok on the field. I am thinking that will be faster than using just grok for the entire message pattern. Please suggest.

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [October 3, 2018, 10:53am UTC](https://discuss.elastic.co/t/optional-field-in-dissect-plugin/149263/2 "2018-10-03T10:53:23Z")

</div>

You can combine the two fields and then use a conditional with another dissect filter.

```auto
if [prog] =~ /\]:\z/ {
  dissect {
    mapping => { "[prog]" => "%{prog}[%{pid}]:%{}" }
  }
}

```

---

<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:** [October 31, 2018, 10:53am UTC](https://discuss.elastic.co/t/optional-field-in-dissect-plugin/149263/3 "2018-10-31T10:53:28Z")

</div>

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