# Accessing FieldData in custom Aggregator in ES 2.1.1

**URL:** <https://discuss.elastic.co/t/accessing-fielddata-in-custom-aggregator-in-es-2-1-1/41869>\
**Category:** Elasticsearch\
**Created:** [February 16, 2016, 10:31am UTC](https://discuss.elastic.co/t/accessing-fielddata-in-custom-aggregator-in-es-2-1-1/41869 "2016-02-16T10:31:11Z")\
**Posts on this page:** 3\
**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:** [February 16, 2016, 10:31am UTC](https://discuss.elastic.co/t/accessing-fielddata-in-custom-aggregator-in-es-2-1-1/41869/1 "2016-02-16T10:31:11Z")

</div>

I was writing a custom Aggrigation module and till ES 1.7.1 I was using DoubleFieldSource which used to fetch the data from FieldData.

However when upgrading my custom plugin to ES 2.1.1, I found that DoubleFieldSource reads from DocValues even when docValues are not enabled. here is the code snippet from DoubleFieldSource.java where it does not check if docValues is enabled, it simply reads from docvalues.

```
@Override
  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final NumericDocValues arr = DocValues.getNumeric(readerContext.reader(), field);
    final Bits valid = DocValues.getDocsWithField(readerContext.reader(), field);
    return new DoubleDocValues(this) {

```

When Trying to use DoubleFIeldSource I get the following error

`unexpected docvalues type NONE for field 'fileExtensionId' (expected=NUMERIC). Use UninvertingReader or index with docvalues.`

The field fileExtensionId has docValues = false and has been indexed thus. Is there any substitute for DoubleFieldSource ? or is this a bug?

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 19, 2016, 4:48pm UTC](https://discuss.elastic.co/t/accessing-fielddata-in-custom-aggregator-in-es-2-1-1/41869/2 "2016-02-19T16:48:32Z")

</div>

I would suggest looking at the patches from both Lucene and Elasticsearch  
to understand what needs to be changed. I went through a Lucene 4 -\> 5  
upgrade, but I no longer remember the details. I gain insights by looking  
at the diffs, especially in the test classes:

[https://issues.apache.org/jira/browse/LUCENE-5666](https://issues.apache.org/jira/browse/LUCENE-5666)  
[do not know what the issue number is in Elasticsearch]

Cheers,

Ivan

---

<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, 11:14pm UTC](https://discuss.elastic.co/t/accessing-fielddata-in-custom-aggregator-in-es-2-1-1/41869/3 "2017-07-05T23:14:47Z")

</div>


