# Java API binary type example

**URL:** <https://discuss.elastic.co/t/java-api-binary-type-example/8034>\
**Category:** Elasticsearch\
**Created:** [June 10, 2012, 1:46pm UTC](https://discuss.elastic.co/t/java-api-binary-type-example/8034 "2012-06-10T13:46:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shimi/32/2620_2.png) [@Shimi](https://discuss.elastic.co/u/Shimi)\
**Post date:** [June 10, 2012, 1:46pm UTC](https://discuss.elastic.co/t/java-api-binary-type-example/8034/1 "2012-06-10T13:46:49Z")

</div>

Is there an example/unit-test on how to use the Binary type in the  
Java client API?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 12, 2012, 10:11am UTC](https://discuss.elastic.co/t/java-api-binary-type-example/8034/2 "2012-06-12T10:11:56Z")

</div>

The json/smile document you build should simply have a binary type to it.

On Sun, Jun 10, 2012 at 3:46 PM, Shimi [shimi.k@gmail.com](mailto:shimi.k@gmail.com) wrote:

> Is there an example/unit-test on how to use the Binary type in the  
> Java client API?

---

<div class="post-metadata">

**Author:** ![Shimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shimi/32/2620_2.png) [@Shimi](https://discuss.elastic.co/u/Shimi)\
**Post date:** [June 12, 2012, 10:30am UTC](https://discuss.elastic.co/t/java-api-binary-type-example/8034/3 "2012-06-12T10:30:50Z")

</div>

So I guess this is not the right way:

client.prepareIndex("indexname", "type1", "1")  
.setSource(jsonBuilder.startObject  
.field("index", "binary index")  
.field("binary", Base64.decode("shimi"))  
.endObject  
)  
.execute.actionGet

I will check json/smile

On Tue, Jun 12, 2012 at 1:11 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> The json/smile document you build should simply have a binary type to it.
> 
> On Sun, Jun 10, 2012 at 3:46 PM, Shimi [shimi.k@gmail.com](mailto:shimi.k@gmail.com) wrote:
> 
> > Is there an example/unit-test on how to use the Binary type in the  
> > Java client API?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 13, 2012, 6:55pm UTC](https://discuss.elastic.co/t/java-api-binary-type-example/8034/4 "2012-06-13T18:55:59Z")

</div>

Just pass the byte array to it, also, the field should be mapped as binary.

On Tue, Jun 12, 2012 at 12:30 PM, Shimi Kiviti [shimi.k@gmail.com](mailto:shimi.k@gmail.com) wrote:

> So I guess this is not the right way:
> 
> client.prepareIndex("indexname", "type1", "1")  
> .setSource(jsonBuilder.startObject  
> .field("index", "binary index")  
> .field("binary", Base64.decode("shimi"))  
> .endObject  
> )  
> .execute.actionGet
> 
> I will check json/smile
> 
> On Tue, Jun 12, 2012 at 1:11 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > The json/smile document you build should simply have a binary type to it.
> > 
> > On Sun, Jun 10, 2012 at 3:46 PM, Shimi [shimi.k@gmail.com](mailto:shimi.k@gmail.com) wrote:
> > 
> > > Is there an example/unit-test on how to use the Binary type in the  
> > > Java client API?

---

<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, 3:24am UTC](https://discuss.elastic.co/t/java-api-binary-type-example/8034/5 "2017-07-06T03:24:23Z")

</div>


