# Query on \_id field

**URL:** <https://discuss.elastic.co/t/query-on--id-field/95430>\
**Category:** Elasticsearch\
**Created:** [August 2, 2017, 12:02am UTC](https://discuss.elastic.co/t/query-on--id-field/95430 "2017-08-02T00:02:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xwang12345](https://avatars.discourse-cdn.com/v4/letter/x/49beb7/32.png) [@xwang12345](https://discuss.elastic.co/u/xwang12345)\
**Post date:** [August 2, 2017, 12:02am UTC](https://discuss.elastic.co/t/query-on--id-field/95430/1 "2017-08-02T00:02:52Z")

</div>

I had some trouble trying to query the id\_ field

The following query works:

```auto
GET my_index/my_type/_search
{
   "query" : {
     "match":{
        "_id": "ABC_my_content1"
     }
   }
}

```

But what if I want to search for all the document that has the \_id start with ABC?  
This does not work:

```auto
GET my_indxe/my_type/_search
{
   "query" :{
     "query_string" : {
         "default_field" : "_id",
         "query" : "ABC*"
      }
   }
}

```

I got the error  
Can only use prefix queries on keyword and text fields - not on [\_id] which is of type [\_id]

Any suggestions?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [August 2, 2017, 8:59pm UTC](https://discuss.elastic.co/t/query-on--id-field/95430/2 "2017-08-02T20:59:14Z")

</div>

Yeah, so the `_id` field is sorta special. It's not really an indexed field like other text fields, it's actually "generated" based on the UID of the document (see: [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-id-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-id-field.html)).

So it only supports a limited subset of the query functionality. If you want to do more advanced text search like prefix/wildcard/fuzzy, etc, you'll need to index the ID into an actual text field on the document itself.

---

<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:** [August 30, 2017, 8:59pm UTC](https://discuss.elastic.co/t/query-on--id-field/95430/3 "2017-08-30T20:59:29Z")

</div>

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