# I want to output log to elasticsearch index from only specific "host.ip"

**URL:** https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494
**Category:** Logstash
**Created:** [March 8, 2021, 1:47am UTC](https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494 "2021-03-08T01:47:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![BlackCat](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@BlackCat](https://discuss.elastic.co/u/BlackCat)
#### Post date: [March 8, 2021, 1:47am UTC](https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494/1 "2021-03-08T01:47:18Z")

</div>

"host.ip" is at "\_source" displayed on Kibana.

Please teach me how to resolve.

logstash config

```auto
input {
  beats {
    port => 5044
  }
}

filter {
    grok {
       match => { "message" => "%{SYSLOGTIMESTAMP:Time} %{HOSTNAME:Hostname} %{GREEDYDATA:Message}" }
    }
    date {
        match => ["Time", "MMM d HH:mm:ss", "MMM dd HH:mm:ss"]
        target => "Time"
    }
}

output {
    elasticsearch {
      hosts => "<elasticsearch ip address>:9200"
      index => "server_log"
    }
}

```

![20210308](https://us1.discourse-cdn.com/elastic/original/3X/0/f/0f4e166af642a2a185cbe47a2850e4ee0258a62a.png)

---

<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: [March 8, 2021, 1:58am UTC](https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494/2 "2021-03-08T01:58:29Z")

</div>

In the filter section you could use

```
if [host][ip] != "10.197.218.10" { drop {} }

```

If the field actually has a period in the name then that would be

```
if [host.ip] != "10.197.218.10" { drop {} }
```

---

<div class="post-metadata">

### Author: ![BlackCat](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@BlackCat](https://discuss.elastic.co/u/BlackCat)
#### Post date: [March 8, 2021, 6:21am UTC](https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494/3 "2021-03-08T06:21:00Z")

</div>

I tried both.  
but, elasticsearch couldn't receive log from host of 10.197.218.10.

Config is below.

```auto
filter {
    if [host][ip] != "10.197.218.10" { drop {} }
    grok {
       match => { "message" => "%{SYSLOGTIMESTAMP:Time} %{HOSTNAME:Hostname} %{GREEDYDATA:Message}" }
    }
    date {
        match => ["Time", "MMM d HH:mm:ss", "MMM dd HH:mm:ss"]
        target => "Time"
    }
}

```

```auto
filter {
    if [host.ip] != "10.197.218.10" { drop {} }
    grok {
       match => { "message" => "%{SYSLOGTIMESTAMP:Time} %{HOSTNAME:Hostname} %{GREEDYDATA:Message}" }
    }
    date {
        match => ["Time", "MMM d HH:mm:ss", "MMM dd HH:mm:ss"]
        target => "Time"
    }
}

```

"\_source" field is auto generated by system of elastic.  
"message" field haven't host.ip.

---

<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: [March 8, 2021, 5:20pm UTC](https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494/4 "2021-03-08T17:20:39Z")

</div>

It looks like beats add [host][ip] as an array of IP addresses, so you need an array membership test...

`if "10.197.218.10" not in [host][ip] { drop {} }`

---

<div class="post-metadata">

### Author: ![BlackCat](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@BlackCat](https://discuss.elastic.co/u/BlackCat)
#### Post date: [March 9, 2021, 3:51am UTC](https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494/5 "2021-03-09T03:51:57Z")

</div>

Just resolved.  
Thank you.

---

<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: [April 6, 2021, 3:52am UTC](https://discuss.elastic.co/t/i-want-to-output-log-to-elasticsearch-index-from-only-specific-host-ip/266494/6 "2021-04-06T03:52:08Z")

</div>

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