# How to filter empty objects in Logstash?

**URL:** <https://discuss.elastic.co/t/how-to-filter-empty-objects-in-logstash/257456>\
**Category:** Logstash\
**Tags:** docker\
**Created:** [December 3, 2020, 6:41am UTC](https://discuss.elastic.co/t/how-to-filter-empty-objects-in-logstash/257456 "2020-12-03T06:41:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppuschmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppuschmann/32/146751_2.png) [@ppuschmann](https://discuss.elastic.co/u/ppuschmann)\
**Post date:** [December 3, 2020, 6:41am UTC](https://discuss.elastic.co/t/how-to-filter-empty-objects-in-logstash/257456/1 "2020-12-03T06:41:14Z")

</div>

Hi,  
given you get the following access-log:

```auto
{
  "container_id": "b62946591d90f24",
  "service": "slash",
  "bytes_received": 0,
  "input": {},
  "type": "filebeat",
  "protocol": "HTTP/1.1",
  "bytes_sent": 8236,
  "host": "docker-48",
  "response_time": 34,
  "tags": [
    "filebeat",
    "beats_input_raw_event"
  ],
  "query_string": {},
  "log_type": "access",
  "status": 200,
  "loglevel": "info",
  "request_method": "GET",
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36",
  "uri": "/services/my-service",
  "remote_address": "172.17.0.1",
  "stream": "stdout"
}

```

The mapping for the field `query_string` is set to `text`.  
This causes ES to complain, because `query_string` is an (empty) object.

How would you filter for this (sort of) invalid field in Logstash?  
(or prevent the creation)

Tools: Docker, filebeat v6 + Logstash v6 (with the idea to upgrade to v7 soon)

---

<div class="post-metadata">

**Author:** ![Raynald](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raynald/32/78897_2.png) [@Raynald](https://discuss.elastic.co/u/Raynald)\
**Post date:** [December 4, 2020, 4:27pm UTC](https://discuss.elastic.co/t/how-to-filter-empty-objects-in-logstash/257456/2 "2020-12-04T16:27:30Z")

</div>

> [@ppuschmann](#):
>
> `query_string`

You could check if value of this field is null, and then set value with empty value like this :  
`ruby {	code => " if event.get('query_string') == nil then event.set('query_string', '') end " }`

---

<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:** [January 1, 2021, 4:28pm UTC](https://discuss.elastic.co/t/how-to-filter-empty-objects-in-logstash/257456/3 "2021-01-01T16:28:04Z")

</div>

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