# Kibana json input

**URL:** <https://discuss.elastic.co/t/kibana-json-input/285857>\
**Category:** Kibana\
**Created:** [October 4, 2021, 10:24pm UTC](https://discuss.elastic.co/t/kibana-json-input/285857 "2021-10-04T22:24:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![azulgrana](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@azulgrana](https://discuss.elastic.co/u/azulgrana)\
**Post date:** [October 4, 2021, 10:24pm UTC](https://discuss.elastic.co/t/kibana-json-input/285857/1 "2021-10-04T22:24:07Z")

</div>

Hi there!

I have a custom visualization that reports on network traffic by protocol, source and destination. I have added to my Split rows bucket a custom JSON input to strip out the last octet and to display the communications based on source / destination subnets

```auto
{
    "script": "( _value.indexOf('.') > 0 ? _value.substring(0, _value.lastIndexOf('.')) : _value )"
}

```

And in cases where the communication happened within the same subnet, the query shows record for it.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/3/933bfd1e4c0095f0ee3842ee4521fa02ef8cd318.png)

What would be the best way to exclude / remove the values where the Source and Destination are the same? I was thinking on comparing the two fields and if the fields have equal value then replace value with 0 and use the "Exclude" option to exclude all zeros ... though I couldn't find a way to it and how to add it to my existing code.

Any feedback or help, would be greatly appreciated

TIA!

Azulgrana

---

<div class="post-metadata">

**Author:** ![azulgrana](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@azulgrana](https://discuss.elastic.co/u/azulgrana)\
**Post date:** [October 5, 2021, 1:38am UTC](https://discuss.elastic.co/t/kibana-json-input/285857/2 "2021-10-05T01:38:06Z")

</div>

I think I made it work

```auto
{
  "script": "if ( doc['ip_src'].value.substring(0, doc['ip_src'].value.lastIndexOf('.')) == doc['ip_dst'].value.substring(0, doc['ip_dst'].value.lastIndexOf('.'))) {return '0'} else {return _value.substring(0, doc['ip_src'].value.lastIndexOf('.'))}"
}

```

---

<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:** [November 2, 2021, 1:38am UTC](https://discuss.elastic.co/t/kibana-json-input/285857/3 "2021-11-02T01:38:40Z")

</div>

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