# CIDR query on ip\_range field not working

**URL:** https://discuss.elastic.co/t/cidr-query-on-ip-range-field-not-working/133932
**Category:** Elasticsearch
**Created:** [May 30, 2018, 7:13pm UTC](https://discuss.elastic.co/t/cidr-query-on-ip-range-field-not-working/133932 "2018-05-30T19:13:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vramakrishnan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vramakrishnan/32/31750_2.png) [@vramakrishnan](https://discuss.elastic.co/u/vramakrishnan)
#### Post date: [May 30, 2018, 7:13pm UTC](https://discuss.elastic.co/t/cidr-query-on-ip-range-field-not-working/133932/1 "2018-05-30T19:13:51Z")

</div>

I have the following mapping

```auto
  "mappings": {
    "_doc": {
      "properties": {
        "src_ip": {
          "type": "ip_range",
          "index": true
        },
		"dst_ip": {
          "type": "ip_range",
          "index": true
        },
        "src_port": {
          "type": "integer_range",
          "index": true
        },
		"dst_port": {
          "type": "integer_range",
          "index": true
        },
    	"protocol": {
            "type" : "keyword"
        }
      }
    }
  }

```

And doc indexed is as follows

```auto
{
  "src_ip": "10.2.0.0/8",
  "dst_ip": "10.3.0.128/29",
  "src_port": {
  	"gte" : 1000,
    "lte" : 1010
  },
  "dst_port": {
  	"gte" : 1100,
    "lte" : 1110
  },
  "protocol": "tcp"
}

```

I am trying to execute a CIDR style query on this doc, but running into illegal arg exception. May I know the right query to use for CIDR style query with ip\_range.

```auto
{
  "query": {
    "term": {
      "src_ip": {
        "value": "10.2.0.0/16"
      }
    }
  }
}

Result is ...

{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: { "term" : { "src_ip" : { "value" : "10.2.0.0/16", "boost" : 1.0 } } }",
"index_uuid": "MqRCsD-yR6ODg-8c7-ihzA",
"index": "ipindex"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "ipindex",
"node": "Dj1Fqc65T6Kuk3pB8hQS3A",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: { "term" : { "src_ip" : { "value" : "10.2.0.0/16", "boost" : 1.0 } } }",
"index_uuid": "MqRCsD-yR6ODg-8c7-ihzA",
"index": "ipindex",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "'10.2.0.0/16' is not an IP string literal."
}
}
}
]
},
"status": 400
}

```

---

<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: [June 27, 2018, 7:13pm UTC](https://discuss.elastic.co/t/cidr-query-on-ip-range-field-not-working/133932/2 "2018-06-27T19:13:55Z")

</div>

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