# Is it possible to use regex expressions on long fields?

**URL:** https://discuss.elastic.co/t/is-it-possible-to-use-regex-expressions-on-long-fields/78899
**Category:** Elasticsearch
**Created:** [March 16, 2017, 4:08pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-regex-expressions-on-long-fields/78899 "2017-03-16T16:08:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)
#### Post date: [March 16, 2017, 4:08pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-regex-expressions-on-long-fields/78899/1 "2017-03-16T16:08:03Z")

</div>

I have long field in my mapping . the field has some values but in that i want the documents of long field that has 130 (i.e i want all the documents that has the long field starting with 130) .

Like below Scenario:

```
Doc1 Doc2 Doc3
long field:130056 long field:130556 long field:120336

```

If i search for long field =130 \* in my query, i have to get Doc 1 &2 in my output.

IS this possible in ES?

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [March 16, 2017, 5:15pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-regex-expressions-on-long-fields/78899/2 "2017-03-16T17:15:10Z")

</div>

If you mean the [numeric datatype `long`](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html) then the answer is No, you cannot use regular expressions on that field. You can add another string field with the same value to each doc to be able to use prefix or regex searches though.

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [March 16, 2017, 6:45pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-regex-expressions-on-long-fields/78899/3 "2017-03-16T18:45:14Z")

</div>

I expect it'd be easier to use a bunch of `range` queries in `bool` `should` clauses. It won't be _faster_, but, depending on what you want, it'd be easier.

If you are always going to be doing these prefix searches I'd suggest looking at the completion suggester and `edge_ngram` analyzers. They both are for fast prefix searching but have different time, memory, and result tradeoffs.

---

<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: [April 13, 2017, 6:45pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-regex-expressions-on-long-fields/78899/4 "2017-04-13T18:45:25Z")

</div>

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