# Shrinked ip address field

**URL:** <https://discuss.elastic.co/t/shrinked-ip-address-field/277376>\
**Category:** Elasticsearch\
**Created:** [June 29, 2021, 5:57pm UTC](https://discuss.elastic.co/t/shrinked-ip-address-field/277376 "2021-06-29T17:57:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roonick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roonick/32/90977_2.png) [@roonick](https://discuss.elastic.co/u/roonick)\
**Post date:** [June 29, 2021, 5:57pm UTC](https://discuss.elastic.co/t/shrinked-ip-address-field/277376/1 "2021-06-29T17:57:20Z")

</div>

Good day!  
I want to create additional field for nginx access log. This field must contain left octets of IP-address. For examle. If remote IP is 192.168.1.10, field will contain only 192.168.1.  
Sorry, my English is not very good.  
Best regards, roonick

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 29, 2021, 11:57pm UTC](https://discuss.elastic.co/t/shrinked-ip-address-field/277376/2 "2021-06-29T23:57:51Z")

</div>

You will need to extract this with an ingest pipeline, or similar, but it's possible.

---

<div class="post-metadata">

**Author:** ![Iker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iker/32/91708_2.png) [@Iker](https://discuss.elastic.co/u/Iker)\
**Post date:** [June 30, 2021, 4:39am UTC](https://discuss.elastic.co/t/shrinked-ip-address-field/277376/3 "2021-06-30T04:39:47Z")

</div>

That should be pretty easy with a Grok pattern (A custom one just for fun), there you go:

**Input**

```auto
172.17.7.10

```

**Custom Grok Pattern**

```auto
LEFTIP (?<![0-9])(?:(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])[.](?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])[.](?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])[.])

```

**Grok Pattern**

```auto
%{LEFTIP:client}

```

**Output**

```auto
{
  "client": [
    [
      "172.17.7."
    ]
  ]
}

```

You can practice at [https://grokdebug.herokuapp.com](https://grokdebug.herokuapp.com)

---

<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 28, 2021, 4:39am UTC](https://discuss.elastic.co/t/shrinked-ip-address-field/277376/4 "2021-07-28T04:39:59Z")

</div>

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