# Sorting an \`ip\_range\` field based on the first IP in the network address

**URL:** <https://discuss.elastic.co/t/sorting-an-ip-range-field-based-on-the-first-ip-in-the-network-address/178962>\
**Category:** Elasticsearch\
**Created:** [April 29, 2019, 4:28pm UTC](https://discuss.elastic.co/t/sorting-an-ip-range-field-based-on-the-first-ip-in-the-network-address/178962 "2019-04-29T16:28:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Westlake](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@Simon\_Westlake](https://discuss.elastic.co/u/Simon_Westlake)\
**Post date:** [April 29, 2019, 4:28pm UTC](https://discuss.elastic.co/t/sorting-an-ip-range-field-based-on-the-first-ip-in-the-network-address/178962/1 "2019-04-29T16:28:05Z")

</div>

Is this possible to do using Painless? I've been trying to figure out a way and haven't succeeded yet.

E.g. given 3 records where the `ip_range` field is 192.168.100.0/24, 192.168.0.0/16, 192.168.98.0/23, I'd like to sort and get back:

192.168.0.0/16  
192.168.98.0/23  
192.168.100.0/24

---

<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:** [May 27, 2019, 4:28pm UTC](https://discuss.elastic.co/t/sorting-an-ip-range-field-based-on-the-first-ip-in-the-network-address/178962/2 "2019-05-27T16:28:05Z")

</div>

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