# Reading field Values from docvalues using DoubleFieldSource

**URL:** <https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874>\
**Category:** Elasticsearch\
**Created:** [March 31, 2016, 5:51am UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874 "2016-03-31T05:51:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkalhans](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rkalhans](https://discuss.elastic.co/u/rkalhans)\
**Post date:** [March 31, 2016, 5:51am UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874/1 "2016-03-31T05:51:09Z")

</div>

Hello All,

In a custom analyzer plugin I am trying to read a field value using DoubleFieldSource. The problem that i am facing is that this fails with the following error.

**QueryPhaseExecutionException[Query Failed [Failed to execute main query]]; nested: IllegalStateException[unexpected docvalues type SORTED\_NUMERIC for field 'fileExtensionId' (expected=NUMERIC). Use UninvertingReader or index with docvalues**

We have indexed the field with doc\_values and the type of the field is double. We were using the custom plugin with 1.7, and it was working fine (although we were using field data and not doc values with ES 1.7).

PS: As an additional step I created SortedDoubleFieldSource which extends from DoubleFieldSource and overrides getValues to read sorted numeric values. It gives me zero for all the docs.

My question is _Why is the double field being treated as Sorted numeric and not numeric? And how can i read value of this double field?_

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [March 31, 2016, 8:28am UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874/2 "2016-03-31T08:28:51Z")

</div>

It feels wrong to me that an analyzer would try to read the index.

Indeed you should not use DoubleFieldSource which expects a different encoding from the one that elasticsearch is using. elasticsearch is using SORTED\_NUMERIC because all fields can be multi-valued in elasticsearch, and NUMERIC only supports single-valued fields. The right way to read values in elasticsearch would be to use the fielddata API. You need to get an IndexNumericFieldData from IndexFielddataService and then call load().getDoubleValues().

---

<div class="post-metadata">

**Author:** ![rkalhans](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rkalhans](https://discuss.elastic.co/u/rkalhans)\
**Post date:** [March 31, 2016, 8:41am UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874/3 "2016-03-31T08:41:09Z")

</div>

Thanks for the response Adrien. i am sorry i meant custom aggregation not custom analyzer. It was a slip while typing. I will try to use the fieldData API and will post if i face trouble.

Thanks and regards.

---

<div class="post-metadata">

**Author:** ![rkalhans](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rkalhans](https://discuss.elastic.co/u/rkalhans)\
**Post date:** [March 31, 2016, 9:33am UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874/4 "2016-03-31T09:33:24Z")

</div>

So i tried the following

```
SearchContext searchContex = SearchContext.current();
IndexFieldDataService idfService = searchContext.fieldData();
IndexNumericFieldData fieldData = idfService.getForField(searchContext.smartNameFieldType(field));
final SortedNumericDoubleValues arr = fieldData.load(readerContext).getDoubleValues();

```

I am still seeing zero for the field for all the docs. is this correct or do i need to change something? Thanks for the help.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 4, 2016, 6:56am UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874/5 "2016-04-04T06:56:08Z")

</div>

Can you check how your field is mapped in the mappings? I am thinking that it might have been mapped as an int or a long instead of a float or double?

---

<div class="post-metadata">

**Author:** ![rkalhans](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rkalhans](https://discuss.elastic.co/u/rkalhans)\
**Post date:** [April 28, 2016, 5:33am UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874/6 "2016-04-28T05:33:17Z")

</div>

This solved the issue.

```
    final SortedNumericDoubleValues arr = fieldData.load(readerContext).getDoubleValues();
    final NumericDoubleValues unwrappedArr = FieldData.unwrapSingleton(arr);
```

---

<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 5, 2017, 10:55pm UTC](https://discuss.elastic.co/t/reading-field-values-from-docvalues-using-doublefieldsource/45874/7 "2017-07-05T22:55:43Z")

</div>


