# Logstash help with pattern for grok needed

**URL:** <https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518>\
**Category:** Logstash\
**Created:** [November 16, 2020, 11:52am UTC](https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518 "2020-11-16T11:52:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christos\_Gitsis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christos_gitsis/32/56529_2.png) [@Christos\_Gitsis](https://discuss.elastic.co/u/Christos_Gitsis)\
**Post date:** [November 16, 2020, 11:52am UTC](https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518/1 "2020-11-16T11:52:33Z")

</div>

Hello, I am trying to parse some data which is in one of the two following formats:

Sample data:

```
Data from service service-a loaded
Data from service service-b not loaded

```

With the following Grok Pattern:

```
Data from service %{NOTSPACE:service} %{NOT:n}loaded

```

and custom patterns:

```
NOT (?:not )

```

I work in Kibana \> Grok Debugger. It seems that my pattern matches the second line of sample data but not the first. I am trying to make it so that the "not " part is optional, and to generate a pattern which matches all my inputs. Could you help me?

Second question, is it possible to use grok to output an integer value, 0 or 1, depending on whether the data from the service is loaded or not?

---

<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:** [November 16, 2020, 4:05pm UTC](https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518/2 "2020-11-16T16:05:19Z")

</div>

> [@Christos\_Gitsis](#):
>
> `NOT (?:not )`

That is, I believe, a non-capturing field. If you want an optional field then the ? should be at the end

```
(not )?

```

---

<div class="post-metadata">

**Author:** ![Christos\_Gitsis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christos_gitsis/32/56529_2.png) [@Christos\_Gitsis](https://discuss.elastic.co/u/Christos_Gitsis)\
**Post date:** [November 16, 2020, 4:14pm UTC](https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518/3 "2020-11-16T16:14:43Z")

</div>

> [@Badger](#):
>
> ```auto
> (not )?
> 
> ```

Thank you, that works. Would someone have an idea for the second question as well?

---

<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:** [November 16, 2020, 4:20pm UTC](https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518/4 "2020-11-16T16:20:04Z")

</div>

> [@Christos\_Gitsis](#):
>
> Would someone have an idea for the second question as well?

The field [n] will only exist if the service is not loaded, so you could use

```
if [n] {
    mutate { add_field => { "someField" => 0 } }
} else {
    mutate { add_field => { "someField" => 1 } }
}
mutate { convert => { "someField" => "integer" } }

```

---

<div class="post-metadata">

**Author:** ![Christos\_Gitsis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christos_gitsis/32/56529_2.png) [@Christos\_Gitsis](https://discuss.elastic.co/u/Christos_Gitsis)\
**Post date:** [November 19, 2020, 1:02pm UTC](https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518/5 "2020-11-19T13:02:32Z")

</div>

thanks!

---

<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:** [December 17, 2020, 1:02pm UTC](https://discuss.elastic.co/t/logstash-help-with-pattern-for-grok-needed/255518/6 "2020-12-17T13:02:41Z")

</div>

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