Accessing BinaryDocValues from a plugin

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,

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) {
    this.field = field;
    this.reader = reader;

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
To view this discussion on the web visit
For more options, visit