# Filter issue with Logstash

**URL:** <https://discuss.elastic.co/t/filter-issue-with-logstash/265171>\
**Category:** Logstash\
**Created:** [February 23, 2021, 7:31am UTC](https://discuss.elastic.co/t/filter-issue-with-logstash/265171 "2021-02-23T07:31:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nyquillus](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@nyquillus](https://discuss.elastic.co/u/nyquillus)\
**Post date:** [February 23, 2021, 7:31am UTC](https://discuss.elastic.co/t/filter-issue-with-logstash/265171/1 "2021-02-23T07:31:54Z")

</div>

Hi,

I recently added a filter to my logstash to change indexing for spesific indices(weekly, monthly etc.)

The filter is this:

```
filter {
        if [retention] == "weekly" {
        mutate { add_field => { "[@metadata][target_index]" => "%{program}-%{+xxxx.ww}" } }
      } else if [retention] == "monthly" {
        mutate { add_field => { "[@metadata][target_index]" => "%{program}-%{+YYYY.MM}" } }
      } else {
        mutate { add_field => { "[@metadata][target_index]" => "%{program}-%{+YYYY.MM.dd}" } }
      }
    }

```

After updating logstash i noticed the logs i receive have every bit of information crammed in message field like this:

`{"@timestamp":"2021-02-22T14:20:01+00:00","source":"x","message":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","level":x,"thread_id":xxxxx,"thread_name":"logger","retention":"weekly","service":"xxx","program":"xxxxxxxxx"}`

So I also added this right before the new filter:

```
filter {
if [message] =~ "\A\{.+\}\z" {
          json { source => "message" }
        }
}

```

after this the logs started appearing in desired format. Now I administrate more than 90 indices and every index except one is working just fine.  
The problem with the spesific index is that it has a data field with always changing variables in it. And each time a log from a different source comes the filter creates that entire data field. On kibana i see avaliable fields like this:

![firefox_nQ2hT3Hvax](https://us1.discourse-cdn.com/elastic/original/3X/d/9/d9ea884858b2ad6ee441ee06338f93e6a0b33ed8.png)

Index now has thousands of these fields and doesnt receive new logs anymore.  
The logger options are like this:

`$syslog_message = json_encode(['@timestamp'=>date('c'),'source'=>gethostname(),'message'=>$message,'level'=>$level,'thread_id'=>'xxxxxxx-'.uniqid(),'thread_name'=>'logger','program'=>'xxxxxxx']);`

```
$message = [
          "path" =>$req->getUri()->getPath(),
          "data" => $req->getParsedBody()
        ];

```

Is there a way to fix this? Either by changing the logstash filter or changing the logger?  
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:** [March 23, 2021, 7:32am UTC](https://discuss.elastic.co/t/filter-issue-with-logstash/265171/2 "2021-03-23T07:32:31Z")

</div>

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