# Converting ES binary to single valued binary

**URL:** <https://discuss.elastic.co/t/converting-es-binary-to-single-valued-binary/247668>\
**Category:** Elasticsearch\
**Created:** [September 6, 2020, 10:30am UTC](https://discuss.elastic.co/t/converting-es-binary-to-single-valued-binary/247668 "2020-09-06T10:30:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehekek](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@mehekek](https://discuss.elastic.co/u/mehekek)\
**Post date:** [September 6, 2020, 10:30am UTC](https://discuss.elastic.co/t/converting-es-binary-to-single-valued-binary/247668/1 "2020-09-06T10:30:21Z")

</div>

Hi there 🙂

To my knowledge, Unlike Lucene, Elasticsearch supports multi-valued byte arrays hence it  
embeds byte arrays by prefixing it with the number of byte arrays embedded  
and number of bytes remaining.

In my code there is a problem. I am iterating through the documents for the purpose of calculating "vector distance" between the documents. Here is the sample of code where all hell breaks loose.

```
@Override
        public double score(int docId, float subQueryScore) throws IOException {
            if (!values.advanceExact(docId)) {
                throw new ElasticsearchException(
                        "Missing BinaryDocValue for field [" + binaryFeatureVector.field() + "]");
            }

            BytesRef x = values.binaryValue();
            BytesRef other = decodeEmbeddedByteArray(x,docId); // HERE IS A MISTAKE!
            //after that it proceeds to calculate distance between vectors..

        }

```

`values.binaryValue()` returns something like this -\> [1 40 fe ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff]

then I want to print `x.bytes`, I get this ...\> 0140FEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0140FCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF01...  
Basically I get binary values for a lot of documents, I dont understand what is going on?

EDIT: Also when use `System.out.println("x.lenght = " + x.length);` I get **66**  
How is this possible??

---

<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:** [October 4, 2020, 10:30am UTC](https://discuss.elastic.co/t/converting-es-binary-to-single-valued-binary/247668/2 "2020-10-04T10:30:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
