# Regex over \_uid field

**URL:** <https://discuss.elastic.co/t/regex-over--uid-field/83222>\
**Category:** Elasticsearch\
**Created:** [April 21, 2017, 2:24pm UTC](https://discuss.elastic.co/t/regex-over--uid-field/83222 "2017-04-21T14:24:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BBerastegui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bberastegui/32/17578_2.png) [@BBerastegui](https://discuss.elastic.co/u/BBerastegui)\
**Post date:** [April 21, 2017, 2:24pm UTC](https://discuss.elastic.co/t/regex-over--uid-field/83222/1 "2017-04-21T14:24:53Z")

</div>

Hi all !

I was using a previous version of ES in order to apply regexp on an \_uid field by using the following query (\_trying to get _id fields greater than 26 characters_):

> { "query": { "bool": { "must": [{ "regexp": { "\_uid": { "value": "mydoctype..{26,}" } } }] } } }

And this was working as expected.

Unfortunately, after upgrading to the latest version of ES, I got the following error when running the same search:

> TransportError(400, u'search\_phase\_execution\_exception', u'Can only use regexp queries on keyword and text fields - not on [\_uid] which is of type [\_uid]')

Is the regexp support over meta fields no longer supported?

Is there any other way of doing this that I might be missing?

Thanks in advance for your time !

Edit: For helping and clarification for the next person that lands here, the answer was given here: [\_uid field doesn't support regexes · Issue #24247 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/24247#issuecomment-296212819)

And the summary is that **no, regexp on \_uid is not supported anymore** , and the reason is:

> We plan on switching `_uid` to a more compact (binary) representation in the future, which will make the uid field incompatible with regexp, prefix or wildcard queries. So I don't think we should allow this again.

Cheers.

---

<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:** [April 21, 2017, 2:50pm UTC](https://discuss.elastic.co/t/regex-over--uid-field/83222/2 "2017-04-21T14:50:25Z")

</div>

> [@BBerastegui](#):
>
> And this was working as expected.

It may have worked but I don't think it worked "as expected". The `script.engine.groovy.inline.update` setting doesn't have anything to do with the `regexp` query. Unless you really need to turn on inline groovy scripting I'd turn it off because it is a security nightmare.

I think your issue is that `_uid` changed to not allow those kinds of queries. I opened an issue to discuss it:

> <https://github.com/elastic/elasticsearch/issues/24247>
>
> I'm opening this discuss issue in response to a forum \[post\](https://discuss.ela…stic.co/t/regex-over--uid-field/83222).
> 
> It looks like you used to be able to run a regex query on \`\_uid\` but you can't anymore. Do we want to allow it again?

I don't know that we'll want to support those queries for `_uid`, but that'll be settled in the issue. You should be able to work around the issue using a script query and the doc values storage for `_uid` but it'll be much slower because it won't be able to use the index.

---

<div class="post-metadata">

**Author:** ![BBerastegui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bberastegui/32/17578_2.png) [@BBerastegui](https://discuss.elastic.co/u/BBerastegui)\
**Post date:** [April 21, 2017, 3:46pm UTC](https://discuss.elastic.co/t/regex-over--uid-field/83222/3 "2017-04-21T15:46:07Z")

</div>

Hi !

I messed up the question by adding the groovy thing, totally true that it was not related to that at all, I already edited the question for the sake of clarity 🙂

I'll follow up that discussion then, as I see it's no longer possible to do what I was doing before !

Thanks for your reply !

---

<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 19, 2017, 3:47pm UTC](https://discuss.elastic.co/t/regex-over--uid-field/83222/4 "2017-05-19T15:47:28Z")

</div>

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