# Getting \_id field from DocLookup

**URL:** <https://discuss.elastic.co/t/getting--id-field-from-doclookup/8933>\
**Category:** Elasticsearch\
**Created:** [September 5, 2012, 12:28pm UTC](https://discuss.elastic.co/t/getting--id-field-from-doclookup/8933 "2012-09-05T12:28:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshdevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshdevins/32/62865_2.png) [@joshdevins](https://discuss.elastic.co/u/joshdevins)\
**Post date:** [September 5, 2012, 12:28pm UTC](https://discuss.elastic.co/t/getting--id-field-from-doclookup/8933/1 "2012-09-05T12:28:03Z")

</div>

I have a custom scorer plugin that needs access to the document's \_id field  
(not the Lucene docId). At the moment, the following always returns null:

doc().field("\_id")

I have tried playing with the mapping and setting "store" to true/false,  
different "index" values, etc., but to no avail. At the moment, the only  
thing that works, but is horribly ugly is to parse the \_uid field and split  
on the "#" since the field is of the form "\<\_type\>#\<\_id\>".

Any ideas? Is this a bug perhaps in DocLookup?

Thanks,

Josh

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [September 5, 2012, 3:56pm UTC](https://discuss.elastic.co/t/getting--id-field-from-doclookup/8933/2 "2012-09-05T15:56:19Z")

</div>

Could it be that it is not stored?  
"By default it is not indexed and not stored (thus, not created) ... the  
APIs still work (since they work with the |\_uid| field)"

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On 9/5/2012 5:28 AM, joshdevins wrote:

> I have a custom scorer plugin that needs access to the document's \_id  
> field (not the Lucene docId). At the moment, the following always  
> returns null:
> 
> doc().field("\_id")
> 
> I have tried playing with the mapping and setting "store" to  
> true/false, different "index" values, etc., but to no avail. At the  
> moment, the only thing that works, but is horribly ugly is to parse  
> the \_uid field and split on the "#" since the field is of the form  
> "\<\_type\>#\<\_id\>".
> 
> Any ideas? Is this a bug perhaps in DocLookup?
> 
> Thanks,
> 
> Josh
> 
> --

--

---

<div class="post-metadata">

**Author:** ![joshdevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshdevins/32/62865_2.png) [@joshdevins](https://discuss.elastic.co/u/joshdevins)\
**Post date:** [September 5, 2012, 4:02pm UTC](https://discuss.elastic.co/t/getting--id-field-from-doclookup/8933/3 "2012-09-05T16:02:16Z")

</div>

It is stored, at least, according to my mapping it is:

{  
"thething": {  
"\_id": {  
"index": "not\_analyzed",  
"store": "yes"  
}  
}  
}

On Wednesday, September 5, 2012 5:56:08 PM UTC+2, P Hill wrote:

> Could it be that it is not stored?  
> "By default it is not indexed and not stored (thus, not created) ... the  
> APIs still work (since they work with the |\_uid| field)"  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/id-field.html)
> 
> On 9/5/2012 5:28 AM, joshdevins wrote:
> 
> > I have a custom scorer plugin that needs access to the document's \_id  
> > field (not the Lucene docId). At the moment, the following always  
> > returns null:
> > 
> > doc().field("\_id")
> > 
> > I have tried playing with the mapping and setting "store" to  
> > true/false, different "index" values, etc., but to no avail. At the  
> > moment, the only thing that works, but is horribly ugly is to parse  
> > the \_uid field and split on the "#" since the field is of the form  
> > "\<\_type\>#\<\_id\>".
> > 
> > Any ideas? Is this a bug perhaps in DocLookup?
> > 
> > Thanks,
> > 
> > Josh
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![joshdevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshdevins/32/62865_2.png) [@joshdevins](https://discuss.elastic.co/u/joshdevins)\
**Post date:** [September 5, 2012, 7:54pm UTC](https://discuss.elastic.co/t/getting--id-field-from-doclookup/8933/4 "2012-09-05T19:54:44Z")

</div>

Crap, PEBKAC. Error in my test setting the mapping. Setting the `_id` field  
to stored: true did it.

On Wednesday, September 5, 2012 6:02:16 PM UTC+2, joshdevins wrote:

> It is stored, at least, according to my mapping it is:
> 
> {  
> "thething": {  
> "\_id": {  
> "index": "not\_analyzed",  
> "store": "yes"  
> }  
> }  
> }
> 
> On Wednesday, September 5, 2012 5:56:08 PM UTC+2, P Hill wrote:
> 
> > Could it be that it is not stored?  
> > "By default it is not indexed and not stored (thus, not created) ... the  
> > APIs still work (since they work with the |\_uid| field)"  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/id-field.html)
> > 
> > On 9/5/2012 5:28 AM, joshdevins wrote:
> > 
> > > I have a custom scorer plugin that needs access to the document's \_id  
> > > field (not the Lucene docId). At the moment, the following always  
> > > returns null:
> > > 
> > > doc().field("\_id")
> > > 
> > > I have tried playing with the mapping and setting "store" to  
> > > true/false, different "index" values, etc., but to no avail. At the  
> > > moment, the only thing that works, but is horribly ugly is to parse  
> > > the \_uid field and split on the "#" since the field is of the form  
> > > "\<\_type\>#\<\_id\>".
> > > 
> > > Any ideas? Is this a bug perhaps in DocLookup?
> > > 
> > > Thanks,
> > > 
> > > Josh
> > > 
> > > --

--

---

<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:** [July 6, 2017, 3:14am UTC](https://discuss.elastic.co/t/getting--id-field-from-doclookup/8933/5 "2017-07-06T03:14:01Z")

</div>


