# Match partial IP

**URL:** <https://discuss.elastic.co/t/match-partial-ip/49331>\
**Category:** Elasticsearch\
**Created:** [May 5, 2016, 6:54pm UTC](https://discuss.elastic.co/t/match-partial-ip/49331 "2016-05-05T18:54:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TroyAndAbed](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@TroyAndAbed](https://discuss.elastic.co/u/TroyAndAbed)\
**Post date:** [May 5, 2016, 6:54pm UTC](https://discuss.elastic.co/t/match-partial-ip/49331/1 "2016-05-05T18:54:11Z")

</div>

Hi,

In my index, I have an IP field. The type of the field is "ip".

I want to search all IPs who starts with "192.168"

All my tentative have failed with the following message: failed to parse ip [192.168], not a valid ip address

Is there a way of doing this or should I change the type of the field to "string"?

Thanks.

---

<div class="post-metadata">

**Author:** ![TroyAndAbed](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@TroyAndAbed](https://discuss.elastic.co/u/TroyAndAbed)\
**Post date:** [May 5, 2016, 7:07pm UTC](https://discuss.elastic.co/t/match-partial-ip/49331/2 "2016-05-05T19:07:59Z")

</div>

My bad, i didn't think of using a range query, so the following will works:

```
GET my_index/_search
{
  "query": {
    "range": {
      "ip_addr": {
        "gte": "192.168.0.0",
        "lt": "192.168.255.255"
      }
    }
  }
}
```

---

<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 5, 2017, 10:53pm UTC](https://discuss.elastic.co/t/match-partial-ip/49331/3 "2017-07-05T22:53:37Z")

</div>


