# Update Byte Array Field Java API

**URL:** <https://discuss.elastic.co/t/update-byte-array-field-java-api/16077>\
**Category:** Elasticsearch\
**Created:** [February 28, 2014, 7:28pm UTC](https://discuss.elastic.co/t/update-byte-array-field-java-api/16077 "2014-02-28T19:28:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_Graham](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Craig\_Graham](https://discuss.elastic.co/u/Craig_Graham)\
**Post date:** [February 28, 2014, 7:28pm UTC](https://discuss.elastic.co/t/update-byte-array-field-java-api/16077/1 "2014-02-28T19:28:46Z")

</div>

Hi Everyone,

Has anyone ever experimented with or know of a way to update a field which  
contains a byte array using the Java API? For example I have the following  
index:

```
     client.prepareIndex(INDEX_NAME, INDEX_TYPE)
                .setSource(
                        jsonBuilder().startObject()
                            .field("_name", fileName)
                            .field("_content_type", "application/pdf")
                            .field("content", uploaded)
                        .endObject()
                ).execute().actionGet();

```

where the variable _uploaded_ is of type byte[]. This indexing works great  
for adding documents and getting them back from search results. However, I  
haven't found a way to update the _content_ field which holds the byte[]  
which allows me to keep that feild's value as type byte[]. The method of  
updating the index I was using is the following, but it requires that\*  
uploaded\* be converted to a string.

String script = "ctx.\_source.content="" + uploaded + """;

```
    UpdateResponse repsonse = client.prepareUpdate(INDEX_NAME,INDEX_TYPE

```

, elasticSearchID)  
.setScript(script)  
.execute()  
.actionGet();

This works to update other fields but it doesn't for the the byte[] array  
field\* content\* because it needs to be a byte[] not a String for the way I  
am using it. If it is not possible I can always change my approach to use  
strings and convert them if necessary - just wondering if anyone knew of an  
method to achieve what I am looking to do.

Thanks!

--  
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/43500340-a34b-4978-bcda-b1cf6112bffb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/43500340-a34b-4978-bcda-b1cf6112bffb%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 28, 2014, 7:44pm UTC](https://discuss.elastic.co/t/update-byte-array-field-java-api/16077/2 "2014-02-28T19:44:13Z")

</div>

I haven't tried the API, but in the script, it may be better to use base64  
encoding for binary content. Don't ask how this is possible because I don't  
know. Maybe not in MVEL but another language.

Jörg

--  
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/CAKdsXoG4RGKxkKzfAud%3Dq7YMuQq-X\_K-v8C4GcCn3jZ2bANxvA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoG4RGKxkKzfAud%3Dq7YMuQq-X_K-v8C4GcCn3jZ2bANxvA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:46am UTC](https://discuss.elastic.co/t/update-byte-array-field-java-api/16077/3 "2017-07-06T01:46:30Z")

</div>


