# Retrieve all ids that starts with a string

**URL:** <https://discuss.elastic.co/t/retrieve-all-ids-that-starts-with-a-string/73332>\
**Category:** Elasticsearch\
**Created:** [January 31, 2017, 9:41am UTC](https://discuss.elastic.co/t/retrieve-all-ids-that-starts-with-a-string/73332 "2017-01-31T09:41:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oranciog](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@oranciog](https://discuss.elastic.co/u/oranciog)\
**Post date:** [January 31, 2017, 9:41am UTC](https://discuss.elastic.co/t/retrieve-all-ids-that-starts-with-a-string/73332/1 "2017-01-31T09:41:20Z")

</div>

Hello!

We want to retrieve all documents that have a common part in their ids.  
For example we want to retrieve all ids that starts with B\*.

I saw the ids query, but it is not we want and also using a regexp on \_id or _uid_ fields doesn't work ("Can only use regexp queries on keyword and text fields - not on [\_uid] which is of type [\_uid]").

It is possible to search something like this?

Thank you,

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 31, 2017, 9:56am UTC](https://discuss.elastic.co/t/retrieve-all-ids-that-starts-with-a-string/73332/2 "2017-01-31T09:56:57Z")

</div>

Hey,

you might want to check out the [prefix](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-prefix-query.html) query. Also note, that `_uid` also contains the type, so maybe just add that id field in your JSON body and then go from there.

---Alex

---

<div class="post-metadata">

**Author:** ![oranciog](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@oranciog](https://discuss.elastic.co/u/oranciog)\
**Post date:** [January 31, 2017, 10:17am UTC](https://discuss.elastic.co/t/retrieve-all-ids-that-starts-with-a-string/73332/3 "2017-01-31T10:17:24Z")

</div>

Hello,

Thank you for your quick response, but prefix query doesn't work also ("Can only use prefix queries on keyword and text fields - not on [\_id] which is of type [\_id]", similar for \_uid).

Btw, we use ES 5.0.0.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 31, 2017, 10:26am UTC](https://discuss.elastic.co/t/retrieve-all-ids-that-starts-with-a-string/73332/4 "2017-01-31T10:26:41Z")

</div>

Hey,

that's why I said, you should add the id as a regular field to your JSON document, sorry if that wasnt clear.

--Alex

---

<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:** [February 28, 2017, 10:26am UTC](https://discuss.elastic.co/t/retrieve-all-ids-that-starts-with-a-string/73332/5 "2017-02-28T10:26:51Z")

</div>

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