# Trimming the URI Path from end

**URL:** <https://discuss.elastic.co/t/trimming-the-uri-path-from-end/147213>\
**Category:** Logstash\
**Created:** [September 4, 2018, 1:14pm UTC](https://discuss.elastic.co/t/trimming-the-uri-path-from-end/147213 "2018-09-04T13:14:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![satish\_kumar1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/satish_kumar1/32/86674_2.png) [@satish\_kumar1](https://discuss.elastic.co/u/satish_kumar1)\
**Post date:** [September 4, 2018, 1:14pm UTC](https://discuss.elastic.co/t/trimming-the-uri-path-from-end/147213/1 "2018-09-04T13:14:05Z")

</div>

Hi All,

I am new to logstash, I am working on creating visualization of top API based on AWS ELB logs, and i am stucked at this point where i need to trim URIPath.

example request: [https://www.google.com/test/v1/api/006b2511-b009-11e8-b30f-0165a332b61d](https://www.google.com/test/v1/api/006b2511-b009-11e8-b30f-0165a332b61d)

Actual URIPATH: "/test/v1/api/006b2511-b009-11e8-b30f-0165a332b61d"

I am looking for parsing logic so that after parsing URI path should come like this.

URIPATH: "/test/v1/api"

I have given example for one scenairo, but we have multiple api's and last section of URIPATH is different in length.

For example:

[https://www.test.com/testing/v3/mgmt/18-EE-69-9FF4049E7C723EE724491E1D8141096B1C7374FC0EBA1421AE4D72F71F96D3AC](https://www.test.com/testing/v3/mgmt/18-EE-69-9FF4049E7C723EE724491E1D8141096B1C7374FC0EBA1421AE4D72F71F96D3AC)

Please guide me how to trim URIPATH from end upto '/'

Regards,  
Satish

---

<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:** [September 7, 2018, 6:03am UTC](https://discuss.elastic.co/t/trimming-the-uri-path-from-end/147213/2 "2018-09-07T06:03:39Z")

</div>

You can e.g. use a mutate filter's gsub option to replace the protocol and hostname (and optionally port) with an empty string. A regexp like `^https?://[^/]+` would do.

---

<div class="post-metadata">

**Author:** ![satish\_kumar1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/satish_kumar1/32/86674_2.png) [@satish\_kumar1](https://discuss.elastic.co/u/satish_kumar1)\
**Post date:** [September 24, 2018, 12:58pm UTC](https://discuss.elastic.co/t/trimming-the-uri-path-from-end/147213/3 "2018-09-24T12:58:31Z")

</div>

thanks magnus, i will try this out and check if it works for my scenario

---

<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:** [October 22, 2018, 1:07pm UTC](https://discuss.elastic.co/t/trimming-the-uri-path-from-end/147213/4 "2018-10-22T13:07:34Z")

</div>

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