# Accessing BinaryDocValues from a plugin

**URL:** <https://discuss.elastic.co/t/accessing-binarydocvalues-from-a-plugin/20620>\
**Category:** Elasticsearch\
**Created:** [November 6, 2014, 11:50pm UTC](https://discuss.elastic.co/t/accessing-binarydocvalues-from-a-plugin/20620 "2014-11-06T23:50:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeev\_sands](https://avatars.discourse-cdn.com/v4/letter/z/46a35a/32.png) [@zeev\_sands](https://discuss.elastic.co/u/zeev_sands)\
**Post date:** [November 6, 2014, 11:50pm UTC](https://discuss.elastic.co/t/accessing-binarydocvalues-from-a-plugin/20620/1 "2014-11-06T23:50:35Z")

</div>

Hello everyone,

I was wondering if someone could clarify this for me: I am storing binary  
arrays in an index as "stored, un-indexed, binary doc values" and later  
reading the fields from a custom query, which implements required lucene  
classes (Weight & Scorer).

Inside the scorer I am loading binaryDocValues for the segment (a snippet  
is provided below).

When I look at BytgeRef br, it appears to have some sort of an offset  
before the data is started, looks like a size of the buffer, but I am NOT  
putting it there explicitly when importing the data via regular es means.  
Also, this offset disappears if I request the document directly from the  
reader and then access the field.

My question is: how do I properly handle the offset? it appears to be of  
variable length? what I am doing below is a kludge...

I appreciate any pointers you might have!

Thank you,  
ZS

class NYScorer extends Scorer {

```
private BinaryDocValues bdv = null;
private final String field;
private final IndexReader reader;

MyScorer(Weight weight, String field, IndexReader reader, float boost) {
    super(weight);
    this.field = field;
    this.reader = reader;
}

@Override
public float score() throws IOException {
    if (bdv == null) {
        AtomicReader ar = (AtomicReader) reader;
        binaryDocValues = ar.getBinaryDocValues(field);
    }

    BytesRef br = bdv.get(docID());
    int offset;
    if (br.bytes[2] == 0) {
        offset = 2;
    } else {
        offset = 3;
    }
    // Do some stuff here

```

}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a037524b-b137-4286-b323-43ed3785a014%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a037524b-b137-4286-b323-43ed3785a014%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:51am UTC](https://discuss.elastic.co/t/accessing-binarydocvalues-from-a-plugin/20620/2 "2017-07-06T00:51:37Z")

</div>


