# Variable on Logstash

**URL:** <https://discuss.elastic.co/t/variable-on-logstash/164356>\
**Category:** Logstash\
**Created:** [January 15, 2019, 6:48pm UTC](https://discuss.elastic.co/t/variable-on-logstash/164356 "2019-01-15T18:48:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcd1189](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rcd1189](https://discuss.elastic.co/u/rcd1189)\
**Post date:** [January 15, 2019, 6:48pm UTC](https://discuss.elastic.co/t/variable-on-logstash/164356/1 "2019-01-15T18:48:57Z")

</div>

Hello everyone!

I'm creating a Centralized Logs with Filebeat, Logstash, and Elasticsearch. My Beat and Elasticsearch work well.  
I'm getting a problem in my logstash on output.

logstash.conf

input {  
hits  
port =\> 5044  
}  
}  
filter {  
if [type] == "t13\_oms\_log" {  
grok {  
patterns\_dir =\> "./patterns"  
match =\> ["message", "% {GREEDYDATA: message}"]  
overwrite =\> ["message"]  
}  
}  
}  
filter {  
if [type] == "t13\_crm\_log" {  
grok {  
patterns\_dir =\> "./patterns"  
match =\> ["message", "% {GREEDYDATA: message}"]  
overwrite =\> ["message"]  
}  
}  
}  
output {  
stdout {codec =\> rubydebug}  
elasticsearch {  
hosts =\> ["10.28.158.2:9200"]  
index =\> "% {type} \_indexer"  
}  
}

When logstash sends data to the elasticsearch, it sends it to:  
green open% {type} \_indexer QSvQEmSNTAmIGeJIyFI\_dA 5 1 3617 0 1.7mb 460b

Logstash can not resolve variable '% {type}'

I tried use an if on output, but, not work. I need a static index name  
What can be this?

---

<div class="post-metadata">

**Author:** ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)\
**Post date:** [January 15, 2019, 8:52pm UTC](https://discuss.elastic.co/t/variable-on-logstash/164356/2 "2019-01-15T20:52:29Z")

</div>

It looks like you have a superfluous spaces in your index pattern, which is causing the string replacement engine to not see the variable in the template:

- Instead of: `index => "% {type} _indexer"`,
- please try: `index => "%{type}_indexer"`

---

<div class="post-metadata">

**Author:** ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)\
**Post date:** [January 15, 2019, 8:57pm UTC](https://discuss.elastic.co/t/variable-on-logstash/164356/3 "2019-01-15T20:57:46Z")

</div>

At second-glance, the superfluous spaces around your GROK patterns are going to cause similar problems, and will result in the events not matching the patterns.

I also can't really tell what you're attempting to do with your GROK plugin configurations; the following, if specified correctly without extra spaces in the pattern template, would essentially say:

- load all of the patterns in the specified directory (_and then don't use any of them_)
- match the contents of the `message` field, capturing everything into a single resulting field that we will call `message`, overwriting the contents of `message` with _an identical copy of itself_.

```auto
grok {
  patterns_dir => "./patterns"
  match => ["message", "%{GREEDYDATA: message}"]
  overwrite => ["message"]
}

```

---

<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:** [February 12, 2019, 8:57pm UTC](https://discuss.elastic.co/t/variable-on-logstash/164356/4 "2019-02-12T20:57:48Z")

</div>

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