# Problems with refactoring FieldCache to DocValues

**URL:** <https://discuss.elastic.co/t/problems-with-refactoring-fieldcache-to-docvalues/61344>\
**Category:** Elasticsearch\
**Created:** [September 23, 2016, 7:45am UTC](https://discuss.elastic.co/t/problems-with-refactoring-fieldcache-to-docvalues/61344 "2016-09-23T07:45:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulM](https://avatars.discourse-cdn.com/v4/letter/p/839c29/32.png) [@PaulM](https://discuss.elastic.co/u/PaulM)\
**Post date:** [September 23, 2016, 7:45am UTC](https://discuss.elastic.co/t/problems-with-refactoring-fieldcache-to-docvalues/61344/1 "2016-09-23T07:45:16Z")

</div>

I'm currently refacoring from ES 1.5 to ES 2.4. But I encounter some problems with the removal of the FieldCache in Lucene 5.

Steps taken:

1. added the doc\_value:true in the mapping (fieldtype is string)
2. Rebuild the index completely
3. Load the docvalues in the doSetNextReader(LeafReaderContext context) from a custom collector class like this

```auto
BinaryDocValues sids = DocValues.getBinary(context.reader(), "id");
```

or like this

```auto
BinaryDocValues ids = context.reader().getBinaryDocValues("id");
```

but in both cases I get the following exception:

```auto
RemoteTransportException[[ws6711][79.99.188.47:9300][geohashcluster[s]]]; nested: IllegalStateException[unexpected docvalues type SORTED_SET for field 'id' (expected one of [BINARY, SORTED]). Use UninvertingReader or index with docvalues.];
Caused by: java.lang.IllegalStateException: unexpected docvalues type SORTED_SET for field 'id' (expected one of [BINARY, SORTED]). Use UninvertingReader or index with docvalues.
	at org.apache.lucene.index.DocValues.checkField(DocValues.java:208)
	at org.apache.lucene.index.DocValues.getBinary(DocValues.java:247)
	at org.elasticsearch.action.geohashcluster.GeohashClusterCollector.doSetNextReader(GeohashClusterCollector.java:153)
	at org.apache.lucene.search.SimpleCollector.getLeafCollector(SimpleCollector.java:33)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:812)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:535)
	at org.elasticsearch.action.geohashcluster.TransportGeohashClusterAction.shardOperation(TransportGeohashClusterAction.java:292)
	at org.elasticsearch.action.geohashcluster.TransportGeohashClusterAction.shardOperation(TransportGeohashClusterAction.java:59)
	at org.elasticsearch.action.support.broadcast.TransportBroadcastAction$ShardTransportHandler.messageReceived(TransportBroadcastAction.java:282)
	at org.elasticsearch.action.support.broadcast.TransportBroadcastAction$ShardTransportHandler.messageReceived(TransportBroadcastAction.java:278)
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77)
	at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
```

Does anyone know what I'm doing wrong?

---

<div class="post-metadata">

**Author:** ![PaulM](https://avatars.discourse-cdn.com/v4/letter/p/839c29/32.png) [@PaulM](https://discuss.elastic.co/u/PaulM)\
**Post date:** [September 23, 2016, 1:34pm UTC](https://discuss.elastic.co/t/problems-with-refactoring-fieldcache-to-docvalues/61344/2 "2016-09-23T13:34:27Z")

</div>

I've found the problem, apparently I should use it like this:

```auto
SortedSetDocValues ids = context.reader().getSortedSetDocValues("id");
```

Why does this work and the BinaryDocValues doesn't?

---

<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:17pm UTC](https://discuss.elastic.co/t/problems-with-refactoring-fieldcache-to-docvalues/61344/3 "2017-07-05T22:17:45Z")

</div>


