# Filter not working

**URL:** <https://discuss.elastic.co/t/filter-not-working/46850>\
**Category:** Logstash\
**Created:** [April 9, 2016, 12:11am UTC](https://discuss.elastic.co/t/filter-not-working/46850 "2016-04-09T00:11:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brain](https://avatars.discourse-cdn.com/v4/letter/b/439d5e/32.png) [@brain](https://discuss.elastic.co/u/brain)\
**Post date:** [April 9, 2016, 12:11am UTC](https://discuss.elastic.co/t/filter-not-working/46850/1 "2016-04-09T00:11:26Z")

</div>

hello internet!

can someone point out why the below filter which look for an IP is not working

```
  if [answers] =~ "127\.0\.0\.1" {
    mutate {
      add_tag => ["non-routable"]
    }
  }
  if [answers] {
    mutate {
      add_tag => ["active"]
    }
  }

```

the field in the elasticsearch document for reference;

```
  "answers": [
     "127.0.0.1"
  ],

```

if also tried using == "127.0.0.1" which also doesnt seem to match

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 12, 2016, 6:20pm UTC](https://discuss.elastic.co/t/filter-not-working/46850/2 "2016-04-12T18:20:20Z")

</div>

This would be the correct regexp match syntax:

```
if [answers] =~ /127\.0\.0\.1/ {

```

But that's a sloppy regexp that doesn't anchor the beginning and end of the string, so this is better:

```
if [answers] =~ /^127\.0\.0\.1$/ {

```

And why use a regexp match when it's a plain string match you're after?

```
if [answers] == "127.0.0.1" {

```

And finally, since it's an array you're matching against what you really want to use is this:

```
if "127.0.0.1" in [answers] {
```

---

<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:** [July 6, 2017, 5:02am UTC](https://discuss.elastic.co/t/filter-not-working/46850/3 "2017-07-06T05:02:43Z")

</div>


