# How to get the total number of records that do not match a regex?

**URL:** <https://discuss.elastic.co/t/how-to-get-the-total-number-of-records-that-do-not-match-a-regex/228230>\
**Category:** Elasticsearch\
**Created:** [April 16, 2020, 2:17am UTC](https://discuss.elastic.co/t/how-to-get-the-total-number-of-records-that-do-not-match-a-regex/228230 "2020-04-16T02:17:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guerreiro\_Sousa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guerreiro_sousa/32/46074_2.png) [@Guerreiro\_Sousa](https://discuss.elastic.co/u/Guerreiro_Sousa)\
**Post date:** [April 16, 2020, 2:17am UTC](https://discuss.elastic.co/t/how-to-get-the-total-number-of-records-that-do-not-match-a-regex/228230/1 "2020-04-16T02:17:53Z")

</div>

How to get the total number of records that do not match a regex? I'm doing this search:

```
{
	"query": {
		"bool": {
			"must_not": [
				{
					"regexp": {
						"clientip": {
							"value": "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",
							"flags": "ALL",
							"rewrite": "constant_score"
						}
					}
				}
			]
		}
	}
}

```

This is an IP regex, however, the field in question may have integers that are not IP addresses. The query is not returning the total. How to achieve this value?

Current return:

```
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": null,
    "hits": []
  }
}
```

---

<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 14, 2020, 2:17am UTC](https://discuss.elastic.co/t/how-to-get-the-total-number-of-records-that-do-not-match-a-regex/228230/2 "2020-05-14T02:17:55Z")

</div>

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