# Doc().numeric() sometimes returns empty for all objects

**URL:** <https://discuss.elastic.co/t/doc-numeric-sometimes-returns-empty-for-all-objects/8091>\
**Category:** Elasticsearch\
**Created:** [June 13, 2012, 9:39pm UTC](https://discuss.elastic.co/t/doc-numeric-sometimes-returns-empty-for-all-objects/8091 "2012-06-13T21:39:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Dellow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colin_dellow/32/2818_2.png) [@Colin\_Dellow](https://discuss.elastic.co/u/Colin_Dellow)\
**Post date:** [June 13, 2012, 9:39pm UTC](https://discuss.elastic.co/t/doc-numeric-sometimes-returns-empty-for-all-objects/8091/1 "2012-06-13T21:39:02Z")

</div>

I wrote a custom search script which tries to access fields through  
doc().field() (in this case, doc().numeric()).

I think I'm missing something obvious. I have a small sample --  
[https://github.com/cldellow/es-native-script/](https://github.com/cldellow/es-native-script/) -- that fetches lens.zoom  
from the doc. The sample works fine.

In production, it doesn't reliably work. Items that definitely have values  
for lens.zoom come back with a DocFieldData where .isEmpty() returns true.  
The main difference in production is that the items and mappings have many  
more fields. (You can click through to the history of the item and mapping  
files in the github repo to see the full item/mapping)

What can cause this class of failure? The mapping in production must exist  
and be correct, otherwise I would expect to see the "No field found for  
[lens.zoom]" exception thrown from DocLookup.

Any ideas? I'm tearing my hair out trying to figure out what the heck is  
going on.

---

<div class="post-metadata">

**Author:** ![Colin\_Dellow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colin_dellow/32/2818_2.png) [@Colin\_Dellow](https://discuss.elastic.co/u/Colin_Dellow)\
**Post date:** [June 14, 2012, 5:04pm UTC](https://discuss.elastic.co/t/doc-numeric-sometimes-returns-empty-for-all-objects/8091/2 "2012-06-14T17:04:55Z")

</div>

Aha, I've figured out what's going on.

If a field in a document has the same name as a type in the index, the  
mapper will use the type when resolving the mapping  
(MapperService.smartNameObjectMapper). This results in the doc.numeric()  
returning empty for all the values.

You can see this in the github repro I published -- as is, it works.  
Uncomment the line in repro.sh that adds a mapping for 'lens', and it stops  
working.

Is this expected, or a bug? I can work around it by ensuring my field names  
don't clash with type names, but it seemed surprising to me.

On Wednesday, 13 June 2012 17:39:02 UTC-4, Colin Dellow wrote:

> I wrote a custom search script which tries to access fields through  
> doc().field() (in this case, doc().numeric()).
> 
> I think I'm missing something obvious. I have a small sample --  
> [https://github.com/cldellow/es-native-script/](https://github.com/cldellow/es-native-script/) -- that fetches lens.zoom  
> from the doc. The sample works fine.
> 
> In production, it doesn't reliably work. Items that definitely have values  
> for lens.zoom come back with a DocFieldData where .isEmpty() returns true.  
> The main difference in production is that the items and mappings have many  
> more fields. (You can click through to the history of the item and mapping  
> files in the github repo to see the full item/mapping)
> 
> What can cause this class of failure? The mapping in production must exist  
> and be correct, otherwise I would expect to see the "No field found for  
> [lens.zoom]" exception thrown from DocLookup.
> 
> Any ideas? I'm tearing my hair out trying to figure out what the heck is  
> going on.

---

<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:24am UTC](https://discuss.elastic.co/t/doc-numeric-sometimes-returns-empty-for-all-objects/8091/3 "2017-07-06T03:24:12Z")

</div>

Closed on July 6, 2017, 3:24am UTC


